Skip to content

Commit 3f8add4

Browse files
committed
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.
1 parent f792c4b commit 3f8add4

File tree

6 files changed

+50
-87
lines changed

6 files changed

+50
-87
lines changed

src/cmd/ksh93/data/variables.c

-3
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@ const struct shtable2 shtab_variables[] =
105105
".sh.pid", NV_INTEGER|NV_NOFREE, (char*)0,
106106
".sh.tilde", 0, (char*)0,
107107
"SHLVL", NV_INTEGER|NV_NOFREE|NV_EXPORT, (char*)0,
108-
#if SHOPT_MULTIBYTE
109-
"CSWIDTH", 0, (char*)0,
110-
#endif /* SHOPT_MULTIBYTE */
111108
"", 0, (char*)0
112109
};
113110

src/cmd/ksh93/tests/case.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ got=$(eval 'case x in (foo);; (if);; esac' 2>&1) || err_exit "'(' + 'if' as nth
9696
# ======
9797
# Verify an invalid character class name is handled without a SIGSEGV or similar failure
9898
# https://github.com/att/ast/issues/1409
99-
got="$($SHELL -c 'case x in [x[:bogus:]]) echo x ;; esac')"
100-
[[ -z $got ]] || err_exit "invalid char class name (got $(printf %q "$got"))"
99+
got=$(set +x; { "$SHELL" -c 'case x in [x[:bogus:]]) echo x ;; esac'; } 2>&1)
100+
((!(e = $?))) && [[ -z $got ]] || err_exit 'use of invalid character class name' \
101+
"(got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"), $(printf %q "$got"))"
101102

102103
# ======
103104
exit $((Errors<125?Errors:125))

src/cmd/ksh93/tests/coprocess.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
. "${SHTESTS_COMMON:-${0%/*}/_common}"
2424

2525
if [[ -d /cygdrive ]]
26-
then err_exit 'Cygwin detected - coprocess tests disabled - enable at the risk of wedging your system'
27-
exit $((Errors))
26+
then warning 'Cygwin detected - coprocess tests disabled - enable at the risk of wedging your system'
27+
exit 0
2828
fi
2929

3030
bintrue=$(whence -p true)

src/cmd/ksh93/tests/grep.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ and some lines contain bar only.
8585
However, many lines contain both foo and also bar.
8686
A line containing foobar should also be counted.
8787
There should be six lines with foo and bar.
88-
There are only two line with out foo but with bar.
88+
There are only two lines without foo but with bar.
8989
!
9090

91-
if (( $(grep -c 'foo*bar' $tmp/grep ) != 6))
92-
then err_exit
91+
got=$(grep -c 'foo*bar' $tmp/grep 2>&1)
92+
if [[ $got != 6 ]]
93+
then err_exit "shell version of grep fails (expected 6, got $(printf %q "$got"))"
9394
fi
9495

9596
exit $((Errors<125?Errors:125))

src/cmd/ksh93/tests/subshell.sh

+18-6
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,22 @@ z.bar[1]=(x=12 y=5)
6565
eval val="$z"
6666
(
6767
z.foo[three]=good
68-
[[ ${z.foo[three]} == good ]] || err_exit 'associative array assignment in subshell not working'
69-
)
68+
[[ ${z.foo[three]} == good ]]
69+
) || err_exit 'associative array assignment in subshell not working'
7070
[[ $z == "$val" ]] || err_exit 'compound variable changes after associative array assignment'
7171
eval val="$z"
7272
(
7373
z.foo[two]=ok
74-
[[ ${z.foo[two]} == ok ]] || err_exit 'associative array assignment to compound variable in subshell not working'
74+
[[ ${z.foo[two]} == ok ]] || exit 101
7575
z.bar[1]=yes
76-
[[ ${z.bar[1]} == yes ]] || err_exit 'indexed array assignment to compound variable in subshell not working'
76+
[[ ${z.bar[1]} == yes ]] || exit 102
7777
)
78+
case $? in
79+
0) ;;
80+
101) err_exit 'associative array assignment to compound variable in subshell not working' ;;
81+
102) err_exit 'indexed array assignment to compound variable in subshell not working' ;;
82+
*) err_exit 'assignment to compound variable in subshell fails' ;;
83+
esac
7884
[[ $z == "$val" ]] || err_exit 'compound variable changes after associative array assignment'
7985

