summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/appendop.right9
-rw-r--r--tests/appendop.tests4
-rw-r--r--tests/appendop2.sub18
-rw-r--r--tests/case.right11
-rw-r--r--tests/case.tests3
-rw-r--r--tests/case1.sub64
-rw-r--r--tests/nquote.right18
-rw-r--r--tests/nquote.tests1
-rw-r--r--tests/nquote2.sub29
-rw-r--r--tests/posix2.tests2
-rw-r--r--tests/trap.right18
-rw-r--r--tests/trap.tests2
-rw-r--r--tests/trap4.sub25
-rw-r--r--tests/trap5.sub18
14 files changed, 218 insertions, 4 deletions
diff --git a/tests/appendop.right b/tests/appendop.right
index 5d55b9c2..9c867921 100644
--- a/tests/appendop.right
+++ b/tests/appendop.right
@@ -1,7 +1,7 @@
14
1 2 3 4 5 6
1 2 3 4 51 6
-5
+145
14
7
42
@@ -15,9 +15,14 @@
4
9
16
-./appendop.tests: line 83: x: readonly variable
+./appendop.tests: line 84: x: readonly variable
declare -A foo='([one]="bar" [two]="baz" [three]="quux" )'
declare -A foo='([one]="bar" [two]="baz" [0]="zero" [three]="quux" )'
declare -A foo='([four]="four" [one]="bar" [two]="baz" [0]="zero" [three]="quux" )'
declare -ai iarr='([0]="3" [1]="2" [2]="3")'
declare -ai iarr='([0]="3" [1]="2" [2]="3" [3]="4" [4]="5" [5]="6")'
+25 25
+7 7
+14
+145
+145 145
diff --git a/tests/appendop.tests b/tests/appendop.tests
index be6c9716..e4e52c2f 100644
--- a/tests/appendop.tests
+++ b/tests/appendop.tests
@@ -12,7 +12,8 @@ x[4]+=1
echo ${x[@]}
# trickier cases
-
+# post-bash-4.2: bash understands += in environment assignments preceding
+# command names
a+=5 printenv a
echo $a
@@ -83,3 +84,4 @@ echo $x
x+=5
${THIS_SH} ./appendop1.sub
+${THIS_SH} ./appendop2.sub
diff --git a/tests/appendop2.sub b/tests/appendop2.sub
new file mode 100644
index 00000000..4225ba3f
--- /dev/null
+++ b/tests/appendop2.sub
@@ -0,0 +1,18 @@
+POSIXLY_CORRECT=1
+x=2
+x+=5 eval printf '"$x "'
+echo "$x"
+
+unset x
+typeset -i x=2
+x+=5 eval printf '"$x "'
+echo "$x"
+
+a=1
+a+=4
+echo $a
+
+# idiotically, ksh93 makes these two cases differ (?)
+a+=5 printenv a
+a+=5 eval printf '"$a "'
+echo $a
diff --git a/tests/case.right b/tests/case.right
index 52fb8a14..58ab2a4f 100644
--- a/tests/case.right
+++ b/tests/case.right
@@ -7,3 +7,14 @@ no more clauses
1.0
./case.tests: line 29: xx: readonly variable
1.1
+ok 1
+ok 2
+ok 3
+ok 4
+ok 5
+ok 6
+ok 7
+ok 8
+ok 9
+mysterious 1
+mysterious 2
diff --git a/tests/case.tests b/tests/case.tests
index 37e7fb92..547e8ccd 100644
--- a/tests/case.tests
+++ b/tests/case.tests
@@ -28,3 +28,6 @@ unset x
readonly xx=1
case 1 in $((xx++)) ) echo hi1 ;; *) echo hi2; esac
echo ${xx}.$?
+
+# tests of quote removal and pattern matching
+${THIS_SH} ./case1.sub
diff --git a/tests/case1.sub b/tests/case1.sub
new file mode 100644
index 00000000..7db09ab2
--- /dev/null
+++ b/tests/case1.sub
@@ -0,0 +1,64 @@
+x='\x'
+
+case x in
+\x) echo ok 1;;
+*) echo bad 1;;
+esac
+
+case x in
+$x) echo ok 2;;
+*) echo bad 2;;
+esac
+
+case $x in
+\x) echo bad 3;;
+\\x) echo ok 3 ;;
+*) echo bad 3.1 ;;
+esac
+
+case $x in
+\\$x) echo ok 4 ;;
+x) echo bad 4;;
+$x) echo bad 4.1 ;;
+*) echo bad 4.2;;
+esac
+
+case x in
+\\x) echo bad 5;;
+\x) echo ok 5;;
+*) echo bad 5.1;;
+esac
+
+case x in
+\\x) echo bad 6;;
+x) echo ok 6;;
+*) echo bad 6.1;;
+esac
+
+case x in
+$x) echo ok 7 ;;
+\\$x) echo bad 7 ;;
+*) echo bad 7.1 ;;
+esac
+
+case x in
+\x) echo ok 8 ;;
+\\x) echo bad 8 ;;
+*) echo bad 8.1 ;;
+esac
+
+case \x in
+\x) echo ok 9 ;;
+\\x) echo bad 9 ;;
+*) echo bad 9.1 ;;
+esac
+
+case $x in
+$x) echo oops 1 ;;
+*) echo mysterious 1 ;;
+esac
+
+case \x in
+\x) echo mysterious 2 ;;
+*) echo oops 2 ;;
+esac
diff --git a/tests/nquote.right b/tests/nquote.right
index 267f0e7f..9d1290ef 100644
--- a/tests/nquote.right
+++ b/tests/nquote.right
@@ -38,3 +38,21 @@ argv[1] = <'A^IB'>
hello' world
hello world!
hello' world!
+' | '
+' | '
+x | x
+x | x
+' | '
+' | '
+' | '
+' | '
+' | '
+' | '
+x | x
+'
+$'\''
+'
+'abcd'
+$'\'abcd\''
+'
+1
diff --git a/tests/nquote.tests b/tests/nquote.tests
index 720c3e15..aa0a9d88 100644
--- a/tests/nquote.tests
+++ b/tests/nquote.tests
@@ -116,3 +116,4 @@ recho "${mytab:-$'\t'}"
recho "$( args $'A\tB' )"
${THIS_SH} ./nquote1.sub
+${THIS_SH} ./nquote2.sub
diff --git a/tests/nquote2.sub b/tests/nquote2.sub
new file mode 100644
index 00000000..d3325f17
--- /dev/null
+++ b/tests/nquote2.sub
@@ -0,0 +1,29 @@
+t() {
+ printf '%s | %s\n' "$1" "$2"
+ }
+ v="'" # v <- '
+
+ #--
+ t "${v/$'\''/$'\''}" "'"
+ t ${v/$'\''/$'\''} "'"
+ t "${v/$'\''/x}" "x"
+ t ${v/$'\''/x} "x"
+ t "${v/x/$'\''}" "'"
+ t ${v/x/$'\''} "'"
+ t "${v/x/$'\x5c\''}" "'"
+ t ${v/x/$'\x5c\''} "'"
+ t "${v/\'/\'}" "'"
+ t ${v/\'/\'} "'"
+ t ${v/\'/x} "x"
+
+echo "'"
+echo "$'\''"
+
+echo $'\''
+
+echo $'\'abcd\''
+echo "$'\'abcd\''"
+
+v=1
+echo ${v/1/\'}
+echo ${v/\'/2}
diff --git a/tests/posix2.tests b/tests/posix2.tests
index a186e781..d0fb46c6 100644
--- a/tests/posix2.tests
+++ b/tests/posix2.tests
@@ -146,7 +146,7 @@ fi
newtest
SQUOTE="'"
val1=$(set | sed -n 's:^SQUOTE=::p')
-if [ "$val1" != "''\\'''" ]; then
+if [ "$val1" != "\'" ]; then
testfail "variable quoting 1"
fi
diff --git a/tests/trap.right b/tests/trap.right
index c04d1726..1da72a52 100644
--- a/tests/trap.right
+++ b/tests/trap.right
@@ -85,6 +85,24 @@ outside 1
outside 2
outside 3
outside 4
+sleep 2
+wait $!
+exit
+in trap EXIT
+sleep 2
+wait $!
+exit
+in trap EXIT
+works
+bar
+bar
+foo
+trap -- '' SIGINT
+trap -- '' SIGUSR2
+foo
+bar
+foo
+bar
caught a child death
caught a child death
caught a child death
diff --git a/tests/trap.tests b/tests/trap.tests
index e9859ec8..0af03ad7 100644
--- a/tests/trap.tests
+++ b/tests/trap.tests
@@ -70,6 +70,8 @@ ${THIS_SH} ./trap3.sub
${THIS_SH} ./trap4.sub
+${THIS_SH} ./trap5.sub
+
#
# show that setting a trap on SIGCHLD is not disastrous.
#
diff --git a/tests/trap4.sub b/tests/trap4.sub
index 6a8abdac..ab5ca3e3 100644
--- a/tests/trap4.sub
+++ b/tests/trap4.sub
@@ -15,3 +15,28 @@ trap 'echo inherited exit trap' EXIT
: | ( exit; ) | : ; echo outside 4
trap - EXIT
+
+# make sure group commands that are not at the beginning or end of pipelines
+# run an EXIT trap, with and without the exit builtin
+echo ignored |
+{
+ trap 'echo "in trap EXIT">&2' EXIT
+ sleep 4 &
+ echo 'sleep 2'>&2
+ sleep 2
+ echo 'wait $!'>&2
+ wait $!
+ echo 'exit'>&2
+ exit
+} | cat
+
+echo ignored |
+{
+ trap 'echo "in trap EXIT">&2' EXIT
+ sleep 4 &
+ echo 'sleep 2'>&2
+ sleep 2
+ echo 'wait $!'>&2
+ wait $!
+ echo 'exit'>&2
+} | cat
diff --git a/tests/trap5.sub b/tests/trap5.sub
new file mode 100644
index 00000000..7f3380b4
--- /dev/null
+++ b/tests/trap5.sub
@@ -0,0 +1,18 @@
+# make sure process substitution runs the exit trap
+[[ -n $(< <(trap "cat /dev/fd/0" EXIT)) ]] <<<works && echo works || echo "fail :("
+
+read foo < <(trap "echo bar" EXIT)
+echo $foo
+
+cat <(trap "echo bar" EXIT)
+
+trap "echo bar" EXIT #should proc subst inherit this?
+cat <(echo foo ; exit 0;)
+
+trap - 0
+trap
+
+cat <(echo foo; trap "echo bar" EXIT)
+
+trap "echo bar" EXIT #should proc subst inherit this?
+cat <(echo foo)