diff options
author | Peter Stephenson <p.stephenson@samsung.com> | 2018-10-08 10:10:42 +0100 |
---|---|---|
committer | Peter Stephenson <p.stephenson@samsung.com> | 2018-10-08 10:10:42 +0100 |
commit | f99f7dca7552d21782354f675c0741896c9785f1 (patch) | |
tree | f58dbc43d86c53b5a6f5cb3513214d22e8c0368c /Test | |
parent | 5c9ef1a1faf42136ce330aa6f8e2123e83497239 (diff) | |
download | zsh-f99f7dca7552d21782354f675c0741896c9785f1.tar.gz zsh-f99f7dca7552d21782354f675c0741896c9785f1.tar.xz zsh-f99f7dca7552d21782354f675c0741896c9785f1.zip |
43616: Various parameter setting and display fixes.
Mostly to do with typeset -p and tied variables and their interaction. Some general tied variable fixes.
Diffstat (limited to 'Test')
-rw-r--r-- | Test/B02typeset.ztst | 291 |
1 files changed, 284 insertions, 7 deletions
diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst index b53f42f83..ac86e0ad1 100644 --- a/Test/B02typeset.ztst +++ b/Test/B02typeset.ztst @@ -20,6 +20,14 @@ # Not yet tested: # Assorted illegal flag combinations +# For a few tests, we include a +# typeset -p param +# typeset -m param +# typeset +m param +# to test the proper output of typeset for a number of different types +# of variables. Note that we can't use a dedicated function to factorize +# that code, as that would affect the scoping. + %prep ## Do not remove the next line, it's used by V10private.ztst # test_zsh_param_private @@ -37,6 +45,9 @@ typeset -a array array=(l o c a l) print $scalar $array + typeset -p scalar array + typeset -m scalar array + typeset +m scalar array } scope01() { local scalar @@ -44,6 +55,9 @@ local -a array array=(l o c a l) print $scalar $array + typeset -p scalar array + typeset -m scalar array + typeset +m scalar array } scope02() { declare scalar @@ -51,10 +65,16 @@ declare -a array array=(l o c a l) print $scalar $array + typeset -p scalar array + typeset -m scalar array + typeset +m scalar array } scope10() { export outer=outer /bin/sh -fc 'echo $outer' + typeset -p outer + typeset -m outer + typeset +m outer } scope11() { typeset -x outer=outer @@ -68,6 +88,9 @@ local -xT OUTER outer outer=(i n n e r) /bin/sh -fc 'echo $OUTER' + typeset -p OUTER outer + typeset -m OUTER outer + typeset +m OUTER outer } # Bug? `typeset -h' complains that ! # $ * - ? @ are not identifiers. @@ -79,8 +102,14 @@ %test + typeset -p scalar array + typeset -m scalar array typeset +m scalar array -0:Report types of parameters with typeset +m +0:Report types for global variables +>typeset -g scalar=scalar +>typeset -g -a array=( a r r a y ) +>scalar=scalar +>array=( a r r a y ) >scalar >array array @@ -88,18 +117,36 @@ print $scalar $array 0:Simple local declarations >local l o c a l +>typeset scalar=local +>typeset -a array=( l o c a l ) +>scalar=local +>array=( l o c a l ) +>local scalar +>array local array >scalar a r r a y scope01 print $scalar $array 0:Equivalence of local and typeset in functions >local l o c a l +>typeset scalar=local +>typeset -a array=( l o c a l ) +>scalar=local +>array=( l o c a l ) +>local scalar +>array local array >scalar a r r a y scope02 print $scalar $array 0:Basic equivalence of declare and typeset >local l o c a l +>typeset scalar=local +>typeset -a array=( l o c a l ) +>scalar=local +>array=( l o c a l ) +>local scalar +>array local array >scalar a r r a y declare +m scalar @@ -110,6 +157,9 @@ print $outer 0:Global export >outer +>export outer=outer +>outer=outer +>outer >outer scope11 @@ -130,18 +180,30 @@ print $f float -F f print $f + typeset -p f + typeset -m f + typeset +m f 0:Floating point, adding a precision, and fixed point >float local f >3.14e+00 >3.142 +>typeset -F f=3.142 +>f=3.142 +>float local f integer i=3.141 typeset +m i integer -i2 i print $i + typeset -p i + typeset -m i + typeset +m i 0:Integer and changing the base >integer local i >2#11 +>typeset -i2 i=3 +>i=3 +>integer 2 local i float -E3 f=3.141 typeset +m f @@ -174,16 +236,33 @@ typeset -gU array print $array + typeset -p array + typeset -m array + typeset +m array 0:Uniquified arrays and non-local scope >a r y +>typeset -g -aU array=( a r y ) +>array=( a r y ) +>array unique array typeset -T SCALAR=l:o:c:a:l array print $array typeset -U SCALAR print $SCALAR $array + typeset -p SCALAR array + typeset -m SCALAR array + typeset +m SCALAR array + print ${(t)SCALAR} ${(t)array} 0:Tied parameters and uniquified colon-arrays >l o c a l >l:o:c:a l o c a +>typeset -UT SCALAR array=( l o c a ) +>typeset -aT SCALAR array=( l o c a ) +>SCALAR=l:o:c:a +>array=( l o c a ) +>local unique tied array SCALAR +>array local tied SCALAR array +>scalar-local-tied-unique array-local-tied (setopt NO_multibyte cbases LC_ALL=C 2>/dev/null @@ -209,9 +288,18 @@ typeset -T SCALAR=$'l\000o\000c\000a\000l' array $'\000' typeset -U SCALAR print $array + typeset -p SCALAR array + typeset -m SCALAR array + typeset +m SCALAR array [[ $SCALAR == $'l\000o\000c\000a' ]] 0:Tied parameters and uniquified arrays with NUL-character as separator >l o c a +>typeset -UT SCALAR array=( l o c a ) '' +>typeset -aT SCALAR array=( l o c a ) '' +>SCALAR=$'l\C-@o\C-@c\C-@a' +>array=( l o c a ) +>local unique tied array SCALAR +>array local tied SCALAR array typeset -T SCALAR array typeset +T SCALAR @@ -223,15 +311,30 @@ print $OUTER 0:Export of tied parameters >i:n:n:e:r +>typeset -xT OUTER outer=( i n n e r ) +>typeset -aT OUTER outer=( i n n e r ) +>OUTER=i:n:n:e:r +>outer=( i n n e r ) +>local exported tied outer OUTER +>array local tied OUTER outer >outer typeset -TU MORESTUFF=here-we-go-go-again morestuff '-' print -l $morestuff + typeset -p MORESTUFF morestuff + typeset -m MORESTUFF morestuff + typeset +m MORESTUFF morestuff 0:Tied arrays with separator specified >here >we >go >again +>typeset -UT MORESTUFF morestuff=( here we go again ) - +>typeset -aUT MORESTUFF morestuff=( here we go again ) - +>MORESTUFF=here-we-go-again +>morestuff=( here we go again ) +>local unique tied morestuff MORESTUFF +>array local unique tied MORESTUFF morestuff typeset -T THIS will not work 1:Tied array syntax @@ -251,13 +354,25 @@ local b=1 ;: to stomp assoc[1] if assoc[b] is broken typeset assoc[1]=a assoc[b]=2 assoc[3]=c print $assoc[1] $assoc[b] $assoc[3] + typeset -p assoc + typeset -m assoc + typeset +m assoc 0:Legal local associative array element assignment >a 2 c +>typeset -A assoc=( [1]=a [3]=c [b]=2 ) +>assoc=( [1]=a [3]=c [b]=2 ) +>association local assoc local scalar scalar[1]=a scalar[2]=b scalar[3]=c print $scalar + typeset -p scalar + typeset -m scalar + typeset +m scalar 0:Local scalar subscript assignment >abc +>typeset scalar=abc +>scalar=abc +>local scalar typeset -L 10 fools for fools in " once" "twice" " thrice" " oops too long here"; do @@ -273,11 +388,17 @@ for foolf in 1.3 4.6 -2.987 -4.91031; do print "'$foolf'" done + typeset -p foolf + typeset -m foolf + typeset +m foolf 0:Left justification of floating point >'1.300 ' >'4.600 ' >'-2.987 ' >'-4.910 ' +>typeset -FL10 foolf=-4.910 +>foolf=-4.910 +>float local left justified 10 foolf typeset -L 10 -Z foolzs for foolzs in 001.3 04.6 -2.987 -04.91231; do @@ -293,10 +414,16 @@ for foors in short longer even-longer; do print "'$foors'" done + typeset -p foors + typeset -m foors + typeset +m foors 0:Right justification of scalars >' short' >' longer' >'ven-longer' +>typeset -R10 foors=even-longer +>foors=even-longer +>local right justified 10 foors typeset -Z 10 foozs for foozs in 42 -42 " 43" " -43"; do @@ -436,24 +563,36 @@ print $case1 upper="VALUE OF \$UPPER" print ${(P)case1} + typeset -p case1 + typeset -m case1 + typeset +m case1 0:Upper case conversion, does not apply to values used internally >UPPER >VALUE OF $UPPER +>typeset -u case1=upper +>case1=upper +>local uppercase case1 local case2=LOWER typeset -l case2 print $case2 LOWER="value of \$lower" print ${(P)case2} + typeset -p case2 + typeset -m case2 + typeset +m case2 0:Lower case conversion, does not apply to values used internally >lower >value of $lower +>typeset -l case2=LOWER +>case2=LOWER +>local lowercase case2 typeset -a array array=(foo bar) fn() { typeset -p array nonexistent; } fn -1:declare -p shouldn't create scoped values +1:typeset -p shouldn't create scoped values >typeset -g -a array=( foo bar ) ?fn:typeset: no such variable: nonexistent @@ -490,7 +629,7 @@ ?0 ?(eval):5: read-only variable: pbro ?(eval):6: read-only variable: pbro -?typeset -g -r pbro +?readonly pbro ?0 ?(eval):10: read-only variable: pbro @@ -820,7 +959,145 @@ > [three]='' >) - (typeset -a -U foo=(bar bar) - typeset -p foo) -0:typeset -p of typeset -U ->typeset -aU foo=( bar ) + (export PATH MANPATH + path=(/bin) + MANPATH=/ + # read-only special params like zsh_eval_context are not output by typeset -p + specials=(path PATH manpath MANPATH zsh_eval_context ZSH_EVAL_CONTEXT) + typeset -p $specials + typeset -m $specials + typeset +m $specials + for var ($specials) print $var: ${(Pt)var} + ) +0:typeset output for some special tied parameters +>typeset -g -aT PATH path=( /bin ) +>export -T PATH path=( /bin ) +>typeset -g -aT MANPATH manpath=( / ) +>export -T MANPATH manpath=( / ) +>path=( /bin ) +>PATH=/bin +>manpath=( / ) +>MANPATH=/ +>zsh_eval_context=( toplevel shfunc shfunc shfunc eval ) +>ZSH_EVAL_CONTEXT=toplevel:shfunc:shfunc:shfunc:eval +>array tied PATH path +>tied path PATH +>array tied MANPATH manpath +>tied manpath MANPATH +>array readonly tied ZSH_EVAL_CONTEXT zsh_eval_context +>readonly tied zsh_eval_context ZSH_EVAL_CONTEXT +>path: array-tied-special +>PATH: scalar-tied-export-special +>manpath: array-tied-special +>MANPATH: scalar-tied-export-special +>zsh_eval_context: array-readonly-tied-special +>ZSH_EVAL_CONTEXT: scalar-readonly-tied-special + + typeset -T VAR var=(a b a b) + typeset -UuT VAR var + + print $VAR +0:redeclare a tied variable with different attributes +>A+B + + typeset -T VAR=a+b var + typeset -T VAR var + + print $var +0:colonarray re-split when changing the join character +>a b + + readonly -T VAR var=(a b) + readonly -T VAR var + +1:cannot change the join character on a readonly tied variable +?(eval):1: read-only variable: var + + typeset -T FOO manpath +1:Can't tie a special tied array to a different variable +?(eval):typeset:1: manpath special parameter can only be tied to special parameter MANPATH + + typeset -T MANPATH foo +1:Can't tie a special tied scalar to a different variable +?(eval):typeset:1: MANPATH special parameter can only be tied to special parameter manpath + + typeset -T MANPATH manpath + +1:Can't change the join character of a special tied variable +?(eval):typeset:1: cannot change the join character of special tied parameters + + (){ + typeset -h path + typeset -T PATH path=(x) + } + (){ + typeset -h PATH + typeset -T PATH path=(x) + } +1:reject attempt to tie special to downgraded peer +?(anon):typeset:2: PATH special parameter can only be tied to special parameter path +?(anon):typeset:2: path special parameter can only be tied to special parameter PATH + + typeset MANPATH + manpath=(/ /) + typeset -UT MANPATH manpath + print $manpath +0:OK to run typeset -T on tied specials as long as peer and joinchar are unchanged +>/ + + typeset FOO=a:b + export FOO + typeset +x -T FOO foo + typeset -p FOO +0:Make sure +x is honoured when tying a parameter +>typeset -T FOO foo=( a b ) + + $ZTST_testdir/../Src/zsh --emulate sh -f -c ' + PATH=/bin; export PATH; readonly PATH + export -p PATH + typeset -p PATH + readonly -p' +0: readonly/export output for exported+readonly+special when started as sh +>export PATH=/bin +>export -r PATH=/bin +>readonly PATH=/bin + + function { + emulate -L sh + MANPATH=/bin; export MANPATH; readonly MANPATH + export -p MANPATH + typeset -p MANPATH + readonly -p + } +0: readonly/export output for exported+readonly+tied+special after switching to sh emulation +>export MANPATH=/bin +>export -rT MANPATH manpath=( /bin ) +>readonly MANPATH=/bin + + function { + local -rax zsh_exported_readonly_array=(2) + local -rAx zsh_exported_readonly_hash=(3 3) + local -rx zsh_exported_readonly_scalar=1 + print zsh: + export -p | grep zsh_exported_readonly + readonly -p | grep zsh_exported_readonly + print sh: + emulate -L sh + export -p | grep zsh_exported_readonly + readonly -p | grep zsh_exported_readonly + print still asking for arrays: + export -ap | grep zsh_exported_readonly + readonly -ap | grep zsh_exported_readonly + } +0: no array/hash in POSIX export/readonly -p +>zsh: +>typeset -arx zsh_exported_readonly_array=( 2 ) +>typeset -Arx zsh_exported_readonly_hash=( [3]=3 ) +>typeset -rx zsh_exported_readonly_scalar=1 +>typeset -arx zsh_exported_readonly_array=( 2 ) +>typeset -Arx zsh_exported_readonly_hash=( [3]=3 ) +>typeset -rx zsh_exported_readonly_scalar=1 +>sh: +>export zsh_exported_readonly_scalar=1 +>readonly zsh_exported_readonly_scalar=1 +>still asking for arrays: +>export zsh_exported_readonly_array=( 2 ) +>export zsh_exported_readonly_scalar=1 +>readonly zsh_exported_readonly_array=( 2 ) +>readonly zsh_exported_readonly_scalar=1 |