Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ Makefile
.Spotlight*
.Trash*
*[Tt]humbs.db

# vim
.*.sw[a-z]
33 changes: 33 additions & 0 deletions test
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions tests/async-subshell-unignore-signal/result.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Scenario 0: "set -i" makes a subshell un-ignore SIGINT.
Scenario 1: resetting SIGINT handler.
Scenario 2: ignoring SIGINT.
OK
38 changes: 38 additions & 0 deletions tests/async-subshell-unignore-signal/test.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions tests/backslash-outside-quotes/result.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/b/c/
4 changes: 4 additions & 0 deletions tests/backslash-outside-quotes/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!./src/dash
a=/b/c/*
b=\\
echo ${a%$b*}
3 changes: 3 additions & 0 deletions tests/dollar-dash-expansion/result.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0: the options are e
1: the options are fe
2: the options are ufe
7 changes: 7 additions & 0 deletions tests/dollar-dash-expansion/test.sh
Original file line number Diff line number Diff line change
@@ -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 $-"
2 changes: 2 additions & 0 deletions tests/echo-backslash-c-spillage/result.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test\ test
test\ test
4 changes: 4 additions & 0 deletions tests/echo-backslash-c-spillage/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!./src/dash
echo test\\ test
echo '\c'
echo test\\ test
1 change: 1 addition & 0 deletions tests/eval-empty/result.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OK
7 changes: 7 additions & 0 deletions tests/eval-empty/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!./src/dash
false
if eval ''; then
echo OK
else
echo not ok
fi
1 change: 1 addition & 0 deletions tests/expmeta-nonleading-slash/result.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dev/null
2 changes: 2 additions & 0 deletions tests/expmeta-nonleading-slash/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!./src/dash
echo /*"/null"
1 change: 1 addition & 0 deletions tests/expmeta-slash-treatment/result.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/root
2 changes: 2 additions & 0 deletions tests/expmeta-slash-treatment/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!./src/dash
echo "/"root*
2 changes: 2 additions & 0 deletions tests/ifs-after-heredoc/result.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
abcdefghijklmnopqrstuvwxyz
OK
7 changes: 7 additions & 0 deletions tests/ifs-after-heredoc/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!./src/dash
dash -c '
cat <<EOF
$@
EOF
echo OK
' - abcdefghijklmnopqrstuvwxyz
1 change: 1 addition & 0 deletions tests/naked-backslash-leakage/result.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<bc>
5 changes: 5 additions & 0 deletions tests/naked-backslash-leakage/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!./src/dash
a="\\*bc"
b="\\"
c="*"
echo "<${a##$b"$c"}>"
2 changes: 2 additions & 0 deletions tests/no-space/result.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
./tests/no-space/test.sh: 2: echo: echo: I/O error
(exit: 1)
2 changes: 2 additions & 0 deletions tests/no-space/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!./src/dash
echo foo >>/dev/full