123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- #!/bin/bash
- #shellcheck disable=SC1090
-
- . "$TF_DIR/include/subtest.sh"
- . "$TF_DIR/include/tools.sh"
-
- tf_enum_subtests() {
- echo "no_module"
- echo "empty_file"
- echo "no_directive"
- echo "deep1"
- echo "deep2"
- echo "deep3"
- echo "deep4"
- echo "1directive"
- echo "2directives"
- echo "3directives"
- echo "twins"
- echo "twins"
- echo "updown"
- echo "directive_empty"
- echo "directive_spaces"
- }
-
- mkresult() {
- #
- # Prepare script body
- #
- #shellcheck disable=SC2016
- {
- echo '#!/bin/bash'
- echo 'SHELLFU_PATH=test/shellfu'
- echo '. "$(sfpath)" || exit 3'
- echo "shellfu _read_directive dname test/shellfu/$TF_SUBTEST.sh"
- } | bash
- }
-
- mkmodule() {
- #
- # Prepare module body
- #
- test "$TF_SUBTEST" == no_module && return 0
- {
- case $TF_SUBTEST in
- updown) echo '#shellfu dname=dvalue'
- esac
- test "$TF_SUBTEST" == empty_file || {
- echo 'foo() {'
- echo ' echo hello'
- echo '}'
- }
- case $TF_SUBTEST in
- no_directive)
- :
- ;;
- deep?)
- n=${TF_SUBTEST#deep}
- echo '#shellfu dname=dvalue'
- while test "$n" -gt 1; do
- ((n--))
- echo
- done
- ;;
- updown)
- echo '#shellfu dname=dvalue2'
- ;;
- directive_empty)
- echo '#shellfu dname='
- ;;
- twins)
- echo '#shellfu dname=dvalue dname=dvalue2'
- ;;
- 1directive)
- echo '#shellfu dname=dvalue'
- ;;
- 2directives)
- echo '#shellfu name=value dname=dvalue'
- ;;
- 3directives)
- echo '#shellfu name=value dname=dvalue name=value'
- ;;
- directive_spaces)
- echo '#shellfu dname=dvalue '
- ;;
- esac
- } > "test/shellfu/$TF_SUBTEST.sh"
- }
-
- mkoracle() {
- case $TF_SUBTEST in
- deep1) echo -n dvalue ;;
- deep2) echo -n dvalue ;;
- deep3) echo -n dvalue ;;
- twins) echo -n dvalue ;;
- updown) echo -n dvalue ;;
- 1directive) echo -n dvalue ;;
- 2directives) echo -n dvalue ;;
- 3directives) echo -n dvalue ;;
- directive_spaces) echo -n dvalue ;;
- esac > "oracle/$TF_SUBTEST.stdout"
- local f="shellfu:fatal:"
- local w="shellfu:"
- local m="test/shellfu/$TF_SUBTEST.sh"
- case $TF_SUBTEST in
- no_module) echo "$f no such file: $m" ;;
- empty_file) echo "$w directive not found: 'dname' in '$m'" ;;
- no_directive) echo "$w directive not found: 'dname' in '$m'" ;;
- deep4) echo "$w directive not found: 'dname' in '$m'" ;;
- esac > "oracle/$TF_SUBTEST.stderr"
- }
-
- mkes() {
- case $TF_SUBTEST in
- empty_file) return 2 ;;
- no_directive) return 2 ;;
- deep4) return 2 ;;
- directive_empty) return 1 ;;
- no_module) return 3 ;;
- esac
- return 0
- }
-
- tf_do_subtest() {
- #
- # Prepare, run and check results of test $1
- #
- local o_es
- mkdir -p test/shellfu result oracle
- mkmodule
- mkoracle
- mkes; o_es=$?
- tf_testflt \
- -n "$TF_SUBTEST" \
- -O "oracle/$TF_SUBTEST.stdout" \
- -E "oracle/$TF_SUBTEST.stderr" \
- -S "$o_es" mkresult
- }
-
- tf_do_subtests
|