summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/builtins.right23
-rw-r--r--tests/builtins.tests3
-rw-r--r--tests/cond-regexp3.sub66
-rw-r--r--tests/cond.right46
-rwxr-xr-xtests/cond.tests2
-rwxr-xr-xtests/dollar-at-star4
-rw-r--r--tests/dollar-at6.sub30
-rw-r--r--tests/dollar.right21
-rw-r--r--tests/nameref.right17
-rw-r--r--tests/nameref.tests2
-rw-r--r--tests/nameref7.sub18
-rw-r--r--tests/nameref8.sub57
-rw-r--r--tests/source7.sub40
13 files changed, 323 insertions, 6 deletions
diff --git a/tests/builtins.right b/tests/builtins.right
index 35fcc234..bafc53fb 100644
--- a/tests/builtins.right
+++ b/tests/builtins.right
@@ -117,6 +117,23 @@ three - OK
0
four - OK
0
+abc
+def
+ghi
+after
+one.1 subshell
+two.1 subshell
+three.1 subshell
+four.1 subshell
+one.2 subshell
+two.2 subshell
+three.2 subshell
+four.2 subshell
+x29 - done
+abc
+def
+ghi
+ok
AVAR
foo
foo
@@ -127,11 +144,11 @@ AVAR
foo
declare -x foo=""
declare -x FOO="\$\$"
-./builtins.tests: line 210: declare: FOO: not found
+./builtins.tests: line 213: declare: FOO: not found
declare -x FOO="\$\$"
ok
ok
-./builtins.tests: line 242: kill: 4096: invalid signal specification
+./builtins.tests: line 245: kill: 4096: invalid signal specification
1
a\n\n\nb
a
@@ -151,4 +168,4 @@ declare -a c='([0]="1" [1]="2" [2]="3")'
declare -a c='([0]="1" [1]="2" [2]="3")'
unset
unset
-./builtins.tests: line 257: exit: status: numeric argument required
+./builtins.tests: line 260: exit: status: numeric argument required
diff --git a/tests/builtins.tests b/tests/builtins.tests
index 69515ada..9d775201 100644
--- a/tests/builtins.tests
+++ b/tests/builtins.tests
@@ -179,6 +179,9 @@ ${THIS_SH} ./source5.sub
# test bugs in sourcing non-regular files, fixed post-bash-3.2
${THIS_SH} ./source6.sub
+# test bugs with source called from multiline aliases and other contexts
+${THIS_SH} ./source7.sub
+
# in posix mode, assignment statements preceding special builtins are
# reflected in the shell environment. `.' and `eval' need special-case
# code.
diff --git a/tests/cond-regexp3.sub b/tests/cond-regexp3.sub
new file mode 100644
index 00000000..aaca0239
--- /dev/null
+++ b/tests/cond-regexp3.sub
@@ -0,0 +1,66 @@
+# simple expansion -- no problem, it's quote_string_for_globbing that was flawed
+c=$'\177'
+r="\\$c"
+
+recho $r
+
+# first, match some regular expressions containing ^A, ^G, ^?
+[[ $'\001' =~ $'\001' ]] ; echo $?
+[[ $'\001' =~ $'\\\001' ]] ; echo $?
+[[ $'\001' =~ $'\\[\001]' ]] ; echo $?
+
+[[ $'\a' =~ $'\a' ]] ; echo $?
+[[ $'\a' =~ $'\\\a' ]] ; echo $?
+[[ $'\a' =~ $'\\[\a]' ]] ; echo $?
+
+[[ $'\177' =~ $'\177' ]] ; echo $?
+[[ $'\177' =~ $'\\\177' ]] ; echo $?
+[[ $'\177' =~ $'\\[\177]' ]] ; echo $?
+
+# Now let's try it with variables expanding to those values
+for c in $'\001' $'\a' $'\177' ; do
+ for r in "$c" "\\$c" "\\[$c]"; do
+ [[ $c =~ $r ]];
+ printf '[[ %q =~ %q ]] -> %d\n' "$c" "$r" "$?";
+ done;
+ printf %s\\n ---
+done
+
+# try again with literals
+
+[[ '' =~ $'' ]] ; echo $?
+[[ '' =~ '\' ]] ; echo $?
+[[ '' =~ '\[]' ]] ; echo $?
+
+[[ '' =~ '' ]] ; echo $?
+[[ '' =~ '\' ]] ; echo $?
+[[ '' =~ '\[]' ]] ; echo $?
+
+[[ '' =~ $'' ]] ; echo $?
+[[ '' =~ '\' ]] ; echo $?
+[[ '' =~ '\[]' ]] ; echo $?
+
+# more expansions, but with literal non-special characters
+[[ x =~ \x ]] ; echo $?
+[[ x =~ \\x ]] ; echo $?
+
+bs='\'
+[[ x =~ ${bs}x ]] ; echo $?
+
+[[ x =~ $'\\'x ]] ; echo $?
+[[ x =~ '\'x ]] ; echo $?
+
+c=$'\001'
+
+recho $c "$c"
+
+[[ $c == $c ]] && echo ok 1
+[[ $c =~ $c ]] && echo ok 2
+[[ $c =~ \\$c ]] || echo ok 3
+[[ $c =~ \\"$c" ]] || echo ok 4
+
+[[ $c =~ "\\"$c ]] || echo ok 5
+[[ $c =~ '\'$c ]] || echo ok 6
+
+[[ $c =~ "\\""$c" ]] || echo ok 7
+[[ $c =~ '\'"$c" ]] || echo ok 8
diff --git a/tests/cond.right b/tests/cond.right
index c7150e1b..b172a128 100644
--- a/tests/cond.right
+++ b/tests/cond.right
@@ -78,3 +78,49 @@ ok 9
ok 10
ok 11
ok 12
+argv[1] = <\^?>
+0
+1
+1
+0
+1
+1
+0
+1
+1
+[[ $'\001' =~ $'\001' ]] -> 0
+[[ $'\001' =~ $'\\\001' ]] -> 1
+[[ $'\001' =~ $'\\[\001]' ]] -> 1
+---
+[[ $'\a' =~ $'\a' ]] -> 0
+[[ $'\a' =~ $'\\\a' ]] -> 1
+[[ $'\a' =~ $'\\[\a]' ]] -> 1
+---
+[[ $'\177' =~ $'\177' ]] -> 0
+[[ $'\177' =~ $'\\\177' ]] -> 1
+[[ $'\177' =~ $'\\[\177]' ]] -> 1
+---
+0
+1
+1
+0
+1
+1
+0
+1
+1
+0
+1
+1
+1
+1
+argv[1] = <^A>
+argv[2] = <^A>
+ok 1
+ok 2
+ok 3
+ok 4
+ok 5
+ok 6
+ok 7
+ok 8
diff --git a/tests/cond.tests b/tests/cond.tests
index 0c096496..d91ddddf 100755
--- a/tests/cond.tests
+++ b/tests/cond.tests
@@ -183,3 +183,5 @@ if [[ "123abc" == *?(a)bc ]]; then echo ok 43; else echo bad 43; fi
${THIS_SH} ./cond-regexp1.sub
${THIS_SH} ./cond-regexp2.sub
+
+${THIS_SH} ./cond-regexp3.sub
diff --git a/tests/dollar-at-star b/tests/dollar-at-star
index 45e4ed4d..9a5d402a 100755
--- a/tests/dollar-at-star
+++ b/tests/dollar-at-star
@@ -246,6 +246,10 @@ ${THIS_SH} ./dollar-at4.sub
# through bash-4.2
${THIS_SH} ./dollar-at5.sub
+# tests for problems with "${@:1}" and other expansions with null entries
+# in positional parameters
+${THIS_SH} ./dollar-at6.sub
+
# tests for expansions of $* when $1 == ""; problem through bash-4.2
${THIS_SH} ./dollar-star6.sub
diff --git a/tests/dollar-at6.sub b/tests/dollar-at6.sub
new file mode 100644
index 00000000..039e11f8
--- /dev/null
+++ b/tests/dollar-at6.sub
@@ -0,0 +1,30 @@
+set -- '';
+
+recho "${@}" x
+recho "${@:1}" x
+
+set -- "${@:1}"
+echo "$#"
+
+set -- '' ''
+
+recho "${@:1}" x
+recho "${@:1:1}" x
+
+typeset -a A # ksh93 needs this
+A=('' '')
+recho "${A[@]:0}" x
+
+recho "${A[@]:0:1}" x
+
+recho "${A[@]:1}" x
+
+set -- ''
+
+recho "${@/foo/bar}"
+recho "${@^^[abcde]}"
+
+A=( '' )
+
+recho "${A[@]/foo/bar}"
+recho "${A[@],,[abcde]}"
diff --git a/tests/dollar.right b/tests/dollar.right
index 92f15d54..6af02b1b 100644
--- a/tests/dollar.right
+++ b/tests/dollar.right
@@ -233,6 +233,27 @@ ${@:2}c$1 c2 c3 #works as long as quoting omitted
set y zcx c2 c3
0
declare -a c='([0]="y" [1]="zcx" [2]="c2" [3]="c3")'
+argv[1] = <>
+argv[2] = <x>
+argv[1] = <>
+argv[2] = <x>
+1
+argv[1] = <>
+argv[2] = <>
+argv[3] = <x>
+argv[1] = <>
+argv[2] = <x>
+argv[1] = <>
+argv[2] = <>
+argv[3] = <x>
+argv[1] = <>
+argv[2] = <x>
+argv[1] = <>
+argv[2] = <x>
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
+argv[1] = <>
argv[1] = <AwR>
argv[1] = <AwR>
argv[1] = <AR>
diff --git a/tests/nameref.right b/tests/nameref.right
index e3251c54..26ae369b 100644
--- a/tests/nameref.right
+++ b/tests/nameref.right
@@ -111,8 +111,19 @@ final state: ref -> three, value: 3
./nameref6.sub: line 2: typeset: x: nameref variable self references not allowed
./nameref6.sub: line 12: typeset: x: reference variable cannot be an array
the -- 1
-./nameref6.sub: line 25: 42: invalid variable name for name reference
42 -- 0
-./nameref6.sub: line 40: 2: invalid variable name for name reference
-./nameref6.sub: line 41: 2: invalid variable name for name reference
+y -- 0
2 -- 0
+2 -- 0
+y -- 0
+bar
+unset
+inside
+inside: one
+outside: two
+foo
+local
+./nameref8.sub: line 47: typeset: v: nameref variable self references not allowed
+./nameref8.sub: line 54: warning: x: circular name reference
+./nameref8.sub: line 55: warning: x: circular name reference
+x =
diff --git a/tests/nameref.tests b/tests/nameref.tests
index 9cf50812..438133c6 100644
--- a/tests/nameref.tests
+++ b/tests/nameref.tests
@@ -114,3 +114,5 @@ ${THIS_SH} ./nameref3.sub
${THIS_SH} ./nameref4.sub
${THIS_SH} ./nameref5.sub
${THIS_SH} ./nameref6.sub
+${THIS_SH} ./nameref7.sub
+${THIS_SH} ./nameref8.sub
diff --git a/tests/nameref7.sub b/tests/nameref7.sub
new file mode 100644
index 00000000..19bdc989
--- /dev/null
+++ b/tests/nameref7.sub
@@ -0,0 +1,18 @@
+fn ()
+{
+ declare -n var=foo; var=bar
+}
+
+unset foo
+fn
+echo ${foo:-unset}
+
+unset -f fn
+unset foo
+fn()
+{
+ declare -n var; var=foo
+}
+
+fn
+echo ${foo:-unset}
diff --git a/tests/nameref8.sub b/tests/nameref8.sub
new file mode 100644
index 00000000..6837f6f4
--- /dev/null
+++ b/tests/nameref8.sub
@@ -0,0 +1,57 @@
+function f1
+{
+ typeset -n v=$1
+
+ v=inside
+}
+
+v=global
+f1 v
+echo $v
+
+unset v
+unset -f f1
+
+function foo
+{
+ typeset x=one
+
+ typeset -n y=$1
+ y=two
+ echo inside: $x
+}
+
+foo x
+echo outside: $x
+
+function foo2
+{
+ typeset -n x=$1
+
+ x=foo
+}
+
+foo2 x
+echo $x
+
+unset -f foo
+function foo { typeset -n v=$1; v=local; }
+
+v=global
+foo v
+echo $v
+
+unset v
+
+# invalid self reference at global scope
+typeset -n v=v
+
+# can we catch a circular self-reference?
+typeset -n v=w
+typeset -n w=x
+typeset -n x=v
+
+x=4
+echo x = $x
+
+unset -n v w x
diff --git a/tests/source7.sub b/tests/source7.sub
new file mode 100644
index 00000000..8ca0aeff
--- /dev/null
+++ b/tests/source7.sub
@@ -0,0 +1,40 @@
+shopt -s expand_aliases
+
+: ${TMPDIR:=/var/tmp}
+
+echo '((echo abc; echo def;); echo ghi)' > $TMPDIR/x28-$$
+. $TMPDIR/x28-$$
+rm -f $TMPDIR/x28-$$
+
+echo after
+
+TMPFILE=$TMPDIR/x29-$$
+
+echo "#! ${THIS_SH}" >$TMPFILE
+cat >> $TMPFILE << \EOF
+
+(echo -n "$1 "; echo subshell)
+EOF
+chmod 755 $TMPFILE
+
+alias foo1='$TMPFILE one.1; source $TMPFILE two.1; source $TMPFILE three.1; $TMPFILE four.1'
+alias foo2='$TMPFILE one.2;
+source $TMPFILE two.2;
+source $TMPFILE three.2;
+$TMPFILE four.2;
+'
+
+foo1
+foo2
+
+echo x29 - done
+rm -f $TMPFILE
+
+# this is also treated similarly to an alias expansion internally
+((echo abc; echo def;); echo ghi)
+
+if (((4+4) + (4 + 7))); then
+ echo ok
+fi
+
+(()) # make sure the null expression works OK