Adjust the tilde expansion test to deal with (very) recent changes
to what the shell produces for tilde expansions, when the expansion of the tilde prefix ends with '/' and the character immediately following is another '/' - previously /bin/sh (and most other shells, but not all) retained both slashes, and this test expected that behaviour. No longer, now only one of the two will appear. Adjust the expected test results accordingly, and add an extra loop iteration to make sure this is thoroughly tested (one more tilde expansion value). Also, add two new test cases that test for the new (explicit - though it was always stated this way, but not as explicitly) that if HOME is an empty string (not unset - that remains an unspecified case, as it was) then the expansion of ~ must generate "", and not nothing. The current test was unable to distinguish those two, since it simply looked for characters in the output, so add a new test cases explicitly to test for this particular case. This also means (also previously in the standard, but not as explicitly) that shells are not permitted to decide "The ~ expansion produces an empty string, that is weird, let's generate something else instead" which some shells were doing.
This commit is contained in:
parent
726d188a97
commit
23edd9e279
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: t_expand.sh,v 1.22 2019/05/04 02:52:22 kre Exp $
|
||||
# $NetBSD: t_expand.sh,v 1.23 2023/03/06 05:54:54 kre Exp $
|
||||
#
|
||||
# Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
|
||||
# All rights reserved.
|
||||
|
@ -432,7 +432,7 @@ tilde_head() {
|
|||
atf_set descr "Checks that the ~ expansions work"
|
||||
}
|
||||
tilde_body() {
|
||||
for HOME in '' / /home/foo \
|
||||
for HOME in '' / /home/foo /home/foo/ \
|
||||
/a/very/long/home/directory/path/that/might/push/the/tilde/expansion/code/beyond/what/it/would/normally/ever/see/on/any/sane/system/and/perhaps/expose/some/bugs
|
||||
do
|
||||
export HOME
|
||||
|
@ -440,22 +440,22 @@ tilde_body() {
|
|||
atf_check -s exit:0 -e empty \
|
||||
-o inline:'HOME\t'"${HOME}"'
|
||||
~\t'"${HOME}"'
|
||||
~/foobar\t'"${HOME}"'/foobar
|
||||
~/foobar\t'"${HOME%/}"'/foobar
|
||||
"$V"\t'"${HOME}"'
|
||||
"$X"\t~
|
||||
"$Y"\t'"${HOME}"':'"${HOME}"'
|
||||
"$YY"\t'"${HOME}"'/foo:'"${HOME}"'/bar
|
||||
"$Z"\t'"${HOME}"'/~
|
||||
"$YY"\t'"${HOME%/}"'/foo:'"${HOME%/}"'/bar
|
||||
"$Z"\t'"${HOME%/}"'/~
|
||||
${U:-~}\t'"${HOME}"'
|
||||
$V\t'"${HOME}"'
|
||||
$X\t~
|
||||
$Y\t'"${HOME}"':'"${HOME}"'
|
||||
$YY\t'"${HOME}"'/foo:'"${HOME}"'/bar
|
||||
$Z\t'"${HOME}"'/~
|
||||
$YY\t'"${HOME%/}"'/foo:'"${HOME%/}"'/bar
|
||||
$Z\t'"${HOME%/}"'/~
|
||||
${U:=~}\t'"${HOME}"'
|
||||
${UU:=~:~}\t'"${HOME}"':'"${HOME}"'
|
||||
${UUU:=~/:~}\t'"${HOME}"'/:'"${HOME}"'
|
||||
${U4:=~/:~/}\t'"${HOME}"'/:'"${HOME}"'/\n' \
|
||||
${UUU:=~/:~}\t'"${HOME%/}"'/:'"${HOME}"'
|
||||
${U4:=~/:~/}\t'"${HOME%/}"'/:'"${HOME%/}"'/\n' \
|
||||
${TEST_SH} -s <<- \EOF
|
||||
unset -v U UU UUU U4
|
||||
V=~
|
||||
|
@ -484,6 +484,15 @@ ${U4:=~/:~/}\t'"${HOME}"'/:'"${HOME}"'/\n' \
|
|||
EOF
|
||||
done
|
||||
|
||||
# Verify that when HOME is "" expanding a bare ~
|
||||
# makes an empty word, not nothing (or anything else)
|
||||
HOME=""
|
||||
export HOME
|
||||
atf_check -s exit:0 -e empty -o inline:'1:<>\n' ${TEST_SH} -c \
|
||||
'set -- ~ ; IFS=, ; printf '"'%d:<%s>\\n'"' "$#" "$*"'
|
||||
atf_check -s exit:0 -e empty -o inline:'4:<,X,,/>\n' ${TEST_SH} -c \
|
||||
'set -- ~ X ~ ~/ ; IFS=, ; printf '"'%d:<%s>\\n'"' "$#" "$*"'
|
||||
|
||||
# Testing ~user is harder, so, perhaps later...
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue