123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- #!/bin/bash
-
- . "$TF_DIR/include/subtest.sh"
- . "$TF_DIR/include/tools.sh"
-
- tf_enum_subtests() {
- echo "no_module"
- echo "empty_file"
- echo "no_declaration"
- echo "deep1"
- echo "deep2"
- echo "deep3"
- echo "deep4"
- echo "version_empty"
- echo "version_spaces"
- }
-
- mkwrapper() {
- #
- # Prepare script body
- #
- local modname=$1
- echo '#!/bin/bash'
- echo 'SHELLFU_PATH=test/shellfu'
- echo '. "$(shellfu-get path)" || exit 3'
- echo "shellfu version $modname"
- }
-
- mkmodule() {
- #
- # Prepare module body
- #
- test "$name" == no_module && return 0
- {
- test "$name" == empty_file || {
- echo 'foo() {'
- echo ' echo hello'
- echo '}'
- }
- case $name in
- no_declaration)
- :
- ;;
- deep?)
- n=${name#deep}
- echo '#shellfu module-version: 0.1.2'
- while test "$n" -gt 1; do
- ((n--))
- echo
- done
- ;;
- version_empty)
- echo '#shellfu module-version:'
- ;;
- version_spaces)
- echo '#shellfu module-version: 0.1.2 '
- ;;
- esac
- } > "test/shellfu/$name.sh"
- }
-
- mkoracle() {
- case $name in
- deep1) echo 0.1.2 ;;
- deep2) echo 0.1.2 ;;
- deep3) echo 0.1.2 ;;
- version_spaces) echo 0.1.2 ;;
- esac > "oracle/$name.stdout"
- case $name in
- no_module) echo "shellfu: cannot find module: $name" ;;
- empty_file) echo "shellfu: missing version declaration: test/shellfu/$name.sh" ;;
- no_declaration) echo "shellfu: missing version declaration: test/shellfu/$name.sh" ;;
- deep4) echo "shellfu: missing version declaration: test/shellfu/$name.sh" ;;
- version_empty) echo "shellfu: missing version declaration: test/shellfu/$name.sh" ;;
- esac > "oracle/$name.stderr"
- }
-
- mkes() {
- case $name in
- deep1|deep2|deep3|version_spaces) echo 0 ;;
- no_module) echo 3 ;;
- *) echo 2 ;;
- esac
- }
-
- run_wrapper() {
- #
- # Run shellfu in wrapper
- #
- mkwrapper "$name" | bash
- }
-
- tf_do_subtest() {
- #
- # Prepare, run and check results of test $1
- #
- local name="$1"
- local o_es
- mkdir -p test/shellfu result oracle
- mkmodule
- mkoracle
- o_es=$(mkes)
- tf_testflt -n "$name" -O "oracle/$name.stdout" -E "oracle/$name.stderr" -S "$o_es" run_wrapper
- }
-
- tf_do_subtests
|