Skip to content

Commit

Permalink
[test/spec] Audit arith, array-compat, array.
Browse files Browse the repository at this point in the history
Addresses issue #311.

- arith: Mark failures as OK.  We don't implement insecure runtime
  parsing.
  • Loading branch information
Andy Chu committed Jun 17, 2019
1 parent cce0739 commit 43a906c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
4 changes: 4 additions & 0 deletions metrics/tarball.sh
Expand Up @@ -75,6 +75,10 @@ linecount-pydeps-src-only() {
echo
_wc-header
_py-deps-src-only | sort | uniq | xargs wc -l | sort -n

echo
echo 'ASDL SCHEMAS'
wc -l "${ASDL_FILES[@]}"
}

# hello: 1.41 MB native + 145 KB = 1.56 MB bundle
Expand Down
2 changes: 2 additions & 0 deletions spec/arith.test.sh
Expand Up @@ -264,6 +264,7 @@ foo=5
x=oo
echo $(( foo + f$x + 1 ))
## stdout: 11
## OK osh stdout: 6

#### Bizarre recursive name evaluation - result of runtime parse/eval
foo=5
Expand All @@ -272,6 +273,7 @@ spam=bar
eggs=spam
echo $((foo+1)) $((bar+1)) $((spam+1)) $((eggs+1))
## stdout: 6 6 6 6
## OK osh stdout: 6 1 1 1
## N-I dash stdout-json: ""
## N-I dash status: 2

Expand Down
12 changes: 7 additions & 5 deletions spec/array-compat.test.sh
Expand Up @@ -27,15 +27,15 @@ b="${a[@]}" # this collapses to a string
c=("${a[@]}") # this preserves the array
c[1]=YYY # mutate a copy -- doesn't affect the original
argv.py "${a[@]}"
argv.py "${b[@]}"
argv.py "${b}"
argv.py "${c[@]}"
## STDOUT:
['x', 'y', 'z']
['x y z']
['x', 'YYY', 'z']
## END

#### $a gives first element of array
#### $a gives first element of array (TODO: osh should disallow)
a=(1 '2 3')
echo $a
## stdout: 1
Expand Down Expand Up @@ -64,11 +64,13 @@ echo ${#a[@]} ${#s}
EQUAL
## END

#### Increment array variables
a=(1 2)
#### ++ on a whole array increments the first element (disallowed in OSH)
a=(1 10)
(( a++ )) # doesn't make sense
echo "${a[@]}"
## stdout: 2 2
## stdout: 2 10
## OK osh status: 1
## OK osh stdout-json: ""

#### Apply vectorized operations on ${a[*]}
a=('-x-' 'y-y' '-z-')
Expand Down
2 changes: 1 addition & 1 deletion spec/array.test.sh
Expand Up @@ -147,7 +147,7 @@ argv.py "${!a[1]}"
## stdout: ['bar']
## N-I mksh stdout: ['a[1]']

#### ${!a} on array
#### ${!a} on array (TODO: OSH should disallow)
# bash gives empty string?
# mksh gives the name of the variable with !. Very weird.
a=(1 '2 3')
Expand Down
8 changes: 7 additions & 1 deletion test/runtime-errors.sh
Expand Up @@ -437,6 +437,12 @@ multiple_assign_2() {
echo $y
}

string_as_array() {
local str='foo'
echo $str
echo "${str[@]}"
}

#
# BUILTINS
#
Expand Down Expand Up @@ -623,7 +629,7 @@ all() {
nounset_arith divzero divzero_var array_arith undef_arith undef_arith2 \
undef_assoc_array \
string_to_int_arith string_to_hex string_to_octal \
string_to_intbase string_to_int_bool \
string_to_intbase string_to_int_bool string_as_array \
array_assign_1 array_assign_2 readonly_assign \
multiple_assign multiple_assign_2 patsub_bad_glob \
builtin_bracket builtin_builtin builtin_source builtin_cd builtin_pushd \
Expand Down
4 changes: 2 additions & 2 deletions test/spec.sh
Expand Up @@ -394,7 +394,7 @@ glob() {
}

arith() {
sh-spec spec/arith.test.sh --osh-failures-allowed 2 \
sh-spec spec/arith.test.sh \
${REF_SHELLS[@]} $ZSH $OSH_LIST "$@"
}

Expand Down Expand Up @@ -542,7 +542,7 @@ array() {
}

array-compat() {
sh-spec spec/array-compat.test.sh --osh-failures-allowed 4 \
sh-spec spec/array-compat.test.sh --osh-failures-allowed 2 \
$BASH $MKSH $OSH_LIST "$@"
}

Expand Down

0 comments on commit 43a906c

Please sign in to comment.