Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/bin/sh Improved handling of TEST_SH so that it is poss...



details:   https://anonhg.NetBSD.org/src/rev/c1377eae7ba5
branches:  trunk
changeset: 343898:c1377eae7ba5
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Mar 01 12:39:35 2016 +0000

description:
Improved handling of TEST_SH so that it is possible to define it
to the name of a shell, plus options that shell needs to run it
in the correct mode to be tested: eg: TEST_SH='bash -o posix'
Also finished the implementation of tests of "set -n" now that
the NetBSD shell supports that as it should. (from kre)

diffstat:

 tests/bin/sh/t_exit.sh   |   24 +++---
 tests/bin/sh/t_here.sh   |   13 +--
 tests/bin/sh/t_option.sh |  160 +++++++++++++++++++++++++++++++++-------------
 tests/bin/sh/t_redir.sh  |   15 ++--
 4 files changed, 139 insertions(+), 73 deletions(-)

diffs (truncated from 554 to 300 lines):

diff -r 1371b82a3234 -r c1377eae7ba5 tests/bin/sh/t_exit.sh
--- a/tests/bin/sh/t_exit.sh    Tue Mar 01 10:29:40 2016 +0000
+++ b/tests/bin/sh/t_exit.sh    Tue Mar 01 12:39:35 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_exit.sh,v 1.4 2016/02/24 14:42:06 christos Exp $
+# $NetBSD: t_exit.sh,v 1.5 2016/03/01 12:39:35 christos Exp $
 #
 # Copyright (c) 2007 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -34,9 +34,9 @@
                        "a command in the background (PR bin/46327)"
 }
 background_body() {
-       atf_check -o match:0 -e empty "${TEST_SH}" -c 'true; true & echo $?'
+       atf_check -o match:0 -e empty ${TEST_SH} -c 'true; true & echo $?'
        # atf_expect_fail "PR bin/46327" (now fixed?)
-       atf_check -o match:0 -e empty "${TEST_SH}" -c 'false; true & echo $?'
+       atf_check -o match:0 -e empty ${TEST_SH} -c 'false; true & echo $?'
 }
 
 atf_test_case function
@@ -46,7 +46,7 @@
 }
 function_body() {
        atf_check -s exit:0 -o match:STATUS=1-0 -e empty \
-               "${TEST_SH}" -c '
+               ${TEST_SH} -c '
                        crud() {
                                test yes = no
 
@@ -66,7 +66,7 @@
 }
 readout_body() {
        atf_check -s exit:0 -o match:0 -e empty \
-               "${TEST_SH}" -c 'true && ! true | false; echo $?'
+               ${TEST_SH} -c 'true && ! true | false; echo $?'
 }
 
 atf_test_case trap_subshell
@@ -87,7 +87,7 @@
 trap_zero__implicit_exit_body() {
        # PR bin/6764: sh works but ksh does not
        echo '( trap "echo exiting" 0 )' >helper.sh
-       atf_check -s exit:0 -o match:exiting -e empty "${TEST_SH}" helper.sh
+       atf_check -s exit:0 -o match:exiting -e empty ${TEST_SH} helper.sh
        # test ksh by setting TEST_SH to /bin/ksh and run the entire set...
        # atf_check -s exit:0 -o match:exiting -e empty /bin/ksh helper.sh
 }
@@ -100,7 +100,7 @@
 trap_zero__explicit_exit_body() {
        echo '( trap "echo exiting" 0; exit; echo NO_NO_NO )' >helper.sh
        atf_check -s exit:0 -o match:exiting -o not-match:NO_NO -e empty \
-               "${TEST_SH}" helper.sh
+               ${TEST_SH} helper.sh
        # test ksh by setting TEST_SH to /bin/ksh and run the entire set...
        # atf_check -s exit:0 -o match:exiting -e empty /bin/ksh helper.sh
 }
@@ -115,7 +115,7 @@
        echo '( trap "echo exiting" 0; return; echo NO_NO_NO )' >helper.sh
        atf_expect_fail "return from a sub-shell not defined and does not work"
        atf_check -s exit:0 -o match:exiting -o not-match:NO_NO -e empty \
-               "${TEST_SH}" helper.sh
+               ${TEST_SH} helper.sh
        # test ksh by setting TEST_SH to /bin/ksh and run the entire set...
        # atf_check -s exit:0 -o match:exiting -e empty /bin/ksh helper.sh
 }
@@ -129,7 +129,7 @@
        for N in 0 1 2 3 4 5 6 42 99 101 125 126 127 128 129 200 254 255
        do
                atf_check -s exit:$N -o empty -e empty \
-                       "${TEST_SH}" -c "exit $N; echo FOO; echo BAR >&2"
+                       ${TEST_SH} -c "exit $N; echo FOO; echo BAR >&2"
        done
 }
 
@@ -142,7 +142,7 @@
        for N in 0 1 2 3 4 5 6 42 99 101 125 126 127 128 129 200 254 255
        do
                atf_check -s exit:0 -o empty -e empty \
