mirror of
https://github.com/sheumann/hush.git
synced 2025-01-18 07:31:34 +00:00
add hush tests for parameter expansion
This commit is contained in:
parent
6379bb4fde
commit
78f9d8eb7a
8
shell/hush_test/hush-vars/param_expand_alt.right
Normal file
8
shell/hush_test/hush-vars/param_expand_alt.right
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
hush: syntax error: unterminated ${name}
|
||||||
|
hush: syntax error: unterminated ${name}
|
||||||
|
_0 _0
|
||||||
|
_ _ _ _ _
|
||||||
|
_aaaa _ _ _word _word
|
||||||
|
_ _ _ _ _
|
||||||
|
_ _ _ _word _
|
||||||
|
_fff _ _ _word _word
|
22
shell/hush_test/hush-vars/param_expand_alt.tests
Executable file
22
shell/hush_test/hush-vars/param_expand_alt.tests
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
# first try some invalid patterns (do in subshell due to parsing error)
|
||||||
|
hush -c 'echo ${+} ; echo moo'
|
||||||
|
hush -c 'echo ${:+} ; echo moo'
|
||||||
|
|
||||||
|
# now some funky ones
|
||||||
|
echo _${#+} _${#:+}
|
||||||
|
|
||||||
|
# now some valid ones
|
||||||
|
set --
|
||||||
|
echo _$1 _${1+} _${1:+} _${1+word} _${1:+word}
|
||||||
|
|
||||||
|
set -- aaaa
|
||||||
|
echo _$1 _${1+} _${1:+} _${1+word} _${1:+word}
|
||||||
|
|
||||||
|
unset f
|
||||||
|
echo _$f _${f+} _${f:+} _${f+word} _${f:+word}
|
||||||
|
|
||||||
|
f=
|
||||||
|
echo _$f _${f+} _${f:+} _${f+word} _${f:+word}
|
||||||
|
|
||||||
|
f=fff
|
||||||
|
echo _$f _${f+} _${f:+} _${f+word} _${f:+word}
|
27
shell/hush_test/hush-vars/param_expand_assign.right
Normal file
27
shell/hush_test/hush-vars/param_expand_assign.right
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
hush: syntax error: unterminated ${name}
|
||||||
|
hush: syntax error: unterminated ${name}
|
||||||
|
0
|
||||||
|
0
|
||||||
|
hush: 1: special vars cannot assign in this way
|
||||||
|
hush: 1: special vars cannot assign in this way
|
||||||
|
hush: 1: special vars cannot assign in this way
|
||||||
|
hush: 1: special vars cannot assign in this way
|
||||||
|
_aa
|
||||||
|
_aa
|
||||||
|
_aa
|
||||||
|
_aa
|
||||||
|
_
|
||||||
|
_
|
||||||
|
_
|
||||||
|
_word
|
||||||
|
_word
|
||||||
|
_
|
||||||
|
_
|
||||||
|
_
|
||||||
|
_
|
||||||
|
_word
|
||||||
|
_fff
|
||||||
|
_fff
|
||||||
|
_fff
|
||||||
|
_fff
|
||||||
|
_fff
|
38
shell/hush_test/hush-vars/param_expand_assign.tests
Executable file
38
shell/hush_test/hush-vars/param_expand_assign.tests
Executable file
@ -0,0 +1,38 @@
|
|||||||
|
# first try some invalid patterns (do in subshell due to parsing error)
|
||||||
|
hush -c 'echo ${=}'
|
||||||
|
hush -c 'echo ${:=}'
|
||||||
|
|
||||||
|
# now some funky ones
|
||||||
|
hush -c 'echo ${#=}'
|
||||||
|
hush -c 'echo ${#:=}'
|
||||||
|
|
||||||
|
# should error out
|
||||||
|
hush -c 'set --; echo _${1=}'
|
||||||
|
hush -c 'set --; echo _${1:=}'
|
||||||
|
hush -c 'set --; echo _${1=word}'
|
||||||
|
hush -c 'set --; echo _${1:=word}'
|
||||||
|
|
||||||
|
# should not error
|
||||||
|
hush -c 'set aa; echo _${1=}'
|
||||||
|
hush -c 'set aa; echo _${1:=}'
|
||||||
|
hush -c 'set aa; echo _${1=word}'
|
||||||
|
hush -c 'set aa; echo _${1:=word}'
|
||||||
|
|
||||||
|
# should work fine
|
||||||
|
unset f; echo _$f
|
||||||
|
unset f; echo _${f=}
|
||||||
|
unset f; echo _${f:=}
|
||||||
|
unset f; echo _${f=word}
|
||||||
|
unset f; echo _${f:=word}
|
||||||
|
|
||||||
|
f=; echo _$f
|
||||||
|
f=; echo _${f=}
|
||||||
|
f=; echo _${f:=}
|
||||||
|
f=; echo _${f=word}
|
||||||
|
f=; echo _${f:=word}
|
||||||
|
|
||||||
|
f=fff; echo _$f
|
||||||
|
f=fff; echo _${f=}
|
||||||
|
f=fff; echo _${f:=}
|
||||||
|
f=fff; echo _${f=word}
|
||||||
|
f=fff; echo _${f:=word}
|
8
shell/hush_test/hush-vars/param_expand_default.right
Normal file
8
shell/hush_test/hush-vars/param_expand_default.right
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
hush: syntax error: unterminated ${name}
|
||||||
|
hush: syntax error: unterminated ${name}
|
||||||
|
_0 _0
|
||||||
|
_ _ _ _word _word
|
||||||
|
_aaaa _aaaa _aaaa _aaaa _aaaa
|
||||||
|
_ _ _ _word _word
|
||||||
|
_ _ _ _ _word
|
||||||
|
_fff _fff _fff _fff _fff
|
22
shell/hush_test/hush-vars/param_expand_default.tests
Executable file
22
shell/hush_test/hush-vars/param_expand_default.tests
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
# first try some invalid patterns (do in subshell due to parsing error)
|
||||||
|
hush -c 'echo ${-}'
|
||||||
|
hush -c 'echo ${:-}'
|
||||||
|
|
||||||
|
# now some funky ones
|
||||||
|
echo _${#-} _${#:-}
|
||||||
|
|
||||||
|
# now some valid ones
|
||||||
|
set --
|
||||||
|
echo _$1 _${1-} _${1:-} _${1-word} _${1:-word}
|
||||||
|
|
||||||
|
set -- aaaa
|
||||||
|
echo _$1 _${1-} _${1:-} _${1-word} _${1:-word}
|
||||||
|
|
||||||
|
unset f
|
||||||
|
echo _$f _${f-} _${f:-} _${f-word} _${f:-word}
|
||||||
|
|
||||||
|
f=
|
||||||
|
echo _$f _${f-} _${f:-} _${f-word} _${f:-word}
|
||||||
|
|
||||||
|
f=fff
|
||||||
|
echo _$f _${f-} _${f:-} _${f-word} _${f:-word}
|
29
shell/hush_test/hush-vars/param_expand_indicate_error.right
Normal file
29
shell/hush_test/hush-vars/param_expand_indicate_error.right
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
hush: syntax error: unterminated ${name}
|
||||||
|
hush: syntax error: unterminated ${name}
|
||||||
|
0
|
||||||
|
0
|
||||||
|
_
|
||||||
|
hush: 1: parameter null or not set
|
||||||
|
hush: 1: parameter null or not set
|
||||||
|
hush: 1: word
|
||||||
|
hush: 1: word
|
||||||
|
_aaaa
|
||||||
|
_aaaa
|
||||||
|
_aaaa
|
||||||
|
_aaaa
|
||||||
|
_aaaa
|
||||||
|
_
|
||||||
|
hush: f: parameter null or not set
|
||||||
|
hush: f: parameter null or not set
|
||||||
|
hush: f: word
|
||||||
|
hush: f: word
|
||||||
|
_
|
||||||
|
_
|
||||||
|
hush: f: parameter null or not set
|
||||||
|
_
|
||||||
|
hush: f: word
|
||||||
|
_fff
|
||||||
|
_fff
|
||||||
|
_fff
|
||||||
|
_fff
|
||||||
|
_fff
|
40
shell/hush_test/hush-vars/param_expand_indicate_error.tests
Executable file
40
shell/hush_test/hush-vars/param_expand_indicate_error.tests
Executable file
@ -0,0 +1,40 @@
|
|||||||
|
# do all of these in subshells since it's supposed to error out
|
||||||
|
|
||||||
|
# first try some invalid patterns
|
||||||
|
hush -c 'echo ${?}'
|
||||||
|
hush -c 'echo ${:?}'
|
||||||
|
|
||||||
|
# then some funky ones
|
||||||
|
hush -c 'echo ${#?}'
|
||||||
|
hush -c 'echo ${#:?}'
|
||||||
|
|
||||||
|
# now some valid ones
|
||||||
|
hush -c 'set --; echo _$1'
|
||||||
|
hush -c 'set --; echo _${1?}'
|
||||||
|
hush -c 'set --; echo _${1:?}'
|
||||||
|
hush -c 'set --; echo _${1?word}'
|
||||||
|
hush -c 'set --; echo _${1:?word}'
|
||||||
|
|
||||||
|
hush -c 'set -- aaaa; echo _$1'
|
||||||
|
hush -c 'set -- aaaa; echo _${1?}'
|
||||||
|
hush -c 'set -- aaaa; echo _${1:?}'
|
||||||
|
hush -c 'set -- aaaa; echo _${1?word}'
|
||||||
|
hush -c 'set -- aaaa; echo _${1:?word}'
|
||||||
|
|
||||||
|
hush -c 'unset f; echo _$f'
|
||||||
|
hush -c 'unset f; echo _${f?}'
|
||||||
|
hush -c 'unset f; echo _${f:?}'
|
||||||
|
hush -c 'unset f; echo _${f?word}'
|
||||||
|
hush -c 'unset f; echo _${f:?word}'
|
||||||
|
|
||||||
|
hush -c 'f=; echo _$f'
|
||||||
|
hush -c 'f=; echo _${f?}'
|
||||||
|
hush -c 'f=; echo _${f:?}'
|
||||||
|
hush -c 'f=; echo _${f?word}'
|
||||||
|
hush -c 'f=; echo _${f:?word}'
|
||||||
|
|
||||||
|
hush -c 'f=fff; echo _$f'
|
||||||
|
hush -c 'f=fff; echo _${f?}'
|
||||||
|
hush -c 'f=fff; echo _${f:?}'
|
||||||
|
hush -c 'f=fff; echo _${f?word}'
|
||||||
|
hush -c 'f=fff; echo _${f:?word}'
|
4
shell/hush_test/hush-vars/param_expand_len.right
Normal file
4
shell/hush_test/hush-vars/param_expand_len.right
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
0 0
|
||||||
|
4 4
|
||||||
|
4 3 2 1 0 0
|
||||||
|
0 3 0
|
12
shell/hush_test/hush-vars/param_expand_len.tests
Executable file
12
shell/hush_test/hush-vars/param_expand_len.tests
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
# make sure len parsing doesnt break arg count
|
||||||
|
set --
|
||||||
|
echo $# ${#}
|
||||||
|
set -- aaaa bbb cc d
|
||||||
|
echo $# ${#}
|
||||||
|
|
||||||
|
echo ${#1} ${#2} ${#3} ${#4} ${#5} ${#6}
|
||||||
|
|
||||||
|
unset e
|
||||||
|
f=abc
|
||||||
|
g=
|
||||||
|
echo ${#e} ${#f} ${#g}
|
Loading…
x
Reference in New Issue
Block a user