treewide: use modern syntax
[project/firewall4.git] / run_tests.sh
index eb4dafa003e6977eb333391f7aba1833173df7e7..af1ae4d5cb577566266eef4386d833d571a72e00 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 
 line='........................................'
-uenv='{ "REQUIRE_SEARCH_PATH": [ "/usr/local/lib/ucode/*.so", "/usr/lib/ucode/*.so", "./tests/*.uc", "./root/usr/share/ucode/*.uc" ] }'
+ucode='ucode -S -T, -L./tests/lib -L./root/usr/share/ucode'
 
 extract_sections() {
        local file=$1
@@ -30,6 +30,14 @@ extract_sections() {
                                outfile=$(printf "%s/%03d.%s" "$dir" $count "$tag")
                                printf "" > "$outfile"
                        ;;
+                       "-- File "*" --")
+                               tag="file"
+                               outfile="${line#-- File }"
+                               outfile="$(echo "${outfile% --}" | xargs)"
+                               outfile="$dir/files$(readlink -m "/${outfile:-file}")"
+                               mkdir -p "$(dirname "$outfile")"
+                               printf "" > "$outfile"
+                       ;;
                        "-- End --")
                                tag=""
                                outfile=""
@@ -55,7 +63,11 @@ run_testcase() {
        local code=$7
        local fail=0
 
-       ucode ${uenv:+-e "$uenv"} ${env:+-e "$(cat "$env")"} -i - <"$in" >"$dir/res.out" 2>"$dir/res.err"
+       $ucode \
+               -D MOCK_SEARCH_PATH='["'"$dir"'/files", "./tests/mocks"]' \
+               ${env:+-F "$env"} \
+               -l mocklib -l fw4 \
+               - <"$in" >"$dir/res.out" 2>"$dir/res.err"
 
        printf "%d\n" $? > "$dir/res.code"
 
@@ -157,13 +169,31 @@ run_test() {
 n_tests=0
 n_fails=0
 
+select_tests="$@"
+
+use_test() {
+       local input="$(readlink -f "$1")"
+       local test
+
+       [ -f "$input" ] || return 1
+       [ -n "$select_tests" ] || return 0
+
+       for test in "$select_tests"; do
+               test="$(readlink -f "$test")"
+
+               [ "$test" != "$input" ] || return 0
+       done
+
+       return 1
+}
+
 for catdir in tests/[0-9][0-9]_*; do
        [ -d "$catdir" ] || continue
 
        printf "\n##\n## Running %s tests\n##\n\n" "${catdir##*/[0-9][0-9]_}"
 
        for testfile in "$catdir/"[0-9][0-9]_*; do
-               [ -f "$testfile" ] || continue
+               use_test "$testfile" || continue
 
                n_tests=$((n_tests + 1))
                run_test "$testfile" || n_fails=$((n_fails + 1))
@@ -171,3 +201,4 @@ for catdir in tests/[0-9][0-9]_*; do
 done
 
 printf "\nRan %d tests, %d okay, %d failures\n" $n_tests $((n_tests - n_fails)) $n_fails
+exit $n_fails