
# Copyright (C) Dmitry Volyntsev
# Copyright (C) NGINX, Inc.

njs_found=no
printf "checking for expect ..."

if /bin/sh -c "(expect -v)" >> $NJS_AUTOCONF_ERR 2>&1; then
    njs_found=yes
fi

if [ $njs_found = yes ]; then
    echo " found"
    echo " + Expect version: `expect -v`"

else
    echo " not found"
fi

if [ $njs_found = yes -a $NJS_HAVE_READLINE = YES ]; then
    cat << END >> $NJS_MAKEFILE

shell_test_njs:	njs test/shell_test.exp
	PATH="$NJS_BUILD_DIR:\$(PATH)" LANG=C.UTF-8 TERM=screen \
    expect -f test/shell_test.exp
	PATH="$NJS_BUILD_DIR:\$(PATH)" LANG=C.UTF-8 TERM=screen \
    expect -f test/shell_test_njs.exp
END

if [ $NJS_HAVE_QUICKJS = YES ]; then
    cat << END >> $NJS_MAKEFILE

shell_test:	shell_test_njs shell_test_quickjs

shell_test_quickjs:	njs test/shell_test.exp
	PATH="$NJS_BUILD_DIR:\$(PATH)" LANG=C.UTF-8 TERM=screen NJS_ENGINE=QuickJS \
    expect -f test/shell_test.exp
END

else
    cat << END >> $NJS_MAKEFILE

shell_test:	shell_test_njs
END

fi

else
    echo " - expect tests are disabled"

    cat << END >> $NJS_MAKEFILE

shell_test:
	@echo "Skipping expect tests"
END

fi