-                       "${TEST_SH}" -c "(exit $N); test \$? -eq $N"
+                       ${TEST_SH} -c "(exit $N); test \$? -eq $N"
        done
 }
 
@@ -153,10 +153,10 @@
 }
 subshell_background_body() {
        atf_check -o match:0 -e empty \
-               "${TEST_SH}" -c 'true; (false || true) & echo $?'
+               ${TEST_SH} -c 'true; (false || true) & echo $?'
        # atf_expect_fail "PR bin/46327" (now fixed?)
        atf_check -o match:0 -e empty \
-               "${TEST_SH}" -c 'false; (false || true) & echo $?'
+               ${TEST_SH} -c 'false; (false || true) & echo $?'
 }
 
 atf_init_test_cases() {
diff -r 1371b82a3234 -r c1377eae7ba5 tests/bin/sh/t_here.sh
--- a/tests/bin/sh/t_here.sh    Tue Mar 01 10:29:40 2016 +0000
+++ b/tests/bin/sh/t_here.sh    Tue Mar 01 12:39:35 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_here.sh,v 1.2 2016/02/29 23:52:53 christos Exp $
+# $NetBSD: t_here.sh,v 1.3 2016/03/01 12:39:35 christos Exp $
 #
 # Copyright (c) 2007 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -39,7 +39,6 @@
        # some of the tests expect us to expand $nl internally...
        CMD="nl='${nl}'; $1"
 
-echo "${CMD}" >/tmp/CMD
        rm -f trace.*
        result="$( ${TEST_SH} -c "${CMD}" 2>"${TEMP_FILE}" )"
        STATUS=$?
@@ -193,11 +192,11 @@
 
 }
 
-atf_test_case viscious
-viscious_head() {
+atf_test_case vicious
+vicious_head() {
        atf_set "descr" "Tests for obscure and obnoxious uses of here docs"
 }
-viscious_body() {
+vicious_body() {
 
        cat <<- \END_SCRIPT > script
                cat <<ONE && cat \
@@ -215,7 +214,7 @@
        # will not check what it produces.   The eventual result
        # seems unlikely to be what we currently output, which
        # is:
-       #       :echo line 1
+       #       A:echo line 1
        #       B:echo line 2)" && prefix DASH_CODE <<DASH_CODE
        #       B:echo line 3
        #       line 4
@@ -257,5 +256,5 @@
        atf_add_test_case do_simple
        atf_add_test_case incomplete
        atf_add_test_case multiple      # multiple << operators on one cmd
-       atf_add_test_case viscious      # evil test from the austin-l list...
+       atf_add_test_case vicious       # evil test from the austin-l list...
 }
diff -r 1371b82a3234 -r c1377eae7ba5 tests/bin/sh/t_option.sh
--- a/tests/bin/sh/t_option.sh  Tue Mar 01 10:29:40 2016 +0000
+++ b/tests/bin/sh/t_option.sh  Tue Mar 01 12:39:35 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_option.sh,v 1.1 2016/02/23 16:20:42 christos Exp $
+# $NetBSD: t_option.sh,v 1.2 2016/03/01 12:39:35 christos Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -52,7 +52,7 @@
                test "${#opt}" -gt 1 &&
   CLEAR='xx="$-" && xx=$(echo "$xx" | tr -d cs) && test -n "$xx" && set +"$xx";'
 
-               atf_check -s exit:0 -o empty -e empty "${TEST_SH}" -c \
+               atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
                        "opt=${opt}"'
                        x() {
                                echo "ERROR: Unable to $1 option $2" >&2
@@ -101,7 +101,7 @@
        for opt
        do
                test "${opt}" = n && continue
-               "${TEST_SH}" -c "set -${opt}" 2>/dev/null  &&
+               ${TEST_SH} -c "set -${opt}" 2>/dev/null  &&
                        OPTS="${OPTS} ${opt}" || RET=1
        done
 
@@ -122,11 +122,11 @@
        test_option_on_off a
 
        # without -a, new variables should not be exported (so grep "fails")
-       atf_check -s exit:1 -o empty -e empty "${TEST_SH}" -ce \
+       atf_check -s exit:1 -o empty -e empty ${TEST_SH} -ce \
                'unset VAR; set +a; VAR=value; env | grep "^VAR="'
 
        # with -a, they should be
-       atf_check -s exit:0 -o match:VAR=value -e empty "${TEST_SH}" -ce \
+       atf_check -s exit:0 -o match:VAR=value -e empty ${TEST_SH} -ce \
                'unset VAR; set -a; VAR=value; env | grep "^VAR="'
 }
 
@@ -150,7 +150,7 @@
        echo Precious_Content > Important_File
 
        # Check that we can redirect onto file when -C is not set
-       atf_check -s exit:0 -o empty -e empty "${TEST_SH}" -c \
+       atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
                '
                D=$(ls -l Junk_File) || exit 1
                set +C
@@ -160,7 +160,7 @@
                '
 
        # Check that we cannot redirect onto file when -C is set
-       atf_check -s exit:0 -o empty -e not-empty "${TEST_SH}" -c \
+       atf_check -s exit:0 -o empty -e not-empty ${TEST_SH} -c \
                '
                D=$(ls -l Important_File) || exit 1
                set -C
@@ -170,7 +170,7 @@
                '
 
        # Check that we can append to file, even when -C is set
-       atf_check -s exit:0 -o empty -e empty "${TEST_SH}" -c \
+       atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
                '
                D=$(ls -l Junk_File) || exit 1
                set -C
@@ -180,7 +180,7 @@
                '
 
        # Check that we abort on attempt to redirect onto file when -Ce is set
-       atf_check -s not-exit:0 -o empty -e not-empty "${TEST_SH}" -c \
+       atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
                '
                set -Ce
                echo "Fail to Overwrite it now" > Important_File
@@ -188,7 +188,7 @@
                '
 
        # Last check that we can override -C for when we really need to
-       atf_check -s exit:0 -o empty -e empty "${TEST_SH}" -c \
+       atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
                '
                D=$(ls -l Junk_File) || exit 1
                set -C
@@ -208,17 +208,17 @@
 
        # Check that -e does nothing if no commands fail
        atf_check -s exit:0 -o match:I_am_OK -e empty \
-           "${TEST_SH}" -c \
+           ${TEST_SH} -c \
                'false; printf "%s" I_am; set -e; true; printf "%s\n" _OK'
 
        # and that it (silently, but with exit status) aborts if cmd fails
        atf_check -s not-exit:0 -o match:I_am -o not-match:Broken -e empty \
-           "${TEST_SH}" -c \
+           ${TEST_SH} -c \
                'false; printf "%s" I_am; set -e; false; printf "%s\n" _Broken'
 
        # same, except -e this time is on from the beginning
        atf_check -s not-exit:0 -o match:I_am -o not-match:Broken -e empty \
-           "${TEST_SH}" -ec 'printf "%s" I_am; false; printf "%s\n" _Broken'
+           ${TEST_SH} -ec 'printf "%s" I_am; false; printf "%s\n" _Broken'
 
        # More checking of -e in other places, there is lots to deal with.
 }
@@ -247,12 +247,12 @@
                echo "$f" > "$f"
        done
 
-       atf_check -s exit:0 -o empty -e empty "${TEST_SH}" -ec \
+       atf_check -s exit:0 -o empty -e empty ${TEST_SH} -ec \
            'X=$(echo b*); Y=$(echo b*); test "${X}" != "a*";
                test "${X}" = "${Y}"'
 
        # now test expansion is different when -f is set
-       atf_check -s exit:0 -o empty -e empty "${TEST_SH}" -ec \
+       atf_check -s exit:0 -o empty -e empty ${TEST_SH} -ec \
           'X=$(echo b*); Y=$(set -f; echo b*); test "${X}" != "${Y}"'
 }
 
