123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- #!/bin/bash
-
- . "$TF_DIR/include/subtest.sh"
-
- tf_enum_subtests() {
- echo "import_fn"
- echo "import_var"
- echo "import_var_fn"
- echo "try_import_fn"
- echo "try_import_var"
- echo "try_import_var_fn"
- echo "import_var_fn_bash"
- echo "import_var_fn_bash_hint"
- echo "ls_imported"
- }
-
- ignored() {
- #
- # Things generated by listing code we want to strip
- #
- # This is list of lines that we expect to appear as new after
- # running the import test since they are a known part of the
- # shellfu itself
- #
- echo declare -f shellfu
- echo SHELLFU_COMPAT
- echo SHELLFU_DEBUGINIT
- echo SHELLFU_EMBEDDED
- echo SHELLFU_EMBEDTMP
- echo SHELLFU_DIR
- echo SHELLFU_GIT_HASH
- echo SHELLFU_INCLUDE
- echo SHELLFU_PATH
- echo SHELLFU_PRETTY
- echo SHELLFU_VERSION
- echo __SHELLFU_IMPORTED
- }
-
- mkdelim() {
- #
- # Print visual delimiter
- #
- echo
- echo "######"
- echo
- }
-
- mksnippet() {
- #
- # Produce a snippet to store env info to a file $1
- #
- # File _ignored_ is used as list of tokens to always
- # remove from the info.
- #
- test "$name" == ls_imported && return 0
- local target="$1"
- printf "
- {
- (set -o posix; set) \\
- | grep -e '^[a-zA-Z_]' \\
- | sed -e 's/=.*//'
- declare -F
- } | sort | grep -vxf _ignored_ > %s
- " "$target"
- }
-
- mktscript_header() {
- #
- # Print part before .before snippet
- #
- case $name in
- *_bash) echo '#!/bin/bash' ;;
- *_bash_hint) echo '#!/bin/bash' ;;
- *) echo '#!/bin/sh' ;;
- esac
- }
-
- mktscript_body() {
- #
- # Print main script body
- #
- echo 'SHELLFU_INCLUDE=test/include'
- echo ". \$(sfpath)"
- case $name in
- import_fn) echo 'shellfu import mod_f' ;;
- import_var) echo 'shellfu import mod_v' ;;
- import_var_fn) echo 'shellfu import mod_v_f' ;;
- import_var_fn_bash) echo 'shellfu import mod_v_f_bash' ;;
- import_var_fn_bash_hint) echo 'SHELLFU_COMPAT=bash; shellfu import mod_v_f_bash' ;;
- try_import_fn) echo 'shellfu try_import mod_f' ;;
- try_import_var) echo 'shellfu try_import mod_v' ;;
- try_import_var_fn) echo 'shellfu try_import mod_v_f' ;;
- ls_imported) echo 'shellfu import mod_v_f'
- echo 'shellfu try_import mod_v_f_bash'
- echo 'shellfu import mod_v'
- echo 'shellfu import mod_v_f'
- echo 'shellfu ls_imported' ;;
- esac
- }
-
- mktscript() {
- #
- # Compose test script
- #
- mktscript_header
- mkdelim
- mksnippet "$name.before"
- mkdelim
- mktscript_body
- mkdelim
- mksnippet "$name.after"
- }
-
- tf_do_subtest() {
- #
- # Prepare, run and check results of test $1
- #
- # Contents of $1 file (which is supposed to be importing
- # code) are altered for testing and wrapped so that on
- # execution in clean environment, two files are produced to
- # hold sets of detected variable and function names--before
- # import and after it.
- #
- # The difference of the sets (i.e. what we have *really*
- # imported) must be same as oracle/$1.new
- #
- local name="$1"
- mktscript "$name" > "$name.sh"
-
- mkdir -p result
- chmod +x "$name.sh"
- env -i PATH="$PATH" SHELLFU_DIR="$SHELLFU_DIR" ./"$name.sh" \
- >"result/$name.out" 2>"result/$name.err"
- test "$name" == ls_imported && {
- diff -u "oracle/$name.out" "result/$name.out" || return 1
- diff -u "oracle/$name.err" "result/$name.err" || return 1
- return 0
- }
- comm -13 "$name.before" "$name.after" > "result/$name.new"
- # i.e. lines introduced by import ^^
- diff -u "oracle/$name.new" "result/$name.new"
- }
-
- export LANG=C
- ignored > _ignored_
-
- tf_do_subtests
|