diff --git a/src/cmd/ksh93/data/variables.c b/src/cmd/ksh93/data/variables.c index d1e198d97bd3..2eb6cedb0d7c 100644 --- a/src/cmd/ksh93/data/variables.c +++ b/src/cmd/ksh93/data/variables.c @@ -105,9 +105,6 @@ const struct shtable2 shtab_variables[] = ".sh.pid", NV_INTEGER|NV_NOFREE, (char*)0, ".sh.tilde", 0, (char*)0, "SHLVL", NV_INTEGER|NV_NOFREE|NV_EXPORT, (char*)0, -#if SHOPT_MULTIBYTE - "CSWIDTH", 0, (char*)0, -#endif /* SHOPT_MULTIBYTE */ "", 0, (char*)0 }; diff --git a/src/cmd/ksh93/tests/case.sh b/src/cmd/ksh93/tests/case.sh index c6830499698f..8dda00dee070 100755 --- a/src/cmd/ksh93/tests/case.sh +++ b/src/cmd/ksh93/tests/case.sh @@ -96,8 +96,9 @@ got=$(eval 'case x in (foo);; (if);; esac' 2>&1) || err_exit "'(' + 'if' as nth # ====== # Verify an invalid character class name is handled without a SIGSEGV or similar failure # https://github.com/att/ast/issues/1409 -got="$($SHELL -c 'case x in [x[:bogus:]]) echo x ;; esac')" -[[ -z $got ]] || err_exit "invalid char class name (got $(printf %q "$got"))" +got=$(set +x; { "$SHELL" -c 'case x in [x[:bogus:]]) echo x ;; esac'; } 2>&1) +((!(e = $?))) && [[ -z $got ]] || err_exit 'use of invalid character class name' \ + "(got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"), $(printf %q "$got"))" # ====== exit $((Errors<125?Errors:125)) diff --git a/src/cmd/ksh93/tests/coprocess.sh b/src/cmd/ksh93/tests/coprocess.sh index 8b67ec8fb1e1..ad7bbf5aa2d0 100755 --- a/src/cmd/ksh93/tests/coprocess.sh +++ b/src/cmd/ksh93/tests/coprocess.sh @@ -23,8 +23,8 @@ . "${SHTESTS_COMMON:-${0%/*}/_common}" if [[ -d /cygdrive ]] -then err_exit 'Cygwin detected - coprocess tests disabled - enable at the risk of wedging your system' - exit $((Errors)) +then warning 'Cygwin detected - coprocess tests disabled - enable at the risk of wedging your system' + exit 0 fi bintrue=$(whence -p true) diff --git a/src/cmd/ksh93/tests/grep.sh b/src/cmd/ksh93/tests/grep.sh index 200e87ffd5ad..45512d3b2b13 100755 --- a/src/cmd/ksh93/tests/grep.sh +++ b/src/cmd/ksh93/tests/grep.sh @@ -85,11 +85,12 @@ and some lines contain bar only. However, many lines contain both foo and also bar. A line containing foobar should also be counted. There should be six lines with foo and bar. -There are only two line with out foo but with bar. +There are only two lines without foo but with bar. ! -if (( $(grep -c 'foo*bar' $tmp/grep ) != 6)) -then err_exit +got=$(grep -c 'foo*bar' $tmp/grep 2>&1) +if [[ $got != 6 ]] +then err_exit "shell version of grep fails (expected 6, got $(printf %q "$got"))" fi exit $((Errors<125?Errors:125)) diff --git a/src/cmd/ksh93/tests/subshell.sh b/src/cmd/ksh93/tests/subshell.sh index a00440ec6006..1c2d64e956cc 100755 --- a/src/cmd/ksh93/tests/subshell.sh +++ b/src/cmd/ksh93/tests/subshell.sh @@ -65,16 +65,22 @@ z.bar[1]=(x=12 y=5) eval val="$z" ( z.foo[three]=good - [[ ${z.foo[three]} == good ]] || err_exit 'associative array assignment in subshell not working' -) + [[ ${z.foo[three]} == good ]] +) || err_exit 'associative array assignment in subshell not working' [[ $z == "$val" ]] || err_exit 'compound variable changes after associative array assignment' eval val="$z" ( z.foo[two]=ok - [[ ${z.foo[two]} == ok ]] || err_exit 'associative array assignment to compound variable in subshell not working' + [[ ${z.foo[two]} == ok ]] || exit 101 z.bar[1]=yes - [[ ${z.bar[1]} == yes ]] || err_exit 'indexed array assignment to compound variable in subshell not working' + [[ ${z.bar[1]} == yes ]] || exit 102 ) +case $? in +0) ;; +101) err_exit 'associative array assignment to compound variable in subshell not working' ;; +102) err_exit 'indexed array assignment to compound variable in subshell not working' ;; +*) err_exit 'assignment to compound variable in subshell fails' ;; +esac [[ $z == "$val" ]] || err_exit 'compound variable changes after associative array assignment' x=( @@ -84,10 +90,16 @@ x=( eval val="$x" ( unset x.foo - [[ ${x.foo.qqq} ]] && err_exit 'x.foo.qqq should be unset' + [[ ${x.foo.qqq} ]] && exit 101 x.foo=good - [[ ${x.foo} == good ]] || err_exit 'x.foo should be good' + [[ ${x.foo} == good ]] || exit 102 ) +case $? in +0) ;; +101) err_exit 'x.foo.qqq should be unset' ;; +102) err_exit 'x.foo should be good' ;; +*) err_exit "x.foo fails" ;; +esac [[ $x == "$val" ]] || err_exit 'compound variable changes after unset leaves' unset l ( diff --git a/src/cmd/ksh93/tests/variables.sh b/src/cmd/ksh93/tests/variables.sh index 40b0a1b9e69b..62c25606741b 100755 --- a/src/cmd/ksh93/tests/variables.sh +++ b/src/cmd/ksh93/tests/variables.sh @@ -619,8 +619,10 @@ chmod +x $tmp/script [[ $(fun .sh.subshell) == 2 ]] || err_exit ".sh.subshell not working for functions in subshells" (( .sh.subshell == 1 )) || err_exit ".sh.subshell not working in a subshell" ) -TIMEFORMAT='this is a test' -[[ $(set +x; { { time :;} 2>&1;}) == "$TIMEFORMAT" ]] || err_exit 'TIMEFORMAT not working' +( + TIMEFORMAT='this is a test' + [[ $(set +x; { { time :;} 2>&1;}) == "$TIMEFORMAT" ]] +) || err_exit 'TIMEFORMAT not working' alias _test_alias=true : ${.sh.version} [[ $(alias _test_alias) == *.sh.* ]] && err_exit '.sh. prefixed to alias name' @@ -965,75 +967,25 @@ actual=$(env SHLVL="2#11+x[\$(env echo Exploited vuln CVE-2019-14868 >&2)0]" "$S # ====== # Check unset, attribute and cleanup/restore behavior of special variables. -# Keep the list in sync (minus ".sh") with shtab_variables[] in src/cmd/ksh93/data/variables.c -set -- \ - "PATH" \ - "PS1" \ - "PS2" \ - "IFS" \ - "PWD" \ - "HOME" \ - "MAIL" \ - "REPLY" \ - "SHELL" \ - "EDITOR" \ - "MAILCHECK" \ - "RANDOM" \ - "ENV" \ - "HISTFILE" \ - "HISTSIZE" \ - "HISTEDIT" \ - "HISTCMD" \ - "FCEDIT" \ - "CDPATH" \ - "MAILPATH" \ - "PS3" \ - "OLDPWD" \ - "VISUAL" \ - "COLUMNS" \ - "LINES" \ - "PPID" \ - "_" \ - "TMOUT" \ - "SECONDS" \ - "LINENO" \ - "OPTARG" \ - "OPTIND" \ - "PS4" \ - "FPATH" \ - "LANG" \ - "LC_ALL" \ - "LC_COLLATE" \ - "LC_CTYPE" \ - "LC_MESSAGES" \ - "LC_NUMERIC" \ - "LC_TIME" \ - "FIGNORE" \ - "KSH_VERSION" \ - "JOBMAX" \ - ".sh.edchar" \ - ".sh.edcol" \ - ".sh.edtext" \ - ".sh.edmode" \ - ".sh.name" \ - ".sh.subscript" \ - ".sh.value" \ - ".sh.version" \ - ".sh.dollar" \ - ".sh.match" \ - ".sh.command" \ - ".sh.file" \ - ".sh.fun" \ - ".sh.lineno" \ - ".sh.subshell" \ - ".sh.level" \ - ".sh.stats" \ - ".sh.math" \ - ".sh.pool" \ - ".sh.pid" \ - ".sh.tilde" \ - "SHLVL" \ - "CSWIDTH" +# ... to avoid forgetting to keep this script synched with shtab_variables[], read from the source +set -- $( + srcdir=${SHTESTS_COMMON%/tests/*} + redirect < $srcdir/data/variables.c || exit + # skip lines until finding shtab_variables struct + while read -r line || exit + do [[ $line == *" shtab_variables[] =" ]] && break + done + read -r line + [[ $line == '{' ]] || exit + # read variable names until '};' + IFS=\" + while read -r first varname junk + do [[ $first == '};' ]] && exit + [[ -z $junk ]] && continue + [[ -n $varname && $varname != '.sh' ]] && print -r -- "$varname" + done +) +(($# >= 66)) || err_exit "could not read shtab_variables[]; adjust test script ($# items read)" # ... unset $SHELL -c '