Source-Changes-HG archive

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

[src/trunk]: src/tests/bin/sh NFC: Added some comments (about other comments)



details:   https://anonhg.NetBSD.org/src/rev/0de2769417fd
branches:  trunk
changeset: 824962:0de2769417fd
user:      kre <kre%NetBSD.org@localhost>
date:      Sat Jun 24 11:06:17 2017 +0000

description:
NFC:   Added some comments (about other comments)

We currently parse var expansions like "${x-"a b c"}" incorrectly
according to POSIX (and ancient tradition) though in a way that is
generally unexpcted (there are 2 quoted strings there, according
to the standard, "${x-" and "}" and 'a b c' is unquoted.)  This has
never been fixed in our sh, as like in many other shells, it is just
a little unbelievable, most people expect that inside the {} is a
whole new ballpark, and everything starts again, and it does in cases
like "${x%"a b c"}" (the newer matching operators.)  There have been
comments in this test explaining how the test is actually testing for
incorrect behaviour for a while now.

But I have since learned of POSIX bug #221 (2010), the resolution of which is
to make the problem case unspecified.  This will not actually become part
of posix until the next major version (POSIX 8) whenever that appears (still
years away I expect) - but at least we now can feel happier about the
way our code works and not worry quite so much about testing that incorrect
code keeps working incorrectly....

diffstat:

 tests/bin/sh/t_fsplit.sh |  13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diffs (48 lines):

diff -r 44a5e2c0b538 -r 0de2769417fd tests/bin/sh/t_fsplit.sh
--- a/tests/bin/sh/t_fsplit.sh  Sat Jun 24 10:25:23 2017 +0000
+++ b/tests/bin/sh/t_fsplit.sh  Sat Jun 24 11:06:17 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_fsplit.sh,v 1.6 2017/06/03 15:15:49 kre Exp $
+# $NetBSD: t_fsplit.sh,v 1.7 2017/06/24 11:06:17 kre Exp $
 #
 # Copyright (c) 2007-2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -145,6 +145,13 @@
        # 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'
 
+       # That and the "should be" below are correct as of POSIX 7 TC2
+       # But this is going to change to "unspecified" in POSIX 8
+       # (resolution of bug 221)  so instead of being incorrect (as now)
+       # the NetBSD shell will simply be implementing is version
+       # of unspecified behaviour.  Just beware that shells differ,
+       # a shell that fails this test is not incorrect because of it.
+
        # 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'
@@ -212,6 +219,8 @@
        check 'x=BOGUS; for i in ${x+"a ${x+b c}" d};   do echo "z${i}z"; done'\
                'za b cz zdz'
 
+       # see the (extended) comment in the default_val test.  This will be
+       # unspecified, hence we are OK (will be) but expect differences.
        # also incorrect:        uuuu qqqqqq uuu q uuu
        check 'x=BOGUS; for i in ${x+"a ${x+"b c"}" d}; do echo "z${i}z"; done'\
                'za b cz zdz'
@@ -241,6 +250,7 @@
                'zaqbqcz zdz'
 
        # this is another almost certainly incorrect expectation
+       # (but again, see comment in default_val test - becoming unspecified.)
        #                        uu qqqqqq uuu q uu     (quoted/unquoted)
        check 'IFS=q; for i in ${x-"aq${x-"bqc"}"qd}; do echo "z${i}z"; done' \
                'zaqbqcz zdz'
@@ -262,6 +272,7 @@
        check 'set "${x-a b c}";   echo $#' 1
 
        # this is another almost certainly incorrect expectation
+       # (but again, see comment in default_val test - becoming unspecified.)
        #           qqqq uuu qqq        (quoted/unquoted)  $1 is a $# is 2
        check 'set "${x-"a b" c}"; echo $1' 'a b c'
 



Home | Main Index | Thread Index | Old Index