Skip to content

Commit

Permalink
[test/spec] Audit var-ref cases.
Browse files Browse the repository at this point in the history
Addresses #311.

Two cases are marked OK.  Filed bug #343.
  • Loading branch information
Andy Chu committed Jun 17, 2019
1 parent faa4965 commit 5c8b44d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions spec/var-ref.test.sh
Expand Up @@ -23,7 +23,7 @@ ref=*; printf "|%s" "${!ref}" $'\n'
|x y|
## END

#### var ref with special vars
#### var ref to $? with '?'
myfunc() {
local ref=$1
echo ${!ref}
Expand All @@ -34,6 +34,10 @@ myfunc '?' # osh doesn't do this dynamically
myfunc
0
## END
## N-I osh STDOUT:
myfunc
## END
## N-I osh status: 1

#### indirection, *then* fancy expansion features
check_eq() {
Expand Down Expand Up @@ -186,21 +190,26 @@ echo done
## OK bash stdout: done

#### declare -n and ${!a}
# NOTE: This is like named-ref.test.sh. OSH doesn't implement it at all.
# Maybe we should throw an error on '-n'.
declare -n a
a=b
b=c
echo ${!a} ${a}
## stdout: b c

#### Bad var ref with ${!a}
#set -o nounset
a='bad var name'
echo ref ${!a}
echo status=$?
## STDOUT:
status=1
## END

# this error is fatal in osh
## OK osh stdout-json: ""
## OK osh status: 1

#### ${!OPTIND} (used by bash completion
set -- a b c
echo ${!OPTIND}
Expand Down
2 changes: 1 addition & 1 deletion test/spec.sh
Expand Up @@ -611,7 +611,7 @@ extglob-match() {
# ${!var} syntax -- oil should replace this with associative arrays.
# mksh has completely different behavior for this syntax. Not worth testing.
var-ref() {
sh-spec spec/var-ref.test.sh --osh-failures-allowed 6 \
sh-spec spec/var-ref.test.sh --osh-failures-allowed 4 \
$BASH $OSH_LIST "$@"
}

Expand Down

0 comments on commit 5c8b44d

Please sign in to comment.