From d4fa4c36896e0d89bf4b32388db08fc1a8523dd4 Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Wed, 9 Dec 2020 21:32:36 -0800 Subject: Make DECLAREDNULL require POSIXBUILTINS and introduce a new test file. V10private has been made agnostic to POSIXBUILTINS. --- Test/E03posix.ztst | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Test/E03posix.ztst (limited to 'Test/E03posix.ztst') diff --git a/Test/E03posix.ztst b/Test/E03posix.ztst new file mode 100644 index 000000000..5e6eddeba --- /dev/null +++ b/Test/E03posix.ztst @@ -0,0 +1,105 @@ +# Test POSIX-specific behavior +# Currently this covers only POSIXBUILTINS, other behaviors are in their +# more directly related sections +# + +%prep + setopt POSIX_BUILTINS + +%test + + local parentenv=preserved + fn() { + typeset -h +g -m \* + unset -m \* + integer i=9 + float -H f=9 + declare -t scalar + declare -H -a array + typeset + typeset + + } + fn + echo $parentenv +0:Parameter hiding and tagging, printing types and values +>array local array +>float local f +>integer local i=9 +>local tagged scalar +>array local array +>float local f +>integer local i +>local tagged scalar +>preserved + + readonly foo=bar novalue + readonly -p +0:readonly -p output (no readonly specials) +>readonly foo=bar +>readonly novalue + + local -a myarray + typeset -p1 myarray + myarray=("&" sand '""' "" plugh) + typeset -p1 myarray +0:typeset -p1 output for array +>typeset -a myarray +>typeset -a myarray=( +> '&' +> sand +> '""' +> '' +> plugh +>) + + local -A myhash + typeset -p1 myhash + myhash=([one]=two [three]= [four]="[]") + typeset -p1 myhash +0:typeset -p1 output for associative array +>typeset -A myhash +>typeset -A myhash=( +> [four]='[]' +> [one]=two +> [three]='' +>) + + str=s + arr=(a) + typeset -A ass + ass=(a a) + integer i=0 + float f=0 + print ${(t)str} ${(t)arr} ${(t)ass} ${(t)i} ${(t)f} +0:${(t)...} +>scalar array association-local integer-local float-local + + print $empty[(i)] $empty[(I)] +0:(i) and (I) return nothing for empty array +> + + ( + # reserved words are handled during parsing, + # hence eval... + disable -r typeset + eval ' + setopt kshtypeset + ktvars=(ktv1 ktv2) + typeset ktfoo=`echo arg1 arg2` $ktvars + () { + local ktfoo + print $+ktv1 $+ktv2 $+ktv3 $+ktfoo + } + print $ktfoo + unsetopt kshtypeset + typeset noktfoo=`echo noktarg1 noktarg2` + print $noktfoo + print $+noktarg1 $+noktarg2 + unset ktfoo ktv1 ktv2 noktfoo noktarg2 + ' + ) +0:KSH_TYPESET option +>0 0 0 0 +>arg1 arg2 +>noktarg1 +>0 0 -- cgit 1.4.1 From d649bf78dc3096d6ca0c705257a928b1acce3b82 Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Sun, 27 Dec 2020 14:36:35 -0800 Subject: Fix ${(t)var} output, add comparative test cases --- Src/subst.c | 3 ++- Test/E01options.ztst | 15 +++++++++++++++ Test/E03posix.ztst | 14 ++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) (limited to 'Test/E03posix.ztst') diff --git a/Src/subst.c b/Src/subst.c index 96e0914eb..9928be0e9 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -2563,7 +2563,8 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, * Handle the (t) flag: value now becomes the type * information for the parameter. */ - if (v && v->pm && !(v->pm->node.flags & PM_UNSET)) { + if (v && v->pm && ((v->pm->node.flags & PM_DECLARED) || + !(v->pm->node.flags & PM_UNSET))) { int f = v->pm->node.flags; switch (PM_TYPE(f)) { diff --git a/Test/E01options.ztst b/Test/E01options.ztst index 415f46cd7..72749e6ab 100644 --- a/Test/E01options.ztst +++ b/Test/E01options.ztst @@ -1451,3 +1451,18 @@ F:If this test fails at the first unsetopt, refer to P01privileged.ztst. 0q:RM_STAR_SILENT *>zsh: sure you want to delete all 15 files in ${PWD:h}/options.tmp \[yn\]\? ${BEL}(|n) *>zsh: sure you want to delete (all <->|more than <->) files in / \[yn\]\? ${BEL}(|n) + + () { + local var + print ${(t)var} + } +0:(t) returns correct type +>scalar-local + + () { + readonly var + typeset -p var + } +0:readonly with typeset -p +F:compare E03posix.ztst +>typeset -r var='' diff --git a/Test/E03posix.ztst b/Test/E03posix.ztst index 5e6eddeba..c59ca4f6e 100644 --- a/Test/E03posix.ztst +++ b/Test/E03posix.ztst @@ -103,3 +103,17 @@ >arg1 arg2 >noktarg1 >0 0 + + () { + local var + print ${(t)var} + } +0:(t) returns correct type +>scalar-local + + () { + readonly var + typeset -p var + } +0:readonly with typeset -p +>typeset -g -r var -- cgit 1.4.1 From e67ccd7f1efae7696dc17f6e3e720cd994e90155 Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Sat, 10 Apr 2021 14:10:21 -0700 Subject: Add TYPESET_DOES_NOT_SET option (cf. 48469) --- Src/builtin.c | 2 +- Src/options.c | 1 + Src/zsh.h | 1 + Test/E03posix.ztst | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) (limited to 'Test/E03posix.ztst') diff --git a/Src/builtin.c b/Src/builtin.c index f0c490119..edd4cad44 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -2491,7 +2491,7 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func), return NULL; } } - if (isset(POSIXBUILTINS)) + if (isset(TYPESETDOESNOTSET)) pm->node.flags |= PM_DEFAULTED; } else { if (idigit(*pname)) diff --git a/Src/options.c b/Src/options.c index fba021e7d..766ffdfdb 100644 --- a/Src/options.c +++ b/Src/options.c @@ -257,6 +257,7 @@ static struct optname optns[] = { {{NULL, "sunkeyboardhack", 0}, SUNKEYBOARDHACK}, {{NULL, "transientrprompt", 0}, TRANSIENTRPROMPT}, {{NULL, "trapsasync", 0}, TRAPSASYNC}, +{{NULL, "typesetdoesnotset", OPT_EMULATE|OPT_BOURNE}, TYPESETDOESNOTSET}, {{NULL, "typesetsilent", OPT_EMULATE|OPT_BOURNE}, TYPESETSILENT}, {{NULL, "unset", OPT_EMULATE|OPT_BSHELL}, UNSET}, {{NULL, "verbose", 0}, VERBOSE}, diff --git a/Src/zsh.h b/Src/zsh.h index 27be1f788..12efb784f 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -2536,6 +2536,7 @@ enum { SUNKEYBOARDHACK, TRANSIENTRPROMPT, TRAPSASYNC, + TYPESETDOESNOTSET, TYPESETSILENT, UNSET, VERBOSE, diff --git a/Test/E03posix.ztst b/Test/E03posix.ztst index c59ca4f6e..a2769f3aa 100644 --- a/Test/E03posix.ztst +++ b/Test/E03posix.ztst @@ -4,7 +4,7 @@ # %prep - setopt POSIX_BUILTINS + setopt POSIX_BUILTINS TYPESET_DOES_NOT_SET %test -- cgit 1.4.1 From b3613e4895f7b059558c4ef211189b516dbf903d Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Mon, 12 Apr 2021 13:59:06 -0700 Subject: Change TYPESET_DOES_NOT_SET to TYPESET_TO_UNSET to avoid double-negative --- Doc/Zsh/builtins.yo | 6 +++++- Doc/Zsh/options.yo | 10 ++++++++++ Src/builtin.c | 2 +- Src/options.c | 2 +- Src/zsh.h | 2 +- Test/D06subscript.ztst | 5 +++++ Test/E03posix.ztst | 45 ++++++++++++++++++++++++++++++++++++++++++++- 7 files changed, 67 insertions(+), 5 deletions(-) (limited to 'Test/E03posix.ztst') diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index a7afe42cf..61dc6986f 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -1872,7 +1872,11 @@ ifnzman(noderef(Local Parameters))\ retain their special attributes when made local. For each var(name)tt(=)var(value) assignment, the parameter -var(name) is set to var(value). +var(name) is set to var(value). If the assignment is omitted and var(name) +does em(not) refer to an existing parameter, a new parameter is intialized +to empty string, zero, or empty array (as appropriate), em(unless) the +shell option tt(TYPESET_TO_UNSET) is set. When that option is set, +the parameter attributes are recorded but the parameter remains unset. If the shell option tt(TYPESET_SILENT) is not set, for each remaining var(name) that refers to a parameter that is already set, the name and diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index b3bf11f5c..6a1f82b07 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -1926,6 +1926,16 @@ If the option is set, they will only be shown when parameters are selected with the `tt(-m)' option. The option `tt(-p)' is available whether or not the option is set. ) +pindex(TYPESET_TO_UNSET) +pindex(NO_TYPESET_TO_UNSET) +pindex(TYPESETTOUNSET) +pindex(NOTYPESETTOUNSET) +item(tt(TYPESET_TO_UNSET) )( +When declaring a new parameter with any of the `tt(typeset)' family of +related commands, the parameter remains unset unless and until a +value is explicity assigned to it, either in the `tt(typeset)' command +itself or as a later assignment statement. +) pindex(VERBOSE) pindex(NO_VERBOSE) pindex(NOVERBOSE) diff --git a/Src/builtin.c b/Src/builtin.c index edd4cad44..6d119f7a5 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -2491,7 +2491,7 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func), return NULL; } } - if (isset(TYPESETDOESNOTSET)) + if (isset(TYPESETTOUNSET)) pm->node.flags |= PM_DEFAULTED; } else { if (idigit(*pname)) diff --git a/Src/options.c b/Src/options.c index 766ffdfdb..23935ae18 100644 --- a/Src/options.c +++ b/Src/options.c @@ -257,8 +257,8 @@ static struct optname optns[] = { {{NULL, "sunkeyboardhack", 0}, SUNKEYBOARDHACK}, {{NULL, "transientrprompt", 0}, TRANSIENTRPROMPT}, {{NULL, "trapsasync", 0}, TRAPSASYNC}, -{{NULL, "typesetdoesnotset", OPT_EMULATE|OPT_BOURNE}, TYPESETDOESNOTSET}, {{NULL, "typesetsilent", OPT_EMULATE|OPT_BOURNE}, TYPESETSILENT}, +{{NULL, "typesettounset", OPT_EMULATE|OPT_BOURNE}, TYPESETTOUNSET}, {{NULL, "unset", OPT_EMULATE|OPT_BSHELL}, UNSET}, {{NULL, "verbose", 0}, VERBOSE}, {{NULL, "vi", 0}, VIMODE}, diff --git a/Src/zsh.h b/Src/zsh.h index 12efb784f..490407ad0 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -2536,8 +2536,8 @@ enum { SUNKEYBOARDHACK, TRANSIENTRPROMPT, TRAPSASYNC, - TYPESETDOESNOTSET, TYPESETSILENT, + TYPESETTOUNSET, UNSET, VERBOSE, VIMODE, diff --git a/Test/D06subscript.ztst b/Test/D06subscript.ztst index c1a8d79cf..4225c543c 100644 --- a/Test/D06subscript.ztst +++ b/Test/D06subscript.ztst @@ -289,3 +289,8 @@ F:Regression test for workers/42297 >14 24 >b b >b?rbaz foob?r + + i=1,3 + [[ ${a[$i]} = ${a[i]} ]] +0f:Math evaluation of commas in array subscripts +F:In math, (($i)) should be the same as ((i)). diff --git a/Test/E03posix.ztst b/Test/E03posix.ztst index a2769f3aa..fb394986d 100644 --- a/Test/E03posix.ztst +++ b/Test/E03posix.ztst @@ -4,7 +4,7 @@ # %prep - setopt POSIX_BUILTINS TYPESET_DOES_NOT_SET + setopt POSIX_BUILTINS TYPESET_TO_UNSET %test @@ -117,3 +117,46 @@ } 0:readonly with typeset -p >typeset -g -r var + +# Tests expected to fail + + echo - +0f:A single "-" for echo does not end the arguments +F:POSIX requires a solitary "-" to be a plain argument +>- + + ARGV0=sh $ZTST_testdir/../Src/zsh -c 'foreach() { true; }' +-f:"foreach" is not a reserved word + + ARGV0=sh $ZTST_testdir/../Src/zsh -c 'end() { true; } +-f:"end" is not a reserved word + + a='a:b:' ARGV0=sh $ZTST_testdir/../Src/zsh -c 'IFS=:; printf "<%s>\n" $a' +0f:IFS is a separator, not a delimiter +> +> + + a=$'\ra\r\rb' ARGV0=sh $ZTST_testdir/../Src/zsh -c 'IFS=:; printf "<%s>\n" $a' +0f:All whitespace characters are "IFS whitespace" +F:isspace('\r') is true so \r should behave like space, \t, \n +F:This may also need to apply to multibyte whitespace +> +> + + ARGV0=sh $ZTST_testdir/../Src/zsh -c 'IFS=2; printf "<%s>\n" $((11*11))' +0f:IFS applies to math results (numbers treated as strings) +><1> +><1> + + ARGV0=sh $ZTST_testdir/../Src/zsh -c 'inf=42; echo $((inf))' +0f:The math constant Inf is case-sensitive, with capital I +>42 + + ARGV0=sh $ZTST_testdir/../Src/zsh -c 'EUID=10; echo "$EUID"' +-f:EUID is not a special variable +>10 + + ARGV0=sh $ZTST_testdir/../Src/zsh -c "printf '<%10s>\n' St$'\M-C\M-)'phane" +0f:Width of %s is computed in bytes not characters +F:This is considered a bugfix in zsh +>< Stéphane> -- cgit 1.4.1 From 6c9a1f5e80d018e28cf6760cda7ffe18cc5a2df8 Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Mon, 12 Apr 2021 15:43:23 -0700 Subject: Update descriptive test for POSIX $((inf)) failure --- Test/E03posix.ztst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Test/E03posix.ztst') diff --git a/Test/E03posix.ztst b/Test/E03posix.ztst index fb394986d..7db4c0c84 100644 --- a/Test/E03posix.ztst +++ b/Test/E03posix.ztst @@ -149,7 +149,8 @@ F:This may also need to apply to multibyte whitespace ><1> ARGV0=sh $ZTST_testdir/../Src/zsh -c 'inf=42; echo $((inf))' -0f:The math constant Inf is case-sensitive, with capital I +0f:All identifiers are variable references in POSIX arithmetic +F:POSIX has neither math functions nor floating point >42 ARGV0=sh $ZTST_testdir/../Src/zsh -c 'EUID=10; echo "$EUID"' -- cgit 1.4.1