1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-13 19:52:20 +00:00

Various cleanups, mostly in regression tests

src/cmd/ksh93/data/variables.sh: shtab_variables[]:
- Remove unused "CSWIDTH" entry. All use of it (including the
  matching CSWIDTHNOD macro) was removed in version 2003-04-22.

src/cmd/ksh93/tests/variables.sh:
- For the tests on the shtab_variables[] variables, read the
  variable names straight from variables.c instead of synching
  the list in the test script, which would surely be forgotten.

src/cmd/ksh93/tests/*.sh:
- Fix a number of mistaken tries to count errors from a subshell.
- Fix miscellaneous minor breakage and typos.
This commit is contained in:
Martijn Dekker 2022-01-21 16:34:11 +00:00
parent 8afc4756e8
commit cda661d34c
6 changed files with 50 additions and 87 deletions

View file

@ -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
};

View file

@ -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))

View file

@ -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)

View file

@ -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))

View file

@ -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
(

View file

@ -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 '