adding a test suite
cover adding a test suite
I pulled these test cases out of the git log. I could do more but wanted to see if this work is welcome first.
I also created a pull request at
https://github.com/herbertx/dash/pull/7, just in case that's easier.
Buck Evan (1):
add tests
.gitignore | 3 ++ test | 33 ++++++++++++++++ .../async-subshell-unignore-signal/result.txt | 4 ++ tests/async-subshell-unignore-signal/test.sh | 38 +++++++++++++++++++ tests/backslash-outside-quotes/result.txt | 1 + tests/backslash-outside-quotes/test.sh | 4 ++ tests/dollar-dash-expansion/result.txt | 3 ++ tests/dollar-dash-expansion/test.sh | 7 ++++ tests/echo-backslash-c-spillage/result.txt | 2 + tests/echo-backslash-c-spillage/test.sh | 4 ++ tests/eval-empty/result.txt | 1 + tests/eval-empty/test.sh | 7 ++++ tests/expmeta-nonleading-slash/result.txt | 1 + tests/expmeta-nonleading-slash/test.sh | 2 + tests/expmeta-slash-treatment/result.txt | 1 + tests/expmeta-slash-treatment/test.sh | 2 + tests/ifs-after-heredoc/result.txt | 2 + tests/ifs-after-heredoc/test.sh | 7 ++++ tests/naked-backslash-leakage/result.txt | 1 + tests/naked-backslash-leakage/test.sh | 5 +++ tests/no-space/result.txt | 2 + tests/no-space/test.sh | 2 + 22 files changed, 132 insertions(+) create mode 100755 test create mode 100644 tests/async-subshell-unignore-signal/result.txt create mode 100755 tests/async-subshell-unignore-signal/test.sh create mode 100644 tests/backslash-outside-quotes/result.txt create mode 100755 tests/backslash-outside-quotes/test.sh create mode 100644 tests/dollar-dash-expansion/result.txt create mode 100755 tests/dollar-dash-expansion/test.sh create mode 100644 tests/echo-backslash-c-spillage/result.txt create mode 100755 tests/echo-backslash-c-spillage/test.sh create mode 100644 tests/eval-empty/result.txt create mode 100755 tests/eval-empty/test.sh create mode 100644 tests/expmeta-nonleading-slash/result.txt create mode 100755 tests/expmeta-nonleading-slash/test.sh create mode 100644 tests/expmeta-slash-treatment/result.txt create mode 100755 tests/expmeta-slash-treatment/test.sh create mode 100644 tests/ifs-after-heredoc/result.txt create mode 100755 tests/ifs-after-heredoc/test.sh create mode 100644 tests/naked-backslash-leakage/result.txt create mode 100755 tests/naked-backslash-leakage/test.sh create mode 100644 tests/no-space/result.txt create mode 100755 tests/no-space/test.sh
Signature · 1 line
2.42.0
PATCH 1/1 add tests
--- .gitignore | 3 ++ test | 33 ++++++++++++++++ .../async-subshell-unignore-signal/result.txt | 4 ++ tests/async-subshell-unignore-signal/test.sh | 38 +++++++++++++++++++ tests/backslash-outside-quotes/result.txt | 1 + tests/backslash-outside-quotes/test.sh | 4 ++ tests/dollar-dash-expansion/result.txt | 3 ++ tests/dollar-dash-expansion/test.sh | 7 ++++ tests/echo-backslash-c-spillage/result.txt | 2 + tests/echo-backslash-c-spillage/test.sh | 4 ++ tests/eval-empty/result.txt | 1 + tests/eval-empty/test.sh | 7 ++++ tests/expmeta-nonleading-slash/result.txt | 1 + tests/expmeta-nonleading-slash/test.sh | 2 + tests/expmeta-slash-treatment/result.txt | 1 + tests/expmeta-slash-treatment/test.sh | 2 + tests/ifs-after-heredoc/result.txt | 2 + tests/ifs-after-heredoc/test.sh | 7 ++++ tests/naked-backslash-leakage/result.txt | 1 + tests/naked-backslash-leakage/test.sh | 5 +++ tests/no-space/result.txt | 2 + tests/no-space/test.sh | 2 + 22 files changed, 132 insertions(+) create mode 100755 test create mode 100644 tests/async-subshell-unignore-signal/result.txt create mode 100755 tests/async-subshell-unignore-signal/test.sh create mode 100644 tests/backslash-outside-quotes/result.txt create mode 100755 tests/backslash-outside-quotes/test.sh create mode 100644 tests/dollar-dash-expansion/result.txt create mode 100755 tests/dollar-dash-expansion/test.sh create mode 100644 tests/echo-backslash-c-spillage/result.txt create mode 100755 tests/echo-backslash-c-spillage/test.sh create mode 100644 tests/eval-empty/result.txt create mode 100755 tests/eval-empty/test.sh create mode 100644 tests/expmeta-nonleading-slash/result.txt create mode 100755 tests/expmeta-nonleading-slash/test.sh create mode 100644 tests/expmeta-slash-treatment/result.txt create mode 100755 tests/expmeta-slash-treatment/test.sh create mode 100644 tests/ifs-after-heredoc/result.txt create mode 100755 tests/ifs-after-heredoc/test.sh create mode 100644 tests/naked-backslash-leakage/result.txt create mode 100755 tests/naked-backslash-leakage/test.sh create mode 100644 tests/no-space/result.txt create mode 100755 tests/no-space/test.sh
.gitignore +3 -0
@@ -40,3 +40,6 @@ Makefile .Spotlight* .Trash* *[Tt]humbs.db + +# vim +.*.sw[a-z]
test new file +33 -0
@@ -0,0 +1,33 @@ +#!/bin/sh +set -eu +export PATH="$PWD/src:$PATH" +if [ "$#" -eq 0 ]; then + # default arguments: all tests + set -- ./tests/* +fi + +success=true +for test in "$@"; do + printf "%-40s " "$test" + if "$test/test.sh" >"$test/result.txt" 2>&1; then + : + else + exit="$?" + echo "(exit: $exit)" >>"$test/result.txt" + fi + if git diff --quiet --exit-code "$test/result.txt"; then + echo PASS + else + echo FAIL + git diff "$test/result.txt" + echo + success=false + fi +done + +if "$success"; then + echo PASS +else + echo FAIL + exit 1 +fi
tests/async-subshell-unignore-signal/result.txt new file +4 -0
@@ -0,0 +1,4 @@ +Scenario 0: "set -i" makes a subshell un-ignore SIGINT. +Scenario 1: resetting SIGINT handler. +Scenario 2: ignoring SIGINT. +OK
tests/async-subshell-unignore-signal/test.sh new file +38 -0
@@ -0,0 +1,38 @@ +#!/bin/sh +shell=src/dash + +set -e + +SubshellWith() { + parent_pid=$(setsid "$shell" -c "( $1; sleep 99 ) </dev/null >/dev/null 2>&1 & echo \$\$") + sleep 1 + subshell_pid=$(ps -o pid= -$parent_pid | tail -n 1) +} + +trap 'kill -TERM -$parent_pid 2>/dev//null ||:' EXIT # Tear down after a failure. + +echo Scenario 0: '"set -i"' makes a subshell un-ignore SIGINT. +SubshellWith 'set -i' +kill -INT $subshell_pid +if ps -p $subshell_pid | grep -q sleep; then + echo FAIL +fi +kill -TERM -$parent_pid 2>/dev//null ||: # Tear down. + +echo Scenario 1: resetting SIGINT handler. +SubshellWith 'trap - INT' +kill -INT -$parent_pid # kill the whole process group since that's the my use case +if ps -p $subshell_pid | grep -q sleep; then + echo FAIL +fi +kill -TERM -$parent_pid 2>/dev//null ||: # Tear down. + +echo Scenario 2: ignoring SIGINT. +SubshellWith 'trap "" INT' +kill -INT $subshell_pid +if ! ps -p $subshell_pid | grep -q sleep; then + echo FAIL +fi +kill -TERM -$parent_pid 2>/dev//null ||: # Tear down. + +echo OK
tests/backslash-outside-quotes/result.txt new file +1 -0
@@ -0,0 +1 @@ +/b/c/
tests/backslash-outside-quotes/test.sh new file +4 -0
@@ -0,0 +1,4 @@ +#!./src/dash +a=/b/c/* +b=\\ +echo ${a%$b*}
tests/dollar-dash-expansion/result.txt new file +3 -0
@@ -0,0 +1,3 @@ +0: the options are e +1: the options are fe +2: the options are ufe
tests/dollar-dash-expansion/test.sh new file +7 -0
@@ -0,0 +1,7 @@ +#!./src/dash +set -e +echo "0: the options are $-" +set -fo debug +echo "1: the options are $-" +set +o debug -uo nolog +echo "2: the options are $-"
tests/echo-backslash-c-spillage/result.txt new file +2 -0
@@ -0,0 +1,2 @@ +test\ test +test\ test
tests/echo-backslash-c-spillage/test.sh new file +4 -0
@@ -0,0 +1,4 @@ +#!./src/dash +echo test\\ test +echo '\c' +echo test\\ test
tests/eval-empty/result.txt new file +1 -0
@@ -0,0 +1 @@ +OK
tests/eval-empty/test.sh new file +7 -0
@@ -0,0 +1,7 @@ +#!./src/dash +false +if eval ''; then + echo OK +else + echo not ok +fi
tests/expmeta-nonleading-slash/result.txt new file +1 -0
@@ -0,0 +1 @@ +/dev/null
tests/expmeta-nonleading-slash/test.sh new file +2 -0
@@ -0,0 +1,2 @@ +#!./src/dash +echo /*"/null"
tests/expmeta-slash-treatment/result.txt new file +1 -0
@@ -0,0 +1 @@ +/root
tests/expmeta-slash-treatment/test.sh new file +2 -0
@@ -0,0 +1,2 @@ +#!./src/dash +echo "/"root*
tests/ifs-after-heredoc/result.txt new file +2 -0
@@ -0,0 +1,2 @@ +abcdefghijklmnopqrstuvwxyz +OK
tests/ifs-after-heredoc/test.sh new file +7 -0
@@ -0,0 +1,7 @@ +#!./src/dash +dash -c ' +cat <<EOF +$@ +EOF +echo OK +' - abcdefghijklmnopqrstuvwxyz
tests/naked-backslash-leakage/result.txt new file +1 -0
@@ -0,0 +1 @@ +<bc>
tests/naked-backslash-leakage/test.sh new file +5 -0
@@ -0,0 +1,5 @@ +#!./src/dash +a="\\*bc" +b="\\" +c="*" +echo "<${a##$b"$c"}>"
tests/no-space/result.txt new file +2 -0
@@ -0,0 +1,2 @@ +./tests/no-space/test.sh: 2: echo: echo: I/O error +(exit: 1)
tests/no-space/test.sh new file +2 -0
@@ -0,0 +1,2 @@ +#!./src/dash +echo foo >>/dev/full
Signature · 1 line
2.42.0
Re: [PATCH 1/1] add tests
test line 3
Quoted 10 lines · Buck Evan
test new file +3
-0@@ -0,0 +1,33 @@ +#!/bin/sh +set -eu +export PATH="$PWD/src:$PATH"
It appears that most references to dash are already doing src/dash. So just change the naked calls to dash to do src/dash instead of modifying PATH.
test line 7
Quoted 4 lines
test new file +4
-0+if [ "$#" -eq 0 ]; then + # default arguments: all tests + set -- ./tests/* +fi
Please use tabs for indentation.
test line 10
Quoted 1 line
test new file +1
-0+for test in "$@"; do
This could simply be
for test; do
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt