Source-Changes-HG archive

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

[src/trunk]: src/tests/bin/sh Add some extra sub-tests checking splitting of ...



details:   https://anonhg.NetBSD.org/src/rev/dd62cbb3d407
branches:  trunk
changeset: 824372:dd62cbb3d407
user:      kre <kre%NetBSD.org@localhost>
date:      Sat Jun 03 10:27:05 2017 +0000

description:
Add some extra sub-tests checking splitting of ${#var} - just for my
piece of mind (to verify I was not breaking anything here.)

Also added some commentary better explaining why one of the tests of splitting
quoted variable expansions is almost certainly incorrect (both the tests,
and what sh does) ... though bash does the same as us, so all is not lost!

diffstat:

 tests/bin/sh/t_fsplit.sh |  22 +++++++++++++++-------
 1 files changed, 15 insertions(+), 7 deletions(-)

diffs (51 lines):

diff -r f8f4598d673a -r dd62cbb3d407 tests/bin/sh/t_fsplit.sh
--- a/tests/bin/sh/t_fsplit.sh  Sat Jun 03 09:00:35 2017 +0000
+++ b/tests/bin/sh/t_fsplit.sh  Sat Jun 03 10:27:05 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_fsplit.sh,v 1.4 2016/03/27 14:50:01 christos Exp $
+# $NetBSD: t_fsplit.sh,v 1.5 2017/06/03 10:27:05 kre Exp $
 #
 # Copyright (c) 2007-2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -137,11 +137,13 @@
        check 'for i in ${x-a ${x-b c} d};     do echo "z${i}z"; done' \
                'zaz zbz zcz zdz'
 
-       # I am not sure these two are correct, the rules on quoting word
-       # in ${var-word} are peculiar, and hard to fathom...
-       # They are what the NetBSD shell does, and bash, not the freebsd shell
-       # (as of Mar 1, 2016)
+       # I am not sure the first of these two is correct, the rules on
+       # quoting word in ${var-word} are peculiar, and hard to fathom...
+       # It is what the NetBSD shell does, and bash, not the freebsd shell
+       # and not ksh93 (as of Mar 1, 2016, and still in June 2017)
+       # The likely correct interp of the next one is 'za bz zcz zdz'
 
+       # should be:    uuuu qqqqqq uuu q uuu   (unquoted/quoted) no nesting.
        check 'for i in ${x-"a ${x-"b c"}" d}; do echo "z${i}z"; done' \
                'za b cz zdz'
        check 'for i in ${x-a ${x-"b c"} d};   do echo "z${i}z"; done' \
@@ -337,6 +339,7 @@
        long=12345678123456781234567812345678
        long=$long$long$long$long
        export long
+       unset x
 
        # first test that the test method works...
        check 'set -u; : ${long}; echo ${#long}' '128'
@@ -344,8 +347,13 @@
        # Check that we apply IFS to ${#var}
        check 'echo ${#long}; IFS=2; echo ${#long}; set 1 ${#long};echo $#' \
                '128 1 8 3'
-       check 'IFS=2; set ${x-${#long}};   IFS=" "; echo $* $#'   '1 8 2'
-       check 'IFS=2; set ${x-"${#long}"}; IFS=" "; echo $* $#'   '128 1'
+       check 'IFS=2; set ${x-${#long}};   IFS=" "; echo $* $#'     '1 8 2'
+       check 'IFS=2; set ${x-"${#long}"}; IFS=" "; echo $* $#'     '128 1'
+       check 'IFS=2; set "${x-${#long}}"; IFS=" "; echo $* $#'     '128 1'
+       check 'IFS=2; set ${x-${#long}};   :      ; echo $* $#'     '1 8 '
+       check 'IFS=2; set ${x-${#long}};   :      ; echo $* "$#"'   '1 8 2'
+       check 'IFS=2; set ${x-${#long}};   :      ; echo "$*" "$#"' '128 2'
+       check 'IFS=2; set ${x-${#long}};   :      ; echo "$@" "$#"' '1 8 2'
 }
 
 atf_init_test_cases() {



Home | Main Index | Thread Index | Old Index