From: Buck Evan <workitharder@gmail.com>
To: dash@vger.kernel.org
Cc: Buck Evan <workitharder@gmail.com>
Subject: [PATCH 1/1] add tests
Date: Sat, 6 Jul 2024 14:44:16 -0500 [thread overview]
Message-ID: <20240706194424.5412-2-workitharder@gmail.com> (raw)
In-Reply-To: <20240706194424.5412-1-workitharder@gmail.com>
---
.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
next prev parent reply other threads:[~2024-07-06 19:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-06 19:44 [PATCH 0/1] adding a test suite Buck Evan
2024-07-06 19:44 ` Buck Evan [this message]
2024-07-28 2:01 ` [PATCH 1/1] add tests Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240706194424.5412-2-workitharder@gmail.com \
--to=workitharder@gmail.com \
--cc=dash@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox