aboutsummaryrefslogtreecommitdiff
path: root/shell/hush_test
AgeCommit message (Collapse)Author
2020-12-25typo fixDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-25hush: fix this case: echo "SCRIPT" | hushDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-23hush: fix fallout from tweaking ${var:START:LEN} codeDenys Vlasenko
function old new delta expand_one_var 2344 2353 +9 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-01hush: document bugs in [[ =~ ]] comparisonDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-31hush: add tests for unquoted < > in [[ ]]Denys Vlasenko
They pass. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-31shell: better support of [[ ]] bashismDenys Vlasenko
Still rather rudimentary for ash function old new delta binop 433 589 +156 check_operator 65 101 +36 done_word 736 769 +33 test_main 405 418 +13 parse_stream 2227 2238 +11 ops_texts 124 133 +9 ops_table 80 86 +6 run_pipe 1557 1562 +5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 8/0 up/down: 269/0) Total: 269 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-24hush: output bash-compat killing signal namesDenys Vlasenko
This significantly syncronises ash-signals and hush-signals tests. function old new delta process_wait_result 449 450 +1 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-24hush: do not print killing signal name in `cmd_whihc_dies_on_signal`Denys Vlasenko
function old new delta process_wait_result 438 449 +11 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-09-29shell: add testsuite for "wait $pid" waiting for other tasksDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-07-31shell: Fix "read -d ''" behaviorChristian Eggers
With bash's read builtin it is possible to read from a file (e.g. device-tree) until the first '\0' character: IFS= read -r -d '' VARIABLE < file In busybox ash the -d extension is also implemented, but checking the read character for '\0' has to be performed after comparing with the delimiter. Signed-off-by: Christian Eggers <ceggers@arri.de> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-26shells: fix exitcode_trapN tests to avoid racesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-21ash: expand: Ensure result is escaped in cvtnumDenys Vlasenko
Upstream commit: Date: Fri, 1 Jun 2018 18:25:29 +0800 expand: Ensure result is escaped in cvtnum The minus sign generated from arithmetic expansion is currently unquoted which causes anomalies when the result is used in where the quoting matters. This patch fixes it by explicitly calling memtodest on the result in cvtnum. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-21hush: make "exit" in trap use pre-trap exitcode - fix for nested trapDenys Vlasenko
function old new delta check_and_run_traps 276 278 +2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-20hush: implement "return NUM in trap sets $? after trap"Denys Vlasenko
function old new delta builtin_return 47 67 +20 check_and_run_traps 243 259 +16 run_pipe 1583 1597 +14 hush_main 1076 1086 +10 run_list 1054 1055 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 5/0 up/down: 61/0) Total: 61 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-19ash,hush: testcase for "exit" without arguments in a trapDenys Vlasenko
hush fails this one Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-17ash: expand: Fix trailing newlines processing in backquote expandingDenys Vlasenko
Upstream commit: Date: Mon, 29 Apr 2019 19:13:37 +0500 expand: Fix trailing newlines processing in backquote expanding According to POSIX.1-2008 we should remove newlines only at the end of the substitution. Newlines-only substitions causes dash to remove newlines before beggining of the substitution. The following code: cat <<END 1 $(echo "") 2 END prints "1<newline>2" instead of expected "1<newline><newline>2". This patch fixes trailing newlines processing in backquote expanding. Signed-off-by: Nikolai Merinov <n.merinov@inango-systems.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-17ash: parser: Only accept single-digit parameter expansion outside of bracesDenys Vlasenko
Upstream commit: Date: Mon, 27 May 2019 13:39:37 +0800 parser: Only accept single-digit parameter expansion outside of braces This patch should fix the problem. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-11-01hush: restore redirected stdinDenys Vlasenko
function old new delta restore_redirects 52 95 +43 save_fd_on_redirect 243 253 +10 hfopen 90 99 +9 fgetc_interactive 259 261 +2 builtin_type 117 115 -2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/1 up/down: 64/-2) Total: 62 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-19hush: remove test for "echo ${-}" errorring out - now it worksDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-15hush: fix quoted "${notexist-}" expansion to not disappearDenys Vlasenko
function old new delta expand_one_var 2296 2311 +15 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-14shells: add tests for backslashes in export VAR=VALDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-07ash: expand: Do not quote backslashes in unquoted parameter expansionDenys Vlasenko
Upstream commit: Date: Wed, 28 Mar 2018 18:37:51 +0800 expand: Do not quote backslashes in unquoted parameter expansion Here is a better example: a="/*/\nullx" b="/*/\null"; printf "%s\n" $a $b dash currently prints /*/\nullx /*/\null bash prints /*/\nullx /dev/null You may argue the bash behaviour is inconsistent but it actually makes sense. What happens is that quote removal only applies to the original token as seen by the shell. It is never applied to the result of parameter expansion. Now you may ask why on earth does the second line say "/dev/null" instead of "/dev/\null". Well that's because it is not the quote removal step that removed the backslash, but the pathname expansion. The fact that the /de\v does not become /dev even though it exists is just the result of the optimisation to avoid unnecessarily calling stat(2). I have checked POSIX and I don't see anything that forbids this behaviour. So going back to dash yes I think we should adopt the bash behaviour for pathname expansion and keep the existing case semantics. This patch does exactly that. Note that this patch does not work unless you have already applied https://patchwork.kernel.org/patch/10306507/ because otherwise the optimisation mentioned above does not get detected correctly and we will end up doing quote removal twice. This patch also updates expmeta to handle naked backslashes at the end of the pattern which is now possible. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> function old new delta expmeta 618 653 +35 memtodest 146 147 +1 Tested to work with both ASH_INTERNAL_GLOB on and off. hush does not handle this correctly. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-05hush: adopt ash's quote_in_varexp1.testsDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-05ash: expand: Fix ghost fields with unquoted $@/$*Denys Vlasenko
Upstream commit: Date: Fri, 23 Mar 2018 18:58:47 +0800 expand: Fix ghost fields with unquoted $@/$* You're right. The proper fix to this is to ensure that nulonly is not set in varvalue for $*. It should only be set for $@ when it's inside double quotes. In fact there is another bug while we're playing with $@/$*. When IFS is set to a non-whitespace character such as :, $* outside quotes won't remove empty fields as it should. This patch fixes both problems. Reported-by: Martijn Dekker <martijn@inlv.org> Suggested-by: Harald van Dijk <harald@gigawatt.nl> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> function old new delta argstr 1111 1113 +2 evalvar 571 569 -2 varvalue 579 576 -3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 2/-5) Total: -3 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-05ash: eval: Variable assignments on functions are no longer persistentDenys Vlasenko
Upstream commit: Date: Wed, 4 Apr 2018 17:54:01 +0800 eval: Variable assignments on functions are no longer persistent Dirk Fieldhouse <fieldhouse@gmx.net> wrote: > In POSIX.1-2017 ("simultaneously IEEE Std 1003.1™-2017 and The Open > Group Technical Standard Base Specifications, Issue 7") > <http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09>, > we read under '2.9.1 Simple Commands' > > "Variable assignments shall be performed as follows: > ... > - If the command name is a standard utility implemented as a function > (see XBD Utility), the effect of variable assignments shall be as if the > utility was not implemented as a function. > ... > - If the command name is a function that is not a standard utility > implemented as a function, variable assignments shall affect the current > execution environment during the execution of the function. It is > unspecified: > > * Whether or not the variable assignments persist after the > completion of the function > > * Whether or not the variables gain the export attribute during > the execution of the function > > * Whether or not export attributes gained as a result of the > variable assignments persist after the completion of the function (if > variable assignments persist after the completion of the function)" POSIX used to require the current dash behaviour. However, you're right that this is no longer the case. This patch will remove the persistence of the variable assignment. I have considered the exporting the variables during the function execution but have decided against it because: 1) It makes the code bigger. 2) dash has never done this in the past. 3) You cannot use this portably anyway. Reported-by: Dirk Fieldhouse <fieldhouse@gmx.net> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> function old new delta evalcommand 1606 1635 +29 evalcase 313 317 +4 evalfun 280 268 -12 pushlocalvars 48 - -48 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 2/1 up/down: 33/-60) Total: -27 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-04ash,hush: properly handle ${v//pattern/repl} if pattern starts with /Denys Vlasenko
Closes 2695 function old new delta parse_dollar 762 790 +28 subevalvar 1258 1267 +9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 37/0) Total: 37 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-28hush: fix another case where empty "for" wasn't setting exitcode to 0Denys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-24hush: add "heredoc.tests" from ash, tweak ash "is a function" messageDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-24hush: fix nested redirects colliding with script fdsDenys Vlasenko
This necessitates switch from libc FILE api to a simple homegrown replacement. The change which fixes the bug here is the deleting of restore_redirected_FILEs(); line. It was prematurely moving (restoring) script fd#3. The fix is: we don't even _want_ to restore scrit fds, we are perfectly fine with them being moved. The only reason we tried to restore them is that FILE api did not allow moving of FILE->fd. function old new delta refill_HFILE_and_getc - 93 +93 hfopen - 90 +90 hfclose - 66 +66 pseudo_exec_argv 591 597 +6 hush_main 1089 1095 +6 builtin_source 209 214 +5 save_fd_on_redirect 197 200 +3 setup_redirects 320 321 +1 fgetc_interactive 235 236 +1 i_peek_and_eat_bkslash_nl 99 97 -2 expand_vars_to_list 1103 1100 -3 restore_redirects 99 52 -47 fclose_and_forget 57 - -57 remember_FILE 63 - -63 ------------------------------------------------------------------------------ (add/remove: 3/2 grow/shrink: 6/3 up/down: 271/-172) Total: 99 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-24hush: handle backslash-newline in heredoc terminatorsDenys Vlasenko
function old new delta fetch_heredocs 479 527 +48 (ash fails this test) Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-24hush: fix handling of heredocs not enclosed in groups where they are "declared"Denys Vlasenko
function old new delta fetch_heredocs - 479 +479 parse_and_run_stream 146 148 +2 parse_stream 2787 2296 -491 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/1 up/down: 481/-491) Total: -10 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-23hush: fix heredoc handling in the "cmd <<EOF ;<newline>" caseDenys Vlasenko
function old new delta parse_stream 2759 2787 +28 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-23hush: fix handling of heredocs starting with empty linesDenys Vlasenko
function old new delta parse_stream 2748 2759 +11 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-20hush: never glob result of dquoted "${v:+/bin/c*}"Denys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-20hush: fix handling of '' in ${var:+ARG}Denys Vlasenko
This wasn't an ash bug in dollar_altvalue9, it was hush bug (and bash!) function old new delta expand_one_var 2236 2254 +18 expand_vars_to_list 1097 1103 +6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 24/0) Total: 24 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-20hush: fix word splitting in ${v:+ARG} - dollar_altvalue1 testDenys Vlasenko
ash might be a bit buggy, need to investigate dollar_altvalue9 test function old new delta expand_one_var 1639 2236 +597 expand_variables 112 128 +16 expand_vars_to_list 1117 1097 -20 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 613/-20) Total: 593 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-17hush: improve ${var#...}, ${var:+...} and ${var/.../...} - handle quotingDenys Vlasenko
dollar_altvalue1 test partially fails: word splitting of unquoted ${var:+...} is not correct function old new delta encode_then_expand_vararg - 443 +443 expand_one_var 1599 1610 +11 parse_stream 2756 2753 -3 encode_string 250 242 -8 setup_heredoc 308 298 -10 expand_and_evaluate_arith 106 96 -10 encode_then_expand_string 142 126 -16 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/5 up/down: 454/-47) Total: 407 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-11shell: add 6856 $IFS tests to testsuitesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-11hush: fix recent breakage from parse_stream() changesDenys Vlasenko
function old new delta parse_stream 3808 3821 +13 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-11hush: fix IFS handling in readDenys Vlasenko
$ echo "X:Y:" | (IFS=": " read x y; echo "|$x|$y|") |X|Y| $ echo "X:Y : " | (IFS=": " read x y; echo "|$x|$y|") |X|Y| function old new delta shell_builtin_read 1320 1426 +106 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-11hush: IFS fixesDenys Vlasenko
$ IFS=": "; x=" "; set x $x; for v; do echo "|$v|"; done |x| $ IFS=": "; x=":"; set x $x; for v; do echo "|$v|"; done |x| || function old new delta run_pipe 1789 1870 +81 expand_on_ifs 310 361 +51 pseudo_exec_argv 588 591 +3 builtin_local 50 53 +3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/0 up/down: 138/0) Total: 138 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-11hush: fix "$v" expansion in case patterns when v='[a]'Denys Vlasenko
function old new delta run_list 1053 1063 +10 setup_redirects 311 320 +9 encode_then_expand_string 135 142 +7 run_pipe 1784 1789 +5 expand_assignments 81 86 +5 expand_string_to_string 124 125 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 6/0 up/down: 37/0) Total: 37 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-11ash: parser: Allow newlines within parameter substitutionDenys Vlasenko
Upstream commit: Date: Thu, 22 Mar 2018 21:41:24 +0800 parser: Allow newlines within parameter substitution On Fri, Mar 16, 2018 at 11:27:22AM +0800, Herbert Xu wrote: > On Thu, Mar 15, 2018 at 10:49:15PM +0100, Harald van Dijk wrote: > > > > Okay, it can be trivially modified to something that does work in other > > shells (even if it were actually executed), but gets rejected at parse time > > by dash: > > > > if false; then > > : ${$+ > > } > > fi > > That's just a bug in dash's parser with ${} in general, because > it bombs out without the if clause too: > > : ${$+ > } This patch fixes the parsing of newlines with parameter substitution. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-11hush: do not drop backslash from eval 'echo ok\'Denys Vlasenko
newer bash does not drop it, most other shells too function old new delta unbackslash 39 57 +18 parse_stream 2753 2751 -2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 18/-2) Total: 16 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-10hush: fix handling of \<eof> in double-quoted stringsDenys Vlasenko
function old new delta encode_string 268 250 -18 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-10hush: fix eval 'echo ok\'Denys Vlasenko
function old new delta parse_stream 2762 2753 -9 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-05hush: fix a few more corner cases with empty-expanding `cmds`Denys Vlasenko
See added testcases function old new delta run_pipe 1723 1784 +61 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-05hush: fix corner cases with exec in empty expansionsDenys Vlasenko
Cases like these: var=val exec >redir var=val `` >redir function old new delta run_pipe 1701 1723 +22 redirect_and_varexp_helper 56 55 -1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 22/-1) Total: 21 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-05hush: fix a bug where we don't properly handle f() { a=A; b=B; }; a= fDenys Vlasenko
function old new delta unset_local_var 20 274 +254 leave_var_nest_level - 98 +98 set_vars_and_save_old 128 164 +36 enter_var_nest_level - 32 +32 builtin_local 46 50 +4 pseudo_exec_argv 554 544 -10 redirect_and_varexp_helper 77 64 -13 run_pipe 1890 1641 -249 unset_local_var_len 267 - -267 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 3/3 up/down: 424/-539) Total: -115 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-04hush: fix for readonly vars in "ro=A ro=B cmd" caseDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>