diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/comsub2.right | 74 | ||||
-rw-r--r-- | tests/comsub2.tests | 122 | ||||
-rw-r--r-- | tests/comsub21.sub | 65 | ||||
-rw-r--r-- | tests/comsub22.sub | 26 | ||||
-rw-r--r-- | tests/exportfunc.right | 2 | ||||
-rw-r--r-- | tests/exportfunc.tests | 3 | ||||
-rw-r--r-- | tests/run-comsub2 | 2 |
7 files changed, 291 insertions, 3 deletions
diff --git a/tests/comsub2.right b/tests/comsub2.right new file mode 100644 index 00000000..281883dd --- /dev/null +++ b/tests/comsub2.right @@ -0,0 +1,74 @@ +aa bb cc dd +AAaa bb cc ddBB +aa bb cc dd +aa bb cc dd +DDDDDaa bb cc ddEEEEE +aa bb cc dd +outside: 42 +aa bb cc dd +outside: +assignment: 12 +abcde +67890 +12345 +JOBaa bb cc ddCONTROL +./comsub2.tests: line 48: p: command not found +NOTFOUND +./comsub2.tests: line 56: p: command not found +./comsub2.tests: line 56: p: command not found +expand_aliases off +expand_aliases off +outside: +expand_aliases off +1 +expand_aliases on +2 +expand_aliases on +outside: +expand_aliases on +1 +xx +expand_aliases on +2 +xx +expand_aliases on +outside: +expand_aliases on +inside: 12 22 42 +outside: 42 2 +newlines + + +outside: 42 +before: 1 2 +after: 2 +before: 1 2 +after: 2 +before: 1 2 +after: 1 2 +XnestedY +a nested b +one two +42 +42 +42 +123 +123 +0 +123 +123 +0 +Mon Aug 29 20:03:02 EDT 2022 +Mon Aug 29 20:03:02 EDT 2022 +Mon Aug 29 20:03:02 EDT 2022 +Mon Aug 29 20:03:02 EDT 2022 +123 +before 123 +in for 123 +outside before: value +inside before: value +inside after: funsub +inside: after false xxx +outside after: funsub +=====posix mode===== +outside before: value diff --git a/tests/comsub2.tests b/tests/comsub2.tests new file mode 100644 index 00000000..0254d8db --- /dev/null +++ b/tests/comsub2.tests @@ -0,0 +1,122 @@ +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +# initial set of tests for ${Ccommand; } nofork command substitution + +# basic functionality + +echo ${ printf '%s\n' aa bb cc dd; } +echo AA${ printf '%s\n' aa bb cc dd; }BB + +echo ${ printf '%s\n' aa bb cc dd; return; echo ee ff; } +echo ${ printf '%s\n' aa bb cc dd + } +echo DDDDD${ + printf '%s\n' aa bb cc dd +}EEEEE +unset x +echo ${ printf '%s\n' aa bb cc dd; x=42 ; return 12; echo ee ff; } +echo outside: $x +unset x +echo ${ typeset x; printf '%s\n' aa bb cc dd; x=42 ; return 12; echo ee ff; } +echo outside: $x +xx=${ typeset x; printf '%s\n' aa bb cc dd; x=42 ; return 12; echo ee ff; } +echo assignment: $? +unset xx + +echo ${( echo abcde )} # works in ksh93 + +echo ${| echo 67890; REPLY=12345; } # works in mksh + +# basic job control +set -m +echo this should disappear | echo JOB${ printf '%s\n' aa bb cc dd; }CONTROL | cat +set +m + +# command not found should still echo error messages to stderr +echo NOT${ p; }FOUND + +# alias handling in command substitutions, default and posix mode +alias p=printf +echo "${ typeset x; + for f in 1 2; do p '%s\n' $f ; shopt expand_aliases; done + x=42 ; return; echo this should not be seen; }" +echo outside: $x +shopt expand_aliases + +set -o posix +echo "${ typeset x; + for f in 1 2; do p '%s\n' $f ; shopt expand_aliases; done + x=42 ; return; echo this should not be seen; }" +echo outside: $x +shopt expand_aliases + +set +o posix + +shopt -s expand_aliases + +alias p=printf +echo "${ typeset x; + for f in 1 2; do p '%s\n' $f ; /bin/echo xx ; shopt expand_aliases; done + x=42 ; return; echo ee ff; }" +echo outside: $x +shopt expand_aliases + +# more tests for value substitutions and local variables +a=1 b=2 +a=${| local b ; a=12 ; b=22 ; REPLY=42 ; echo inside: $a $b $REPLY; } +echo outside: $a $b +unset a b + +# this form doesn't remove the trailing newlines +REPLY=42 +a=${| REPLY=$'newlines\n\n'; } +echo "$a" +echo outside: $REPLY + +# how do we handle shift with these weird ksh93 function-like semantics? +# ksh93 doesn't reset the positional parameters here +set -- 1 2 +echo before: "$@" +: "${ shift;}" +echo after: "$@" + +set -- 1 2 +echo before: "$@" +: "${| shift;}" +echo after: "$@" + +set -- 1 2 +echo before: "$@" +: "${( shift)}" +echo after: "$@" + +# nested funsubs +echo ${ echo X${ echo nested; }Y; } +echo ${ echo a ; echo ${ echo nested; }; echo b; } + +# nested funsubs/comsubs +x=${ + echo ${ echo one;} $(echo two) +} +echo $x + +# mixing funsubs and arithmetic expansion +echo $(( ${ echo 24 + 18; })) +echo $(( ${ echo 14 + 18; }+ 10)) +echo ${ echo $(( 24+18 )); } + +# alias expansion and nested funsubs in other constructs +${THIS_SH} ./comsub21.sub +${THIS_SH} ./comsub22.sub diff --git a/tests/comsub21.sub b/tests/comsub21.sub new file mode 100644 index 00000000..0837f723 --- /dev/null +++ b/tests/comsub21.sub @@ -0,0 +1,65 @@ +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +# posix-mode alias expansion in nofork command substitutions within +# other constructs + +DATE='Mon Aug 29 20:03:02 EDT 2022' +shopt -s expand_aliases + +alias number="echo 123" + +echo ${ number; } +echo $(( ${ number; } )) +(( ${ number; } )) ; echo $? + +set -o posix +echo ${ number; } +echo $(( ${ number; } )) +(( ${ number; } )) ; echo $? +set +o posix + +# have to turn it back on after leaving posix mode +shopt -s expand_aliases + +alias my_alias='echo $DATE' + +echo ${ eval my_alias; } +echo ${ my_alias; } + +set -o posix +echo ${ eval my_alias; } +echo ${ my_alias; } +set +o posix ; shopt -s expand_aliases + +alias e=echo +alias v='e 123' + +set -o posix +echo ${ v; } +echo ${ echo before ; v; } +echo ${ for f in 0; do +echo in for +done; v; } +set +o posix ; shopt -s expand_aliases + +alias let='let --' + +let '1 == 1' +: ${ let '1 == 1'; } + +set -o posix +let '1 == 1' +: ${ let '1 == 1'; } +set +o posix ; shopt -s expand_aliases diff --git a/tests/comsub22.sub b/tests/comsub22.sub new file mode 100644 index 00000000..9fdf6199 --- /dev/null +++ b/tests/comsub22.sub @@ -0,0 +1,26 @@ +# tests for inheriting set -e into command substitutions + +set -e +var=value +echo "outside before: $var" +echo "${ + echo "inside before: $var" + var=funsub + echo "inside after: $var" + false; + echo inside: after false +}" xxx +echo "outside after: $var" + +set -o posix +echo =====posix mode===== +var=value +echo "outside before: $var" +echo "${ + echo "inside before: $var" + var=funsub + echo "inside after: $var" + false; + echo inside: after false +}" xxx +echo "outside after: $var" diff --git a/tests/exportfunc.right b/tests/exportfunc.right index 890bdfa4..ad6b58c6 100644 --- a/tests/exportfunc.right +++ b/tests/exportfunc.right @@ -5,7 +5,7 @@ exportfunc ok 2 ./exportfunc.tests: line 43: cve7169-bad2: No such file or directory ./exportfunc1.sub: line 14: maximum here-document count exceeded ./exportfunc.tests: line 72: HELLO_WORLD: No such file or directory -eval ok +./exportfunc.tests: eval: line 83: unexpected EOF while looking for matching `}' ./exportfunc3.sub: line 23: export: foo=bar: cannot export status: 1 equals-1 diff --git a/tests/exportfunc.tests b/tests/exportfunc.tests index 1a8b8a20..64eb38bb 100644 --- a/tests/exportfunc.tests +++ b/tests/exportfunc.tests @@ -78,8 +78,7 @@ env -i BASH_FUNC_x%%='() { _; } >_[${ $() }] { id; }' ${THIS_SH} -c : 2>/dev/nul env BASH_FUNC_x%%=$'() { _;}>_[$($())]\n{ echo vuln;}' ${THIS_SH} -c : 2>/dev/null eval 'x() { _;}>_[$($())] { echo vuln;}' 2>/dev/null -echo this will fail now that '${ ' has syntactic meaning - +# this fails looking for closing `}' now that `${ ' has syntactic meaning eval 'foo() { _; } >_[${ $() }] ;{ echo eval ok; }' # other tests fixed in bash43-030 concerning function name transformation diff --git a/tests/run-comsub2 b/tests/run-comsub2 new file mode 100644 index 00000000..e88d38ff --- /dev/null +++ b/tests/run-comsub2 @@ -0,0 +1,2 @@ +${THIS_SH} ./comsub2.tests > ${BASH_TSTOUT} 2>&1 +diff ${BASH_TSTOUT} comsub2.right && rm -f ${BASH_TSTOUT} |