8086
x=(
@@ -84,10 +90,16 @@ x=(
8490
eval val="$x"
8591
(
8692
unset x.foo
87-
[[ ${x.foo.qqq} ]] && err_exit 'x.foo.qqq should be unset'
93+
[[ ${x.foo.qqq} ]] && exit 101
8894
x.foo=good
89-
[[ ${x.foo} == good ]] || err_exit 'x.foo should be good'
95+
[[ ${x.foo} == good ]] || exit 102
9096
)
97+
case $? in
98+
0) ;;
99+
101) err_exit 'x.foo.qqq should be unset' ;;
100+
102) err_exit 'x.foo should be good' ;;
101+
*) err_exit "x.foo fails" ;;
102+
esac
91103
[[ $x == "$val" ]] || err_exit 'compound variable changes after unset leaves'
92104
unset l
93105
(

src/cmd/ksh93/tests/variables.sh

+23-71
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,10 @@ chmod +x $tmp/script
619619
[[ $(fun .sh.subshell) == 2 ]] || err_exit ".sh.subshell not working for functions in subshells"
620620
(( .sh.subshell == 1 )) || err_exit ".sh.subshell not working in a subshell"
621621
)
622-
TIMEFORMAT='this is a test'
623-
[[ $(set +x; { { time :;} 2>&1;}) == "$TIMEFORMAT" ]] || err_exit 'TIMEFORMAT not working'
622+
(
623+
TIMEFORMAT='this is a test'
624+
[[ $(set +x; { { time :;} 2>&1;}) == "$TIMEFORMAT" ]]
625+
) || err_exit 'TIMEFORMAT not working'
624626
alias _test_alias=true
625627
: ${.sh.version}
626628
[[ $(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
965967
# ======
966968
# Check unset, attribute and cleanup/restore behavior of special variables.
967969

968-
# Keep the list in sync (minus ".sh") with shtab_variables[] in src/cmd/ksh93/data/variables.c
969-
set -- \
970-
"PATH" \
971-
"PS1" \
972-
"PS2" \
973-
"IFS" \
974-
"PWD" \
975-
"HOME" \
976-
"MAIL" \
977-
"REPLY" \
978-
"SHELL" \
979-
"EDITOR" \
980-
"MAILCHECK" \
981-
"RANDOM" \
982-
"ENV" \
983-
"HISTFILE" \
984-
"HISTSIZE" \
985-
"HISTEDIT" \
986-
"HISTCMD" \
987-
"FCEDIT" \
988-
"CDPATH" \
989-
"MAILPATH" \
990-
"PS3" \
991-
"OLDPWD" \
992-
"VISUAL" \
993-
"COLUMNS" \
994-
"LINES" \
995-
"PPID" \
996-
"_" \
997-
"TMOUT" \
998-
"SECONDS" \
999-
"LINENO" \
1000-
"OPTARG" \
1001-
"OPTIND" \
1002-
"PS4" \
1003-
"FPATH" \
1004-
"LANG" \
1005-
"LC_ALL" \
1006-
"LC_COLLATE" \
1007-
"LC_CTYPE" \
1008-
"LC_MESSAGES" \
1009-
"LC_NUMERIC" \
1010-
"LC_TIME" \
1011-
"FIGNORE" \
1012-
"KSH_VERSION" \
1013-
"JOBMAX" \
1014-
".sh.edchar" \
1015-
".sh.edcol" \
1016-
".sh.edtext" \
1017-
".sh.edmode" \
1018-
".sh.name" \
1019-
".sh.subscript" \
1020-
".sh.value" \
1021-
".sh.version" \
1022-
".sh.dollar" \
1023-
".sh.match" \
1024-
".sh.command" \
1025-
".sh.file" \
1026-
".sh.fun" \
1027-
".sh.lineno" \
1028-
".sh.subshell" \
1029-
".sh.level" \
1030-
".sh.stats" \
1031-
".sh.math" \
1032-
".sh.pool" \
1033-
".sh.pid" \
1034-
".sh.tilde" \
1035-
"SHLVL" \
1036-
"CSWIDTH"
970+
# ... to avoid forgetting to keep this script synched with shtab_variables[], read from the source
971+
set -- $(
972+
srcdir=${SHTESTS_COMMON%/tests/*}
973+
redirect < $srcdir/data/variables.c || exit
974+
# skip lines until finding shtab_variables struct
975+
while read -r line || exit
976+
do [[ $line == *" shtab_variables[] =" ]] && break
977+
done
978+
read -r line
979+
[[ $line == '{' ]] || exit
980+
# read variable names until '};'
981+
IFS=\"
982+
while read -r first varname junk
983+
do [[ $first == '};' ]] && exit
984+
[[ -z $junk ]] && continue
985+
[[ -n $varname && $varname != '.sh' ]] && print -r -- "$varname"
986+
done
987+
)
988+
(($# >= 66)) || err_exit "could not read shtab_variables[]; adjust test script ($# items read)"
1037989

1038990
# ... unset
1039991
$SHELL -c '

0 commit comments

Comments
 (0)