Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/bin/sh Adjust the tilde expansion test to deal with (v...



details:   https://anonhg.NetBSD.org/src/rev/20a92576dddd
branches:  trunk
changeset: 373849:20a92576dddd
user:      kre <kre%NetBSD.org@localhost>
date:      Mon Mar 06 05:54:54 2023 +0000

description:
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.

diffstat:

 tests/bin/sh/t_expand.sh |  27 ++++++++++++++++++---------
 1 files changed, 18 insertions(+), 9 deletions(-)

diffs (64 lines):

diff -r 240b9e68de36 -r 20a92576dddd tests/bin/sh/t_expand.sh
--- a/tests/bin/sh/t_expand.sh  Mon Mar 06 05:54:34 2023 +0000
+++ b/tests/bin/sh/t_expand.sh  Mon Mar 06 05:54:54 2023 +0000
@@ -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 @@
        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 @@
                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 @@
                        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...
 }
 



Home | Main Index | Thread Index | Old Index