@@ -268,18 +268,84 @@
 
        # nothing should be executed, hence no output...
        atf_check -s exit:0 -o empty -e empty \
-               "${TEST_SH}" -enc 'echo ABANDON HOPE; echo ALL YE; echo ...'
+               ${TEST_SH} -enc 'echo ABANDON HOPE; echo ALL YE; echo ...'
 
        # this is true even when the "commands" do not exist
        atf_check -s exit:0 -o empty -e empty \
-               "${TEST_SH}" -enc 'ERR; FAIL; ABANDON HOPE'
+               ${TEST_SH} -enc 'ERR; FAIL; ABANDON HOPE'
 
-       # but if there is a syntax error, it should be detected
+       # but if there is a syntax error, it should be detected (w or w/o -e)
+       atf_check -s not-exit:0 -o empty -e not-empty \
+               ${TEST_SH} -enc 'echo JUMP; for frogs swim; echo in puddles'
+       atf_check -s not-exit:0 -o empty -e not-empty \
+               ${TEST_SH} -nc 'echo ABANDON HOPE; echo "ALL YE; echo ...'
+       atf_check -s not-exit:0 -o empty -e not-empty \
+               ${TEST_SH} -enc 'echo ABANDON HOPE;; echo ALL YE; echo ...'
        atf_check -s not-exit:0 -o empty -e not-empty \
-               "${TEST_SH}" -enc 'echo JUMP; for frogs swim; echo in puddles'
+               ${TEST_SH} -nc 'do YOU ABANDON HOPE; for all eternity?'
+
+       # now test enabling -n in the middle of a script
+       # note that once turned on, it cannot be turned off again.
+       #
+       # omit more complex cases, as those can send some shells
+       # into infinite loops, and believe it or not, that might be OK!
+
+       atf_check -s exit:0 -o match:first -o not-match:second -e empty \
+               ${TEST_SH} -c 'echo first; set -n; echo second'
+       atf_check -s exit:0 -o match:first -o not-match:third -e empty \



Home | Main Index | Thread Index | Old Index