summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChet Ramey <chet.ramey@case.edu>2018-09-17 15:10:56 -0400
committerChet Ramey <chet.ramey@case.edu>2018-09-17 15:10:56 -0400
commit2f5dfe5a18b4670eb4cea32c1c76295eb70a8865 (patch)
treebf19e42dcaf6c5cf8e0ce0a1c15d56e8f8a6d675 /tests
parent9a51695bed07d37086c352372ac69d0a30039a6b (diff)
downloadbash-5.0-beta.tar.gz
bash-5.0-beta releasebash-5.0-beta
Diffstat (limited to 'tests')
-rw-r--r--tests/array.right120
-rw-r--r--tests/array.tests1
-rw-r--r--tests/array26.sub118
-rw-r--r--tests/assoc.right9
-rw-r--r--tests/assoc.tests2
-rw-r--r--tests/assoc10.sub17
-rw-r--r--tests/histexp.right37
-rw-r--r--tests/histexp.tests2
-rw-r--r--tests/histexp5.sub28
-rw-r--r--tests/histexp6.sub24
-rw-r--r--tests/intl.right5
-rw-r--r--tests/nameref.right43
-rw-r--r--tests/nameref20.sub71
-rw-r--r--tests/nameref21.sub56
-rw-r--r--tests/nquote1.right10
-rw-r--r--tests/nquote1.tests9
-rw-r--r--tests/posixexp.right8
-rw-r--r--tests/posixexp.tests1
-rw-r--r--tests/posixexp5.sub2
-rw-r--r--tests/posixexp7.sub13
-rw-r--r--tests/quote.right34
-rw-r--r--tests/quote.tests1
-rw-r--r--tests/quote2.sub42
-rw-r--r--tests/redir.right2
-rw-r--r--tests/redir.tests3
-rw-r--r--tests/run-varenv2
-rw-r--r--tests/shopt.right5
-rw-r--r--tests/test-glue-functions2
-rw-r--r--tests/unicode3.sub5
-rw-r--r--tests/varenv.right60
-rw-r--r--tests/varenv.tests246
-rw-r--r--tests/varenv12.sub38
-rw-r--r--tests/varenv13.sub23
-rw-r--r--tests/varenv14.sub33
-rw-r--r--tests/varenv15.in3
-rw-r--r--tests/varenv15.sub38
36 files changed, 1101 insertions, 12 deletions
diff --git a/tests/array.right b/tests/array.right
index aab4153d..3c465248 100644
--- a/tests/array.right
+++ b/tests/array.right
@@ -621,3 +621,123 @@ arithmetic:
6.declare -A a=([" "]="13" [0]="0" [1]="1" ["\" \""]="11" )
7.declare -A a=([" "]="13" [0]="0" [1]="1" ["\" \""]="11" )
8.declare -A a=([" "]="13" [0]="0" [1]="1" ["\" \""]="13" )
+argv[1] = <aa>
+argv[2] = <bb>
+argv[1] = <aa>
+argv[2] = <bb>
+argv[1] = <aa>
+argv[2] = <bb>
+argv[1] = <aa>
+argv[2] = <bb>
+argv[1] = <aa>
+argv[2] = <bb>
+argv[3] = <aa>
+argv[4] = <bb>
+argv[1] = <aa>
+argv[2] = <bb>
+argv[3] = <aa>
+argv[4] = <bb>
+argv[1] = <aa+bb>
+argv[2] = <aa+bb>
+argv[1] = <aa>
+argv[2] = <bb>
+argv[3] = <aa>
+argv[4] = <bb>
+argv[1] = <xa>
+argv[2] = <bb>
+argv[1] = <xa>
+argv[2] = <bb>
+argv[1] = <xa>
+argv[2] = <bb>
+argv[1] = <xa>
+argv[2] = <bb>
+argv[1] = <xa>
+argv[2] = <bb>
+argv[1] = <xa>
+argv[2] = <bb>
+argv[1] = <xa+bb>
+argv[1] = <xa+bb>
+argv[1] = <xa+bb>
+argv[2] = <xa+bb>
+argv[1] = <xa>
+argv[2] = <bb>
+argv[1] = <xa>
+argv[2] = <bb>
+argv[1] = <xa>
+argv[2] = <bb>
+argv[1] = <xa+bb>
+argv[1] = <xa>
+argv[2] = <bb>
+argv[1] = <xa>
+argv[2] = <bb>
+argv[1] = <xa>
+argv[2] = <bb>
+argv[1] = <xa>
+argv[2] = <bb>
+argv[1] = <xa>
+argv[2] = <bb>
+argv[1] = <xa>
+argv[2] = <bb>
+argv[1] = <xabb>
+argv[1] = <xabb>
+argv[1] = <xabb>
+argv[2] = <xabb>
+argv[1] = <xa>
+argv[2] = <bb>
+argv[1] = <xa>
+argv[2] = <bb>
+argv[1] = <xa>
+argv[2] = <bb>
+argv[1] = <xabb>
+argv[1] = <aa>
+argv[2] = <bb>
+argv[1] = <aa>
+argv[2] = <bb>
+argv[1] = <aa>
+argv[2] = <bb>
+argv[1] = <aa>
+argv[2] = <bb>
+argv[1] = <aa>
+argv[2] = <bb>
+argv[3] = <aa>
+argv[4] = <bb>
+argv[1] = <aa>
+argv[2] = <bb>
+argv[3] = <aa>
+argv[4] = <bb>
+argv[1] = <aa+bb>
+argv[2] = <aa+bb>
+argv[1] = <aa+bb>
+argv[2] = <aa+bb>
+argv[1] = <aa>
+argv[2] = <bb>
+argv[3] = <aa>
+argv[4] = <bb>
+argv[1] = <aa>
+argv[2] = <bb>
+argv[1] = <aa>
+argv[2] = <bb>
+argv[1] = <aa>
+argv[2] = <bb>
+argv[1] = <aa+bb>
+argv[1] = <a>
+argv[2] = <b>
+argv[1] = <a>
+argv[2] = <b>
+argv[1] = <a>
+argv[2] = <b>
+argv[3] = <a>
+argv[4] = <b>
+argv[1] = <a+b>
+argv[2] = <a+b>
+argv[1] = <a>
+argv[2] = <b>
+argv[3] = <a>
+argv[4] = <b>
+argv[1] = <a>
+argv[2] = <b>
+argv[1] = <a>
+argv[2] = <b>
+argv[1] = <a>
+argv[2] = <b>
+argv[1] = <a+b>
diff --git a/tests/array.tests b/tests/array.tests
index e045d5c4..7fa1cdaf 100644
--- a/tests/array.tests
+++ b/tests/array.tests
@@ -404,3 +404,4 @@ ${THIS_SH} ./array22.sub
${THIS_SH} ./array23.sub
${THIS_SH} ./array24.sub
${THIS_SH} ./array25.sub
+${THIS_SH} ./array26.sub
diff --git a/tests/array26.sub b/tests/array26.sub
new file mode 100644
index 00000000..826774f7
--- /dev/null
+++ b/tests/array26.sub
@@ -0,0 +1,118 @@
+# these should produce the same results
+a=(aa bb)
+set -- aa bb
+
+IFS=+
+
+recho ${a[@]}
+recho ${a[@]:0}
+
+recho $@
+recho ${@:1}
+
+A=${a[*]} B=${a[*]:0}
+recho $* ${*:1}
+recho ${a[*]} ${a[*]:0}
+recho "$A" "$B"
+recho $A $B
+
+unset A B
+
+recho ${@/a/x}
+recho ${a[@]/a/x}
+recho "${@/a/x}"
+recho "${a[@]/a/x}"
+
+recho ${*/a/x}
+recho ${a[*]/a/x}
+recho "${*/a/x}"
+recho "${a[*]/a/x}"
+
+A=${*/a/x}
+B=${a[*]/a/x}
+
+recho "$A" "$B"
+
+unset A B
+declare -A A
+A[0]=aa
+A[1]=bb
+
+recho ${A[@]/a/x}
+recho "${A[@]/a/x}"
+recho ${A[*]/a/x}
+recho "${A[*]/a/x}"
+
+unset A
+IFS=
+
+recho ${@/a/x}
+recho ${a[@]/a/x}
+recho "${@/a/x}"
+recho "${a[@]/a/x}"
+
+recho ${*/a/x}
+recho ${a[*]/a/x}
+recho "${*/a/x}"
+recho "${a[*]/a/x}"
+
+A=${*/a/x}
+B=${a[*]/a/x}
+
+recho "$A" "$B"
+
+unset A B
+declare -A A
+A[0]=aa
+A[1]=bb
+
+recho ${A[@]/a/x}
+recho "${A[@]/a/x}"
+recho ${A[*]/a/x}
+recho "${A[*]/a/x}"
+
+unset A
+
+IFS=+
+
+recho ${a[@]}
+recho ${a[@],,}
+recho "${a[@]}"
+recho "${a[@],,}"
+
+A=${a[*]} B=${a[*],,}
+recho $* ${*,,}
+recho ${a[*]} ${a[*],,}
+recho "${a[*]}" "${a[*],,}"
+recho "$A" "$B"
+recho $A $B
+
+unset A B
+declare -A A
+A[0]=aa
+A[1]=bb
+
+recho ${A[@],,}
+recho "${A[@],,}"
+recho ${A[*],,}
+recho "${A[*],,}"
+
+unset A
+
+recho ${a[@]#?}
+recho ${@#?}
+
+A=${a[*]#?} B=${a[*]#?}
+recho ${*#?} ${a[*]#?}
+recho "$A" "$B"
+recho $A $B
+
+unset A B
+declare -A A
+A[0]=aa
+A[1]=bb
+
+recho ${A[@]#?}
+recho "${A[@]#?}"
+recho ${A[*]#?}
+recho "${A[*]#?}"
diff --git a/tests/assoc.right b/tests/assoc.right
index e10636b2..99143f00 100644
--- a/tests/assoc.right
+++ b/tests/assoc.right
@@ -220,3 +220,12 @@ declare -A a=(["80's"]="Depeche Mode" )
1+5
declare -A a=(["\$(date >&2)"]="5" )
declare -A myarray=([foo]="bleh" ["foo[bar"]="bleh" )
+./assoc10.sub: line 1: declare: a: cannot convert indexed to associative array
+f: declare -a a
+./assoc10.sub: line 4: declare: a: cannot convert associative to indexed array
+f: declare -A a
+
+f: declare -a a
+main: declare -- a="7"
+f: declare -A a
+main: declare -- a="42"
diff --git a/tests/assoc.tests b/tests/assoc.tests
index 24ab08c0..84326c9c 100644
--- a/tests/assoc.tests
+++ b/tests/assoc.tests
@@ -217,3 +217,5 @@ ${THIS_SH} ./assoc8.sub
# new shopt option to prevent multiple expansion of assoc array subscripts
${THIS_SH} ./assoc9.sub
+
+${THIS_SH} ./assoc10.sub
diff --git a/tests/assoc10.sub b/tests/assoc10.sub
new file mode 100644
index 00000000..9eef2cac
--- /dev/null
+++ b/tests/assoc10.sub
@@ -0,0 +1,17 @@
+f() { declare -a a; declare -A a; echo -n "$FUNCNAME: " ; declare -p a; }
+f
+
+f() { declare -A a; declare -a a; echo -n "$FUNCNAME: " ; declare -p a; }
+f
+
+echo
+
+f() { declare -a a; echo -n "$FUNCNAME: " ; declare -p a; }
+a=7
+f
+echo -n 'main: '; declare -p a
+
+f() { declare -A a; echo -n "$FUNCNAME: " ; declare -p a; }
+a=42
+f
+echo -n 'main: '; declare -p a
diff --git a/tests/histexp.right b/tests/histexp.right
index bcf5dea6..9dc592cb 100644
--- a/tests/histexp.right
+++ b/tests/histexp.right
@@ -203,3 +203,40 @@ d
e
! !
./histexp4.sub: line 20: !': event not found
+/tmp/Step1
+echo /$(echo tmp)/Step1
+/tmp/Step1
+echo /<(echo tmp)/Step1 > /dev/null
+/tmp/Step1
+echo $(echo /tmp)/Step1
+/tmp/Step1
+echo <(echo /tmp)/Step1 > /dev/null
+/+(one|two|three)/Step1
+echo /+(one|two|three)/Step1
+/+(one|two|three)/Step1
+/*(tmp|dev|usr)/Step1
+echo /*(tmp|dev|usr)/Step1
+/*(tmp|dev|usr)/Step1
++(/one|/two|/three)/Step1
+echo +(/one|/two|/three)/Step1
++(/one|/two|/three)/Step1
+*(/tmp|/dev|/usr)/Step1
+echo *(/tmp|/dev|/usr)/Step1
+*(/tmp|/dev|/usr)/Step1
+one
+ echo echo one
+echo one
+echo one
+echo one
+ 1 set -o histexpand
+ 2 echo one
+ 3 for f in a b c; do echo echo one; done
+ 4 history
+two
+ echo echo two
+echo two
+echo two
+echo two
+ 1 echo two
+ 2 for f in a b c; do echo echo two; done
+ 3 history
diff --git a/tests/histexp.tests b/tests/histexp.tests
index 2901064f..5ae925e1 100644
--- a/tests/histexp.tests
+++ b/tests/histexp.tests
@@ -140,3 +140,5 @@ ${THIS_SH} ./histexp1.sub
${THIS_SH} ./histexp2.sub
${THIS_SH} ./histexp3.sub
${THIS_SH} ./histexp4.sub
+${THIS_SH} ./histexp5.sub
+${THIS_SH} ./histexp6.sub
diff --git a/tests/histexp5.sub b/tests/histexp5.sub
new file mode 100644
index 00000000..0fe62fe4
--- /dev/null
+++ b/tests/histexp5.sub
@@ -0,0 +1,28 @@
+set -o history
+set -o histexpand
+
+# command and process substitutions should be tokenized as a single word
+echo /$(echo tmp)/Step1
+echo !:*
+echo /<(echo tmp)/Step1 >/dev/null
+echo !:*
+
+# same tests at the beginning of a word
+echo $(echo /tmp)/Step1
+echo !:*
+echo <(echo /tmp)/Step1 >/dev/null
+echo !:*
+
+# so should shell extended glob patterns
+shopt -s extglob
+
+echo /+(one|two|three)/Step1
+echo !:*
+echo /*(tmp|dev|usr)/Step1
+echo !:*
+
+# same tests at the beginning of a word
+echo +(/one|/two|/three)/Step1
+echo !:*
+echo *(/tmp|/dev|/usr)/Step1
+echo !:*
diff --git a/tests/histexp6.sub b/tests/histexp6.sub
new file mode 100644
index 00000000..00610b07
--- /dev/null
+++ b/tests/histexp6.sub
@@ -0,0 +1,24 @@
+unset HISTIGNORE
+HISTFILE=$TMPDIR/bashhist-$$
+
+set -o history
+set -o histexpand
+
+echo one
+
+for f in a b c; do
+ echo !!
+done
+
+history
+history -c
+
+echo two
+for f in a b c; do
+ echo !-1
+done
+
+history
+
+set +o history
+rm -f $HISTFILE
diff --git a/tests/intl.right b/tests/intl.right
index 006318e5..7da99192 100644
--- a/tests/intl.right
+++ b/tests/intl.right
@@ -50,7 +50,8 @@ Passed all 1378 Unicode tests
0000003
0000000 101 040 302 243 040 305 222 012
0000010
-./unicode3.sub: line 3: $'5\247@3\231+\306S8\237\242\352\263': command not found
-./unicode3.sub: line 5: cd: $'5\247@3\231+\306S8\237\242\352\263': No such file or directory
+./unicode3.sub: line 5: $'5\247@3\231+\306S8\237\242\352\263': command not found
+./unicode3.sub: line 7: cd: $'5\247@3\231+\306S8\237\242\352\263': No such file or directory
$'5\247@3\231+\306S8\237\242\352\263'
+ : $'5\247@3\231+\306S8\237\242\352\263'
++ set +x
diff --git a/tests/nameref.right b/tests/nameref.right
index 2ab62b09..698002ec 100644
--- a/tests/nameref.right
+++ b/tests/nameref.right
@@ -440,3 +440,46 @@ declare -n foo="bar"
declare -- bar
declare -- foo="bar"
declare -- bar
+declare -a v=([0]="Y")
+r: <Y>
+v: <Y>
+declare -n ref="var"
+declare -a var=([0]="X")
+declare -n ref="var"
+declare -a var=([0]="X")
+declare -n ref="var"
+./nameref20.sub: line 23: declare: var: not found
+outside:
+declare -a foo=([0]="X")
+declare -n ref="var"
+declare -a var=([0]="X")
+outside:
+./nameref20.sub: line 38: declare: ref: not found
+./nameref20.sub: line 38: declare: var: not found
+declare -n ref="var"
+declare -- var="X"
+outside:
+./nameref20.sub: line 45: declare: ref: not found
+./nameref20.sub: line 45: declare: var: not found
+declare -n ref="var"
+declare -a var=([0]="Y")
+declare -- ref="Y"
+declare -- var="X"
+ref=Y
+declare -- ref="Y"
+./nameref20.sub: line 61: declare: var: not found
+ref=Y
+declare -n ref="var"
+declare -A var=([2]="" )
+declare -n ref="var"
+declare -A var=([2]="" )
+declare -n ref="var"
+declare -a var=([2]="")
+declare -n ref="var"
+declare -a var=([2]="")
+declare -n ref="var"
+declare -ai var=([1]="0")
+declare -n ref="var"
+declare -ai var=([1]="0")
+declare -n ref="var"
+declare -- var="1"
diff --git a/tests/nameref20.sub b/tests/nameref20.sub
new file mode 100644
index 00000000..1e6faec9
--- /dev/null
+++ b/tests/nameref20.sub
@@ -0,0 +1,71 @@
+# a collection of cases in bug reports after bash-5.0-alpha was released
+
+declare -n r=v[0]
+v=(X); r=Y
+declare -p ${!v*}
+printf "%s: <%s>\n" "r" "$r" "v" "$v"
+
+unset -n r
+unset -v v
+
+declare -n ref=var; declare -a ref
+ref=(X)
+declare -p ref var
+
+unset -n ref
+unset -v var
+
+f() { declare -n ref=var; declare ref=(X); declare -p ref var; };
+f
+
+unset -f f
+
+f() { declare -n ref=var; declare -g ref=(X); declare -p ref var; };
+
+declare -n ref=foo
+f
+echo outside:
+declare -p foo
+
+unset -n ref
+unset -v foo
+unset -f f
+
+f() { declare -n ref=var; declare -a ref; ref=(X); declare -p ref var; }
+
+f
+echo outside:
+declare -p ref var
+unset -f f
+
+f() { declare -n ref=var; declare ref; ref=X; declare -p ref var; }
+
+f
+echo outside:
+declare -p ref var
+
+unset -f f
+
+unset -n ref; unset var
+
+f()
+{
+ declare var=X; declare -n ref=var; declare ref=(Y)
+ declare -p ref var
+}
+f
+
+unset -f f
+
+declare -n ref=var
+f() { local ref=Y; declare -p ref var; local; }
+
+var=X
+f
+
+unset -v var
+f
+
+unset -n ref
+unset -f f
+
diff --git a/tests/nameref21.sub b/tests/nameref21.sub
new file mode 100644
index 00000000..a555a084
--- /dev/null
+++ b/tests/nameref21.sub
@@ -0,0 +1,56 @@
+# issues with local variables and local namerefs post-bash-4.4
+
+f()
+{
+ local -n ref=var
+ local -A ref=([1]=)
+# declare -p ref var
+ ref=([2]=)
+ declare -p ref var
+}
+
+unset ref var
+f
+
+unset ref; var=0
+f
+
+unset var
+unset -f f
+
+f()
+{
+ local -n ref=var
+ local -a ref=([1]=)
+ ref=([2]=)
+ declare -p ref var
+}
+
+unset ref var
+f
+
+unset ref; var=0
+f
+
+unset var
+unset -f f
+
+f() { local -n ref=var; local -i ref=([1]=); declare -p ref var; }
+
+unset var
+f
+
+var=0
+f
+
+unset var
+unset -f f
+
+f() { local -n ref=var; local ref=1; declare -p ref var; }
+
+var=0
+f
+
+unset var
+unset -f f
+
diff --git a/tests/nquote1.right b/tests/nquote1.right
index 26e16b91..45389ef3 100644
--- a/tests/nquote1.right
+++ b/tests/nquote1.right
@@ -119,3 +119,13 @@ argv[3] = <uv^Aw^Axy>
argv[1] = <@2>
argv[2] = <uv^Aw^Axy>
argv[3] = <uv^Aw^Axy>
+argv[1] = <aa1>
+argv[2] = <uv^A^A>
+argv[1] = <aa2>
+argv[2] = <uv^A^A>
+argv[1] = <aa3>
+argv[2] = <uv^A^Awx>
+argv[3] = <uv^A^Awx>
+argv[1] = <aa4>
+argv[2] = <uv^A^Awx>
+argv[3] = <uv^A^Awx>
diff --git a/tests/nquote1.tests b/tests/nquote1.tests
index 0970e77c..f47ab54e 100644
--- a/tests/nquote1.tests
+++ b/tests/nquote1.tests
@@ -95,3 +95,12 @@ recho d2 "${1:2:2}"
recho @1 ${@:1:2}
recho @2 "${@:1:2}"
+
+declare -A assoc
+assoc=( [0]=$e [1]=$e )
+
+recho aa1 ${assoc:0:4}
+recho aa2 "${assoc:0:4}"
+
+recho aa3 ${assoc[@]:0:2}
+recho aa4 "${assoc[@]:0:2}"
diff --git a/tests/posixexp.right b/tests/posixexp.right
index 1e81eadb..53a08e3b 100644
--- a/tests/posixexp.right
+++ b/tests/posixexp.right
@@ -275,5 +275,9 @@ argv[2] = <b>
[ abc def ghi jkl / abc def ghi jkl ]
[ abc def ghi jkl ]
[ abc def ghi jkl / abc def ghi jkl / abc def ghi jkl ]
-./posixexp.tests: line 82: unexpected EOF while looking for matching `}'
-./posixexp.tests: line 83: syntax error: unexpected end of file
+5: notOK
+OK
+OK
+5: $'not\ttoo\nbad'
+./posixexp.tests: line 83: unexpected EOF while looking for matching `}'
+./posixexp.tests: line 84: syntax error: unexpected end of file
diff --git a/tests/posixexp.tests b/tests/posixexp.tests
index 76dfede9..3368711f 100644
--- a/tests/posixexp.tests
+++ b/tests/posixexp.tests
@@ -76,6 +76,7 @@ ${THIS_SH} ./posixexp3.sub
${THIS_SH} ./posixexp4.sub
${THIS_SH} ./posixexp5.sub
${THIS_SH} ./posixexp6.sub
+${THIS_SH} ./posixexp7.sub
# this will be an error
foo=bar
diff --git a/tests/posixexp5.sub b/tests/posixexp5.sub
index cceeb00c..e477bbb1 100644
--- a/tests/posixexp5.sub
+++ b/tests/posixexp5.sub
@@ -7,7 +7,7 @@ teststring=$(printf '\1\2\3\177')
n=0
trim_od() {
- od -a | sed -n '1 { s/^0*[[:blank:]]*//; s/[[:blank:]]*$//; p; }'
+ od -t a | sed -n '1 { s/^0*[[:blank:]]*//; s/[[:blank:]]*$//; p; }'
}
doTest() {
diff --git a/tests/posixexp7.sub b/tests/posixexp7.sub
new file mode 100644
index 00000000..2e230cf8
--- /dev/null
+++ b/tests/posixexp7.sub
@@ -0,0 +1,13 @@
+# test the effect of quotes on the WORD in the posix pattern removal operators
+# a here document does not behave the same as double quotes
+x=notOK
+cat <<EOF
+5: ${x#$'not'}
+EOF
+
+echo "${x#'not'}"
+echo "${x#$'not'}"
+
+cat <<EOF
+5: $'not\ttoo\nbad'
+EOF
diff --git a/tests/quote.right b/tests/quote.right
index e4c25741..e4eb9bb9 100644
--- a/tests/quote.right
+++ b/tests/quote.right
@@ -86,3 +86,37 @@ test'string
a'b'c
foo b c baz
foo 'bar baz
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
+=====
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
+=====
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
+=====
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
diff --git a/tests/quote.tests b/tests/quote.tests
index 57ee7e58..d7f13cd0 100644
--- a/tests/quote.tests
+++ b/tests/quote.tests
@@ -121,3 +121,4 @@ echo "${foo:-string \\}"
echo ${foo:-string \\\}}
${THIS_SH} ./quote1.sub
+${THIS_SH} ./quote2.sub
diff --git a/tests/quote2.sub b/tests/quote2.sub
new file mode 100644
index 00000000..7deb4cfa
--- /dev/null
+++ b/tests/quote2.sub
@@ -0,0 +1,42 @@
+x=x
+e=
+
+recho ${x:+""}
+recho ${x:+ ""}
+recho ${x:+"" }
+recho ${x:+"$e"}
+recho ${x:+ "$e"}
+recho ${x:+"$e""$e"""}
+recho ${x:+"$e""$e"""}
+recho ${x:+"$e" "$e"""}
+recho ${x:+"$e""$e" ""}
+recho ${x:+ "$e""$e"""}
+
+echo =====
+recho ${x:+''}
+recho ${x:+ ''}
+recho ${x:+'' }
+recho ${x:+'' ''}
+
+recho ${x:+$e''}
+recho ${x:+''$e}
+
+recho ${x:+''$e $e''}
+
+echo =====
+recho ${x:+"$(:)"}
+recho ${x:+ "$(:)"}
+recho ${x:+"$(:)""$(:)"""}
+recho ${x:+"$(:)""$(:)"""}
+recho ${x:+"$(:)" "$(:)"""}
+recho ${x:+"$(:)""$(:)" ""}
+recho ${x:+ "$(:)""$(:)"""}
+
+echo =====
+recho ${x:+"`:`"}
+recho ${x:+ "`:`"}
+recho ${x:+"`:`""`:`"""}
+recho ${x:+"`:`""`:`"""}
+recho ${x:+"`:`" "`:`"""}
+recho ${x:+"`:`""`:`" ""}
+recho ${x:+ "`:`""`:`"""}
diff --git a/tests/redir.right b/tests/redir.right
index ab737d49..75ed4555 100644
--- a/tests/redir.right
+++ b/tests/redir.right
@@ -44,7 +44,7 @@ kl
ab
cd
cd
-./redir.tests: line 154: redir1.*: No such file or directory
+./redir.tests: line 157: redir1.*: No such file or directory
# tests of ksh93-like dup-and-close redirection operators
exec 9<$0
diff --git a/tests/redir.tests b/tests/redir.tests
index 7b74ac53..6af02194 100644
--- a/tests/redir.tests
+++ b/tests/redir.tests
@@ -57,6 +57,9 @@ echo to c 1>&6
cat $TMPDIR/bash-c
echo "Point 5"
+# clean up before running scripts
+exec 4>&- 5>&- 6<&-
+
rm -f $TMPDIR/bash-a $TMPDIR/bash-b $TMPDIR/bash-c
#
diff --git a/tests/run-varenv b/tests/run-varenv
index 5987a7f3..f147d70b 100644
--- a/tests/run-varenv
+++ b/tests/run-varenv
@@ -1,2 +1,2 @@
-${THIS_SH} ./varenv.sh 2>&1 | grep -v '^expect' > ${BASH_TSTOUT}
+${THIS_SH} ./varenv.tests 2>&1 | grep -v '^expect' > ${BASH_TSTOUT}
diff ${BASH_TSTOUT} varenv.right && rm -f ${BASH_TSTOUT}
diff --git a/tests/shopt.right b/tests/shopt.right
index bb0ac696..64c718c8 100644
--- a/tests/shopt.right
+++ b/tests/shopt.right
@@ -27,7 +27,7 @@ shopt -u extglob
shopt -s extquote
shopt -u failglob
shopt -s force_fignore
-shopt -u globasciiranges
+shopt -s globasciiranges
shopt -u globstar
shopt -u gnu_errfmt
shopt -u histappend
@@ -63,6 +63,7 @@ shopt -s complete_fullquote
shopt -s expand_aliases
shopt -s extquote
shopt -s force_fignore
+shopt -s globasciiranges
shopt -s hostcomplete
shopt -s interactive_comments
shopt -s progcomp
@@ -89,7 +90,6 @@ shopt -u execfail
shopt -u extdebug
shopt -u extglob
shopt -u failglob
-shopt -u globasciiranges
shopt -u globstar
shopt -u gnu_errfmt
shopt -u histappend
@@ -130,7 +130,6 @@ execfail off
extdebug off
extglob off
failglob off
-globasciiranges off
globstar off
gnu_errfmt off
histappend off
diff --git a/tests/test-glue-functions b/tests/test-glue-functions
index b958ab71..07ad8215 100644
--- a/tests/test-glue-functions
+++ b/tests/test-glue-functions
@@ -9,5 +9,5 @@ _intl_normalize_spaces()
# avoid whitespace differences in wc implementations
_cut_leading_spaces()
{
- sed -e 's/^[[:space:]]*//g'
+ sed -e 's/^[ ]*//g'
}
diff --git a/tests/unicode3.sub b/tests/unicode3.sub
index b39f1d3c..cb1b8732 100644
--- a/tests/unicode3.sub
+++ b/tests/unicode3.sub
@@ -1,4 +1,6 @@
export LANG=en_US.UTF-8 # make sure
+
+cd $TMPDIR # try to avoid NFS artifacts
payload=$'\065\247\100\063\231\053\306\123\070\237\242\352\263'
"$payload"
@@ -6,4 +8,5 @@ cd "$payload"
printf %q "$payload"
echo
-set -x ; : "$payload"
+set -x ; : "$payload" ; set +x
+cd $OLDPWD
diff --git a/tests/varenv.right b/tests/varenv.right
index 7ca5f661..4e8c0d16 100644
--- a/tests/varenv.right
+++ b/tests/varenv.right
@@ -145,8 +145,68 @@ outside:
declare -x foo="abc"
inside: declare -x var="value"
outside: declare -- var="one"
+inside: declare -x var="value"
+outside: declare -x var="value"
inside: declare -- var="local"
outside: declare -x var="global"
+foo=<unset> environment foo=
+foo=foo environment foo=foo
+foo=foo environment foo=foo
+./varenv13.sub: line 3: `var[0]': not a valid identifier
+./varenv13.sub: line 3: `var[@]': not a valid identifier
+./varenv13.sub: line 1: declare: var: not found
+./varenv13.sub: line 12: var[@]: bad array subscript
+declare -A var=([0]="X" )
+help
+./varenv13.sub: line 21: `var[0]': not a valid identifier
+1
+./varenv14.sub: line 6: warning: var: cannot inherit value from incompatible type
+declare -a var=([0]="X")
+./varenv14.sub: line 9: warning: var: cannot inherit value from incompatible type
+declare -a var=([0]="Y")
+./varenv14.sub: line 10: warning: var: cannot inherit value from incompatible type
+declare -a var=([0]="Y")
+./varenv14.sub: line 11: warning: var: cannot inherit value from incompatible type
+declare -a var=()
+./varenv14.sub: line 12: warning: var: cannot inherit value from incompatible type
+declare -a var=()
+./varenv14.sub: line 18: f: var: cannot convert indexed to associative array
+declare -a a=([0]="X")
+declare -a s=([0]="X")
+declare -a a=([0]="X" [1]="Y")
+declare -a s=([0]="X" [1]="Y")
+declare -a a=([0]="XY")
+declare -a s=([0]="XY")
+f: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
+f1: after: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
+done: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
+f3:1
+f3:2
+f3:3
+f3:4
+f3:5
+f3:6
+f3:7
+f3:8
+f3:9
+f3:10
+f3:11
+f3:12
+f3:13
+f3:14
+f3:15
+f3:16
+f3:17
+f3:18
+f3:19
+f3:20
+before source: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
+varenv15.in: before set: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
+varenv15.in: after set: a b c d e f g h i j k l m n o p q r s t u v w x y z
+after source 1: a b c d e f g h i j k l m n o p q r s t u v w x y z
+varenv15.in: before set: one two three four five six seven eight nine ten
+varenv15.in: after set: a b c d e f g h i j k l m n o p q r s t u v w x y z
+after source 2: a b c d e f g h i j k l m n o p q r s t u v w x y z
a=z
a=b
a=z
diff --git a/tests/varenv.tests b/tests/varenv.tests
new file mode 100644
index 00000000..34b85596
--- /dev/null
+++ b/tests/varenv.tests
@@ -0,0 +1,246 @@
+#
+# varenv.sh
+#
+# Test the behavior of the shell with respect to variable and environment
+# assignments
+#
+expect()
+{
+ echo expect "$@"
+}
+
+a=1
+b=2
+c=3
+d=4
+e=5
+f=6 g=7 h=8
+
+a=3 b=4 $CHMOD $MODE $FN
+
+# This should echo "3 4" according to Posix.2
+expect "3 4"
+echo $a $b
+
+set -k
+
+# Assignment statements made when no words are left affect the shell's
+# environment
+a=5 b=6 $CHMOD c=7 $MODE d=8 $FN e=9
+
+expect "5 6 7 8 9"
+echo $a $b $c $d $e
+
+$CHMOD f=7 $MODE g=8 $FN h=9
+expect "7 8 9"
+echo $f $g $h
+
+set +k
+
+# The temporary environment does not affect variable expansion, only the
+# environment given to the command
+
+export HOME=/usr/chet
+expect $HOME
+echo $HOME
+
+expect $HOME
+HOME=/a/b/c /bin/echo $HOME
+
+expect $HOME
+echo $HOME
+
+# This should echo /a/b/c
+expect /a/b/c
+HOME=/a/b/c printenv HOME
+
+set -k
+
+# This should echo $HOME 9, NOT /a/b/c 9
+
+expect "$HOME"
+HOME=/a/b/c /bin/echo $HOME c=9
+expect "$HOME 7"
+echo $HOME $c
+
+# I claim the next two echo calls should give identical output.
+# ksh agrees, the System V.3 sh does not
+
+expect "/a/b/c 9 /a/b/c"
+HOME=/a/b/c $ECHO a=$HOME c=9
+echo $HOME $c $a
+
+expect "/a/b/c 9 /a/b/c"
+HOME=/a/b/c a=$HOME c=9
+echo $HOME $c $a
+set +k
+
+# How do assignment statements affect subsequent assignments on the same
+# line?
+expect "/a/b/c /a/b/c"
+HOME=/a/b/c a=$HOME
+echo $HOME $a
+
+# The system V.3 sh does this wrong; the last echo should output "1 1",
+# but the system V.3 sh has it output "2 2". Posix.2 says the assignment
+# statements are processed left-to-right. bash and ksh output the right
+# thing
+c=1
+d=2
+expect "1 2"
+echo $c $d
+d=$c c=$d
+expect "1 1"
+echo $c $d
+
+# just for completeness
+unset d c
+expect unset
+echo ${d-unset}
+
+# no output
+export a
+a=bcde
+export a
+/bin/true 2>/dev/null
+
+func()
+{
+ local YYZ
+
+ YYZ="song by rush"
+ echo $YYZ
+ echo $A
+}
+
+YYZ="toronto airport"
+A="AVAR"
+echo $YYZ
+echo $A
+A=BVAR func
+echo $YYZ
+echo $A
+
+export A
+# Make sure expansion doesn't use assignment statements preceding a builtin
+A=ZVAR echo $A
+
+XPATH=/bin:/usr/bin:/usr/local/bin:.
+func2()
+{
+ local z=yy
+ local -a avar=( ${XPATH//: } )
+ echo ${avar[@]}
+ local
+}
+
+avar=42
+echo $avar
+func2
+echo $avar
+
+# try to set an attribute for an unset variable; make sure it persists
+# when the variable is assigned a value
+declare -i ivar
+
+ivar=10
+
+declare -p ivar
+unset ivar
+
+# export an unset variable, make sure it is not suddenly set, but make
+# sure the export attribute persists when the variable is assigned a
+# value
+export ivar
+echo ${ivar-unset}
+
+ivar=42
+declare -p ivar
+
+# make sure set [-+]o ignoreeof and $IGNOREEOF are reflected
+unset IGNOREEOF
+set +o ignoreeof
+set -o ignoreeof
+if [ "$IGNOREEOF" -ne 10 ]; then
+ echo "./varenv.sh: set -o ignoreeof is not reflected in IGNOREEOF" >&2
+fi
+unset IGNOREEOF
+set +o ignoreeof
+
+# older versions of bash used to not reset RANDOM in subshells correctly
+[[ $RANDOM -eq $(echo $RANDOM) ]] && echo "RANDOM: problem with subshells"
+
+# make sure that shopt -o is reflected in $SHELLOPTS
+# first, get rid of things that might be set automatically via shell
+# variables
+set +o posix
+set +o ignoreeof
+set +o monitor
+echo $-
+echo ${SHELLOPTS}
+shopt -so physical
+echo $-
+echo ${SHELLOPTS}
+
+# and make sure it is readonly
+readonly -p | grep SHELLOPTS
+
+# This was an error in bash versions prior to bash-2.04. The `set -a'
+# should cause the assignment statement that's an argument to typeset
+# to create an exported variable
+unset FOOFOO
+FOOFOO=bar
+set -a
+typeset FOOFOO=abcde
+
+printenv FOOFOO
+
+# test out export behavior of variable assignments preceding builtins and
+# functions
+$THIS_SH ./varenv1.sub
+
+# more tests; bugs in bash up to version 2.05a
+$THIS_SH ./varenv2.sub
+
+# more tests; bugs in bash IFS scoping up through version 4.2
+$THIS_SH ./varenv3.sub
+
+# scoping problems with declare -g through bash-4.2
+${THIS_SH} ./varenv4.sub
+
+# more scoping and declaration problems with -g and arrays through bash-4.2
+${THIS_SH} ./varenv5.sub
+
+# variable scoping in the presence of nameref
+${THIS_SH} ./varenv6.sub
+
+# variable declaration problems with arrays and readonly local variables
+${THIS_SH} ./varenv7.sub
+
+# variable visibility problems with process substitution subshells in
+# redirections
+${THIS_SH} ./varenv8.sub
+
+# make sure that builtins like readonly and export modify local array variables
+# if executed in shell functions, like they modify local scalar variables
+${THIS_SH} ./varenv9.sub
+
+# more tests of unset and local variables with dynamic scoping
+${THIS_SH} ./varenv10.sub
+
+# tests of compound assignments in function scope
+${THIS_SH} ./varenv11.sub
+
+# temporary environment variable propagation and scoping in posix mode
+${THIS_SH} ./varenv12.sub
+
+# temporary environment and invalid shell indentifier names
+${THIS_SH} ./varenv13.sub
+
+# localvar_inherit
+${THIS_SH} ./varenv14.sub
+
+${THIS_SH} ./varenv15.sub
+
+# make sure variable scoping is done right
+tt() { typeset a=b;echo a=$a; };a=z;echo a=$a;tt;echo a=$a
diff --git a/tests/varenv12.sub b/tests/varenv12.sub
index 6aaf512b..edba3c94 100644
--- a/tests/varenv12.sub
+++ b/tests/varenv12.sub
@@ -47,6 +47,28 @@ echo -n 'outside: ' ; declare -p var
unset -v var
unset -f func
+# this will probably change behavior; export shouldn't behave like this when
+# not in posix mode and the sequencing is probably wrong in posix mode. since
+# export is a special builtin, the variable assignment should modify the
+# global variable, leaving the local variable unchanged. all shells, including
+# bash, modify the local variable; bash is the only one that propagates the
+# value out to the calling environment. bash does that only when in posix
+# mode.
+
+func()
+{
+ local var=inside
+ var=value export var
+ echo -n 'inside: ' ; declare -p var
+}
+
+var=outside
+func
+echo -n 'outside: ' ; declare -p var
+
+unset -v var
+unset -f func
+
func()
{
local var=local
@@ -60,3 +82,19 @@ echo -n 'outside: ' ; declare -p var
unset -v var
unset -f func
+
+# test whether or not temporary environment assignments are exported
+# in posix mode
+showfoo()
+{
+ printf %s "foo=${foo-<unset>}"
+ echo -n ' environment foo='
+ printenv foo || echo
+}
+unset foo
+showfoo
+foo=foo showfoo
+showfoo
+
+unset -v foo
+unset -f showfoo
diff --git a/tests/varenv13.sub b/tests/varenv13.sub
new file mode 100644
index 00000000..0e6a42c1
--- /dev/null
+++ b/tests/varenv13.sub
@@ -0,0 +1,23 @@
+f() { declare -p ${!var*} | grep ^var; declare -p var ; }
+
+var[0]=X var[@]=Y f
+
+unset -f f
+unset -v var
+
+typeset -A var
+
+f() { declare -p ${!var*}; }
+
+var[0]=X var[@]=Y
+f
+
+: ${THIS_SH:=./bash}
+env 'v[0]=help' ${THIS_SH} -c 'printenv "v[0]"'
+
+unset -v var
+
+f() { test -v 'var[0]'; echo $?; }
+var[0]=X f
+
+unset -v var
diff --git a/tests/varenv14.sub b/tests/varenv14.sub
new file mode 100644
index 00000000..52b20d81
--- /dev/null
+++ b/tests/varenv14.sub
@@ -0,0 +1,33 @@
+# testing framework for local variable inheritence
+
+shopt -s localvar_inherit
+declare -A var
+
+f() { declare var+=([0]=X); declare -p var; }
+f
+
+f() { declare var=([Y]=Y); declare -p var; }; f
+f() { declare var+=([Y]=Y); declare -p var; }; f
+f() { declare var+=(); declare -p var; }; f
+f() { declare var=(); declare -p var; }; f
+
+unset -f f
+unset -v var
+
+declare -a var=( [0]=12 )
+f() { declare -A var+=([0]=X); declare -p var; }
+f
+
+unset -f f
+unset a s
+
+a=(X) s=X
+
+f() { local -a a s; declare -p a s; }
+f
+
+f() { local a+=(Y) s+=(Y); declare -p a s; }
+f
+
+f() { local -a a+=Y s+=Y; declare -p a s; }
+f
diff --git a/tests/varenv15.in b/tests/varenv15.in
new file mode 100644
index 00000000..e635b12a
--- /dev/null
+++ b/tests/varenv15.in
@@ -0,0 +1,3 @@
+echo varenv15.in: before set: "$@"
+set -- a b c d e f g h i j k l m n o p q r s t u v w x y z
+echo varenv15.in: after set: "$@"
diff --git a/tests/varenv15.sub b/tests/varenv15.sub
new file mode 100644
index 00000000..52c8a940
--- /dev/null
+++ b/tests/varenv15.sub
@@ -0,0 +1,38 @@
+# check saving and restoring positional parameters around function calls
+
+f()
+{
+ echo $FUNCNAME: "$@"
+}
+
+f1()
+{
+ f {1..50}
+ echo $FUNCNAME: after: $@
+}
+
+set -- {1..100}
+
+f1 {1..20}
+echo done: $@
+
+f3()
+{
+ echo $FUNCNAME:$1
+ shift
+ if [ $# -le 0 ]; then
+ return
+ fi
+ f3 "$@"
+}
+
+f3 {1..20}
+
+# now let's try source with and without positional parameters
+
+set -- {1..20}
+echo before source: "$@"
+. ./varenv15.in
+echo after source 1: "$@"
+. ./varenv15.in one two three four five six seven eight nine ten
+echo after source 2: "$@"