* [PATCH 0/1] adding a test suite
@ 2024-07-06 19:44 Buck Evan
2024-07-06 19:44 ` [PATCH 1/1] add tests Buck Evan
0 siblings, 1 reply; 3+ messages in thread
From: Buck Evan @ 2024-07-06 19:44 UTC (permalink / raw)
To: dash; +Cc: Buck Evan
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
--
2.42.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/1] add tests
2024-07-06 19:44 [PATCH 0/1] adding a test suite Buck Evan
@ 2024-07-06 19:44 ` Buck Evan
2024-07-28 2:01 ` Herbert Xu
0 siblings, 1 reply; 3+ messages in thread
From: Buck Evan @ 2024-07-06 19:44 UTC (permalink / raw)
To: dash; +Cc: Buck Evan
---
.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
diff --git a/.gitignore b/.gitignore
index e349901..1827ca2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -40,3 +40,6 @@ Makefile
.Spotlight*
.Trash*
*[Tt]humbs.db
+
+# vim
+.*.sw[a-z]
diff --git a/test b/test
new file mode 100755
index 0000000..8d214f5
--- /dev/null
+++ b/test
@@ -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
diff --git a/tests/async-subshell-unignore-signal/result.txt b/tests/async-subshell-unignore-signal/result.txt
new file mode 100644
index 0000000..e96c3ad
--- /dev/null
+++ b/tests/async-subshell-unignore-signal/result.txt
@@ -0,0 +1,4 @@
+Scenario 0: "set -i" makes a subshell un-ignore SIGINT.
+Scenario 1: resetting SIGINT handler.
+Scenario 2: ignoring SIGINT.
+OK
diff --git a/tests/async-subshell-unignore-signal/test.sh b/tests/async-subshell-unignore-signal/test.sh
new file mode 100755
index 0000000..35ae9aa
--- /dev/null
+++ b/tests/async-subshell-unignore-signal/test.sh
@@ -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
diff --git a/tests/backslash-outside-quotes/result.txt b/tests/backslash-outside-quotes/result.txt
new file mode 100644
index 0000000..030ebde
--- /dev/null
+++ b/tests/backslash-outside-quotes/result.txt
@@ -0,0 +1 @@
+/b/c/
diff --git a/tests/backslash-outside-quotes/test.sh b/tests/backslash-outside-quotes/test.sh
new file mode 100755
index 0000000..4b3a476
--- /dev/null
+++ b/tests/backslash-outside-quotes/test.sh
@@ -0,0 +1,4 @@
+#!./src/dash
+a=/b/c/*
+b=\\
+echo ${a%$b*}
diff --git a/tests/dollar-dash-expansion/result.txt b/tests/dollar-dash-expansion/result.txt
new file mode 100644
index 0000000..dfafdb2
--- /dev/null
+++ b/tests/dollar-dash-expansion/result.txt
@@ -0,0 +1,3 @@
+0: the options are e
+1: the options are fe
+2: the options are ufe
diff --git a/tests/dollar-dash-expansion/test.sh b/tests/dollar-dash-expansion/test.sh
new file mode 100755
index 0000000..ba72a12
--- /dev/null
+++ b/tests/dollar-dash-expansion/test.sh
@@ -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 $-"
diff --git a/tests/echo-backslash-c-spillage/result.txt b/tests/echo-backslash-c-spillage/result.txt
new file mode 100644
index 0000000..ecb747d
--- /dev/null
+++ b/tests/echo-backslash-c-spillage/result.txt
@@ -0,0 +1,2 @@
+test\ test
+test\ test
diff --git a/tests/echo-backslash-c-spillage/test.sh b/tests/echo-backslash-c-spillage/test.sh
new file mode 100755
index 0000000..f6f4886
--- /dev/null
+++ b/tests/echo-backslash-c-spillage/test.sh
@@ -0,0 +1,4 @@
+#!./src/dash
+echo test\\ test
+echo '\c'
+echo test\\ test
diff --git a/tests/eval-empty/result.txt b/tests/eval-empty/result.txt
new file mode 100644
index 0000000..d86bac9
--- /dev/null
+++ b/tests/eval-empty/result.txt
@@ -0,0 +1 @@
+OK
diff --git a/tests/eval-empty/test.sh b/tests/eval-empty/test.sh
new file mode 100755
index 0000000..d1d1772
--- /dev/null
+++ b/tests/eval-empty/test.sh
@@ -0,0 +1,7 @@
+#!./src/dash
+false
+if eval ''; then
+ echo OK
+else
+ echo not ok
+fi
diff --git a/tests/expmeta-nonleading-slash/result.txt b/tests/expmeta-nonleading-slash/result.txt
new file mode 100644
index 0000000..b555872
--- /dev/null
+++ b/tests/expmeta-nonleading-slash/result.txt
@@ -0,0 +1 @@
+/dev/null
diff --git a/tests/expmeta-nonleading-slash/test.sh b/tests/expmeta-nonleading-slash/test.sh
new file mode 100755
index 0000000..711e1a7
--- /dev/null
+++ b/tests/expmeta-nonleading-slash/test.sh
@@ -0,0 +1,2 @@
+#!./src/dash
+echo /*"/null"
diff --git a/tests/expmeta-slash-treatment/result.txt b/tests/expmeta-slash-treatment/result.txt
new file mode 100644
index 0000000..cd3d018
--- /dev/null
+++ b/tests/expmeta-slash-treatment/result.txt
@@ -0,0 +1 @@
+/root
diff --git a/tests/expmeta-slash-treatment/test.sh b/tests/expmeta-slash-treatment/test.sh
new file mode 100755
index 0000000..735f69b
--- /dev/null
+++ b/tests/expmeta-slash-treatment/test.sh
@@ -0,0 +1,2 @@
+#!./src/dash
+echo "/"root*
diff --git a/tests/ifs-after-heredoc/result.txt b/tests/ifs-after-heredoc/result.txt
new file mode 100644
index 0000000..3b7172a
--- /dev/null
+++ b/tests/ifs-after-heredoc/result.txt
@@ -0,0 +1,2 @@
+abcdefghijklmnopqrstuvwxyz
+OK
diff --git a/tests/ifs-after-heredoc/test.sh b/tests/ifs-after-heredoc/test.sh
new file mode 100755
index 0000000..2f0a96e
--- /dev/null
+++ b/tests/ifs-after-heredoc/test.sh
@@ -0,0 +1,7 @@
+#!./src/dash
+dash -c '
+cat <<EOF
+$@
+EOF
+echo OK
+' - abcdefghijklmnopqrstuvwxyz
diff --git a/tests/naked-backslash-leakage/result.txt b/tests/naked-backslash-leakage/result.txt
new file mode 100644
index 0000000..dcb7930
--- /dev/null
+++ b/tests/naked-backslash-leakage/result.txt
@@ -0,0 +1 @@
+<bc>
diff --git a/tests/naked-backslash-leakage/test.sh b/tests/naked-backslash-leakage/test.sh
new file mode 100755
index 0000000..66df7bd
--- /dev/null
+++ b/tests/naked-backslash-leakage/test.sh
@@ -0,0 +1,5 @@
+#!./src/dash
+a="\\*bc"
+b="\\"
+c="*"
+echo "<${a##$b"$c"}>"
diff --git a/tests/no-space/result.txt b/tests/no-space/result.txt
new file mode 100644
index 0000000..e714e38
--- /dev/null
+++ b/tests/no-space/result.txt
@@ -0,0 +1,2 @@
+./tests/no-space/test.sh: 2: echo: echo: I/O error
+(exit: 1)
diff --git a/tests/no-space/test.sh b/tests/no-space/test.sh
new file mode 100755
index 0000000..dc9cb42
--- /dev/null
+++ b/tests/no-space/test.sh
@@ -0,0 +1,2 @@
+#!./src/dash
+echo foo >>/dev/full
--
2.42.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] add tests
2024-07-06 19:44 ` [PATCH 1/1] add tests Buck Evan
@ 2024-07-28 2:01 ` Herbert Xu
0 siblings, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2024-07-28 2:01 UTC (permalink / raw)
To: Buck Evan; +Cc: dash
On Sat, Jul 06, 2024 at 07:44:16PM +0000, Buck Evan wrote:
>
> diff --git a/test b/test
> new file mode 100755
> index 0000000..8d214f5
> --- /dev/null
> +++ b/test
> @@ -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.
> +if [ "$#" -eq 0 ]; then
> + # default arguments: all tests
> + set -- ./tests/*
> +fi
Please use tabs for indentation.
> +for test in "$@"; do
This could simply be
for test; do
Thanks,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-07-28 2:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-06 19:44 [PATCH 0/1] adding a test suite Buck Evan
2024-07-06 19:44 ` [PATCH 1/1] add tests Buck Evan
2024-07-28 2:01 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox