Skip to content

Commit

Permalink
[spec/var-op-test] Add failing test case for "${v[@]+foo}" and set -u (
Browse files Browse the repository at this point in the history
…#1857)

- Test this file with zsh too

---------

Co-authored-by: Andy C <andy@oilshell.org>
  • Loading branch information
Melkor333 and Andy C committed Mar 19, 2024
1 parent 1c25aa0 commit 9552ad4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
50 changes: 48 additions & 2 deletions spec/var-op-test.test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## oils_failures_allowed: 1
## compare_shells: bash dash mksh zsh

#### Lazy Evaluation of Alternative
i=0
Expand Down Expand Up @@ -33,6 +35,10 @@ argv.py X${unset=x$@x}X # If you want OSH to split, write this
['Xx1 2', '3 4xX']
['Xx1', '2', '3', '4xX']
## END
## OK zsh STDOUT:
['Xx1 2 3 4xX']
['Xx1 2 3 4xX']
## END

#### Quoted with array as default value
set -- '1 2' '3 4'
Expand Down Expand Up @@ -63,6 +69,10 @@ argv.py "$unset"
['Xx1 2', '3 4xX']
['x1 2 3 4x']
## END
## OK zsh STDOUT:
['Xx1 2 3 4xX']
['x1 2 3 4x']
## END

#### Assign default value when empty
empty=''
Expand Down Expand Up @@ -108,6 +118,24 @@ v=
v=
## END

#### "${a[@]+foo}" and "${a[@]:+foo}" undefined, with set -u
case $SH in dash) exit ;; esac

set -u

echo array="${array[@]+foo}"
echo array="${array[@]:+foo}"
## status: 0

## STDOUT:
array=
array=
## END

## N-I dash STDOUT:
## END


#### ${v-foo} and ${v:-foo} when set -u
set -u
v=v
Expand Down Expand Up @@ -194,6 +222,8 @@ a3=plus
['plus']
## END
## N-I dash stdout-json: ""
## N-I zsh stdout-json: "empty=\na1=\n"
## N-I zsh status: 1

#### $@ and - and +
echo argv=${@-minus}
Expand All @@ -206,7 +236,7 @@ argv=
argv=minus
argv=
## END
## BUG dash STDOUT:
## BUG dash/zsh STDOUT:
argv=
argv=plus
argv=minus
Expand Down Expand Up @@ -240,7 +270,21 @@ empty=
assoc=v
assoc=plus
## END
## N-I dash/mksh stdout-json: ""

## BUG zsh STDOUT:
empty=
empty=plus
assoc=minus
assoc=
---
empty=minus
empty=
assoc=minus
assoc=
## END

## N-I dash/mksh STDOUT:
## END


#### Error when empty
Expand Down Expand Up @@ -288,6 +332,8 @@ echo ${#arr[@]}
## END
## N-I dash status: 2
## N-I dash stdout-json: ""
## N-I zsh status: 1
## N-I zsh stdout-json: "0\n"

#### assoc array ${arr["k"]=x}
# note: this also works in zsh
Expand Down
3 changes: 1 addition & 2 deletions test/spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,7 @@ tilde() {
}

var-op-test() {
sh-spec spec/var-op-test.test.sh \
${REF_SHELLS[@]} $OSH_LIST "$@"
run-file var-op-test "$@"
}

var-op-len() {
Expand Down

0 comments on commit 9552ad4

Please sign in to comment.