From f8d98d9978c1100c8d70b9da791ad3f2791538e1 Mon Sep 17 00:00:00 2001 From: Thomas Levine <_@thomaslevine.com> Date: Mon, 29 Feb 2016 12:29:47 +0000 Subject: [PATCH] update shell cycling logic to match documentation and I updated the documentation already because this new way seems easier to think about --- .../$TEST_SHELL should be .special-shell. | 2 +- ... script should be invoked with the specified shell. | 5 +++-- ... script should be invoked with the specified shell. | 2 +- ... variable should be set to the specified shell too. | 2 +- ...nment variable TEST_SHELL should be passed through. | 2 +- ... variable TEST_SHELL should default to sh if empty. | 2 +- ...ption should invoke tests with the specified shell. | 5 +++-- tests/Cross-shell testing/setup | 1 + urchin | 10 +++++++--- 9 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 tests/Cross-shell testing/setup diff --git a/tests/Cross-shell testing/.test-TEST_SHELL-passed-through/$TEST_SHELL should be .special-shell. b/tests/Cross-shell testing/.test-TEST_SHELL-passed-through/$TEST_SHELL should be .special-shell. index d1290f3..511a36b 100755 --- a/tests/Cross-shell testing/.test-TEST_SHELL-passed-through/$TEST_SHELL should be .special-shell. +++ b/tests/Cross-shell testing/.test-TEST_SHELL-passed-through/$TEST_SHELL should be .special-shell. @@ -8,4 +8,4 @@ echo "\$TEST_SHELL: $TEST_SHELL" -[ "$(basename "$TEST_SHELL")" = '.special-shell' ] +basename "$TEST_SHELL" | grep '.special-shell' diff --git a/tests/Cross-shell testing/.test-run-by-specified-shell/With -s, a sh test script should be invoked with the specified shell. b/tests/Cross-shell testing/.test-run-by-specified-shell/With -s, a sh test script should be invoked with the specified shell. index 3ba7be7..8a7d82d 100755 --- a/tests/Cross-shell testing/.test-run-by-specified-shell/With -s, a sh test script should be invoked with the specified shell. +++ b/tests/Cross-shell testing/.test-run-by-specified-shell/With -s, a sh test script should be invoked with the specified shell. @@ -1,9 +1,10 @@ #!/bin/sh -# Assuming that urchin was invoked with `-s bash`, this script should be being run with bash. +# This script should run with /bin/sh +# regardless of whether -s or -n is passed. this_shell=$(ps -o pid,comm | sed -n "s/^ *$$//p" | cut -d\ -f2) echo "Running shell: $this_shell" -basename "$this_shell" | grep .special-shell +test $(basename "$this_shell") = sh diff --git a/tests/Cross-shell testing/.test-run-by-specified-shell/With -s, a shebang-less test script should be invoked with the specified shell. b/tests/Cross-shell testing/.test-run-by-specified-shell/With -s, a shebang-less test script should be invoked with the specified shell. index 74a2aa1..e64318b 100755 --- a/tests/Cross-shell testing/.test-run-by-specified-shell/With -s, a shebang-less test script should be invoked with the specified shell. +++ b/tests/Cross-shell testing/.test-run-by-specified-shell/With -s, a shebang-less test script should be invoked with the specified shell. @@ -3,7 +3,7 @@ set -e # Assuming that urchin was invoked with `-s bash`, this script should be being run with bash. -this_shell=$(ps -o pid,comm | sed -n "s/^ *$$//p" | cut -d\ -f2) +this_shell="$(ps -o pid,comm | sed -n "s/^ *$$//p" | cut -d\ -f2)" echo "Running shell: $this_shell" diff --git a/tests/Cross-shell testing/.test-run-by-specified-shell/With -s, the TEST_SHELL environment variable should be set to the specified shell too. b/tests/Cross-shell testing/.test-run-by-specified-shell/With -s, the TEST_SHELL environment variable should be set to the specified shell too. index c10da8e..569be97 100755 --- a/tests/Cross-shell testing/.test-run-by-specified-shell/With -s, the TEST_SHELL environment variable should be set to the specified shell too. +++ b/tests/Cross-shell testing/.test-run-by-specified-shell/With -s, the TEST_SHELL environment variable should be set to the specified shell too. @@ -7,4 +7,4 @@ echo "Running shell: $this_shell" echo "\$TEST_SHELL: $TEST_SHELL" -basename "$this_shell" | grep .special-shell +echo "$TEST_SHELL" | grep .special-shell diff --git a/tests/Cross-shell testing/Environment variable TEST_SHELL should be passed through. b/tests/Cross-shell testing/Environment variable TEST_SHELL should be passed through. index 019afd2..377310f 100755 --- a/tests/Cross-shell testing/Environment variable TEST_SHELL should be passed through. +++ b/tests/Cross-shell testing/Environment variable TEST_SHELL should be passed through. @@ -4,5 +4,5 @@ # (for test scripts that want to invoke shell scripts with a specified shell). # Test if $TEST_SHELL, when placed in urchin's environment, is passed through to the test scripts. -TEST_SHELL="$PWD/.special-shell" $TEST_SHELL \ +TEST_SHELL=.special-shell $TEST_SHELL \ ../../urchin --disable-cycling ./.test-TEST_SHELL-passed-through diff --git a/tests/Cross-shell testing/Environment variable TEST_SHELL should default to sh if empty. b/tests/Cross-shell testing/Environment variable TEST_SHELL should default to sh if empty. index a984a70..740f412 100755 --- a/tests/Cross-shell testing/Environment variable TEST_SHELL should default to sh if empty. +++ b/tests/Cross-shell testing/Environment variable TEST_SHELL should default to sh if empty. @@ -5,5 +5,5 @@ # Test if $TEST_SHELL - if *defined, but empty* - is exported with value '/bin/sh' by urchin # and thus has that value inside the scripts. -TEST_SHELL="$PWD/.special-shell" $TEST_SHELL \ +TEST_SHELL= $TEST_SHELL \ ../../urchin ./.test-TEST_SHELL-undefined_or_empty diff --git a/tests/Cross-shell testing/The -s option should invoke tests with the specified shell. b/tests/Cross-shell testing/The -s option should invoke tests with the specified shell. index a05b453..21d29f7 100755 --- a/tests/Cross-shell testing/The -s option should invoke tests with the specified shell. +++ b/tests/Cross-shell testing/The -s option should invoke tests with the specified shell. @@ -1,4 +1,5 @@ #!/bin/sh -# Tests the `-s option, which invokes shebang-less and sh-shebang-line test scripts with the specified shell (for testing *sourced* shell code). -../../urchin -s "$PWD/.special-shell" ./.test-run-by-specified-shell +# Tests the `-s option, which invokes shebang-less test scripts with +# the specified shell (for testing *sourced* shell code). +../../urchin -s .special-shell ./.test-run-by-specified-shell diff --git a/tests/Cross-shell testing/setup b/tests/Cross-shell testing/setup new file mode 100644 index 0000000..7d1f9cb --- /dev/null +++ b/tests/Cross-shell testing/setup @@ -0,0 +1 @@ +export PATH="$PWD:$PATH" diff --git a/urchin b/urchin index 25851bf..0866000 100755 --- a/urchin +++ b/urchin @@ -192,9 +192,13 @@ recurse() { start=$(date +%s) set +e { - if $cycle_shell && ! has_shebang_line "$potential_test"; then - TEST_SHELL="$the_test_shell" $TIMEOUT \ - "$the_test_shell" "$potential_test" + if $cycle_shell; then + if has_shebang_line "$potential_test"; then + TEST_SHELL="$the_test_shell" $TIMEOUT "$potential_test" + else + TEST_SHELL="$the_test_shell" $TIMEOUT \ + "$the_test_shell" "$potential_test" + fi else # Shell cycling is disabled with -n; use the present value of # TEST_SHELL or default to /bin/sh