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 new test case in to check (coming) bug fix ...



details:   https://anonhg.NetBSD.org/src/rev/c2615f07c897
branches:  trunk
changeset: 352047:c2615f07c897
user:      kre <kre%NetBSD.org@localhost>
date:      Sun Mar 12 00:39:47 2017 +0000

description:
Add new test case in to check (coming) bug fix for newly discovered
ash based shell bug
        echo ${unset_var##$(echo a)}$(echo b)
should say "b" but instead says "a" ... the first "echo a" is not
evaluated because it cannot possibly match an unset variable, but is
not removed from the list of command substitutions, when the shell
needs to execute the 2nd cmdsub, "echo b" should be at the head of
the list, but isn't, "echo a" is still there...

This test should fail (for now) - should show 4 of 40 subtests failing.
It isn't marked as atf_expect_fail as the fix for this will be coming
later today (I will just wait at least 1 b5 build cycle so the failure
can be observed).

Detecting the bug, and the fix, are from FreeBSD.

diffstat:

 tests/bin/sh/t_expand.sh |  62 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 60 insertions(+), 2 deletions(-)

diffs (88 lines):

diff -r c16f49bb3033 -r c2615f07c897 tests/bin/sh/t_expand.sh
--- a/tests/bin/sh/t_expand.sh  Sat Mar 11 23:59:02 2017 +0000
+++ b/tests/bin/sh/t_expand.sh  Sun Mar 12 00:39:47 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_expand.sh,v 1.8 2016/04/29 18:29:17 christos Exp $
+# $NetBSD: t_expand.sh,v 1.9 2017/03/12 00:39:47 kre Exp $
 #
 # Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -319,7 +319,7 @@
        echo >&2 " - - - - - - - - - - - - - - - - -"
        echo >&2 "${TEST_FAILURES}"
        atf_fail \
- "Test ${TEST_ID}: $TEST_FAIL_COUNT subtests (of $TEST_NUM) failed - see stderr"
+ "Test ${TEST_ID}: $TEST_FAIL_COUNT (of $TEST_NUM) subtests failed - see stderr"
 }
 
 atf_test_case shell_params
@@ -366,6 +366,63 @@
        results
 }
 
+atf_test_case var_with_embedded_cmdsub
+var_with_embedded_cmdsub_head() {
+       atf_set "descr" "Test expansion of vars with embedded cmdsub"
+}
+var_with_embedded_cmdsub_body() {
+
+       reset var_with_embedded_cmdsub
+
+       check 'unset x; echo ${x-$(echo a)}$(echo b)'  'ab' 0   #1
+       check 'unset x; echo ${x:-$(echo a)}$(echo b)' 'ab' 0   #2
+       check 'x=""; echo ${x-$(echo a)}$(echo b)'     'b'  0   #3
+       check 'x=""; echo ${x:-$(echo a)}$(echo b)'    'ab' 0   #4
+       check 'x=c; echo ${x-$(echo a)}$(echo b)'      'cb' 0   #5
+       check 'x=c; echo ${x:-$(echo a)}$(echo b)'     'cb' 0   #6
+
+       check 'unset x; echo ${x+$(echo a)}$(echo b)'  'b'  0   #7
+       check 'unset x; echo ${x:+$(echo a)}$(echo b)' 'b'  0   #8
+       check 'x=""; echo ${x+$(echo a)}$(echo b)'     'ab' 0   #9
+       check 'x=""; echo ${x:+$(echo a)}$(echo b)'    'b'  0   #10
+       check 'x=c; echo ${x+$(echo a)}$(echo b)'      'ab' 0   #11
+       check 'x=c; echo ${x:+$(echo a)}$(echo b)'     'ab' 0   #12
+
+       check 'unset x; echo ${x=$(echo a)}$(echo b)'  'ab' 0   #13
+       check 'unset x; echo ${x:=$(echo a)}$(echo b)' 'ab' 0   #14
+       check 'x=""; echo ${x=$(echo a)}$(echo b)'     'b'  0   #15
+       check 'x=""; echo ${x:=$(echo a)}$(echo b)'    'ab' 0   #16
+       check 'x=c; echo ${x=$(echo a)}$(echo b)'      'cb' 0   #17
+       check 'x=c; echo ${x:=$(echo a)}$(echo b)'     'cb' 0   #18
+
+       check 'unset x; echo ${x?$(echo a)}$(echo b)'  ''   2   #19
+       check 'unset x; echo ${x:?$(echo a)}$(echo b)' ''   2   #20
+       check 'x=""; echo ${x?$(echo a)}$(echo b)'     'b'  0   #21
+       check 'x=""; echo ${x:?$(echo a)}$(echo b)'    ''   2   #22
+       check 'x=c; echo ${x?$(echo a)}$(echo b)'      'cb' 0   #23
+       check 'x=c; echo ${x:?$(echo a)}$(echo b)'     'cb' 0   #24
+
+       check 'unset x; echo ${x%$(echo a)}$(echo b)'  'b'  0   #25
+       check 'unset x; echo ${x%%$(echo a)}$(echo b)' 'b'  0   #26
+       check 'x=""; echo ${x%$(echo a)}$(echo b)'     'b'  0   #27
+       check 'x=""; echo ${x%%$(echo a)}$(echo b)'    'b'  0   #28
+       check 'x=c; echo ${x%$(echo a)}$(echo b)'      'cb' 0   #29
+       check 'x=c; echo ${x%%$(echo a)}$(echo b)'     'cb' 0   #30
+       check 'x=aa; echo ${x%$(echo "*a")}$(echo b)'  'ab' 0   #31
+       check 'x=aa; echo ${x%%$(echo "*a")}$(echo b)' 'b'  0   #32
+
+       check 'unset x; echo ${x#$(echo a)}$(echo b)'  'b'  0   #33
+       check 'unset x; echo ${x##$(echo a)}$(echo b)' 'b'  0   #34
+       check 'x=""; echo ${x#$(echo a)}$(echo b)'     'b'  0   #35
+       check 'x=""; echo ${x##$(echo a)}$(echo b)'    'b'  0   #36
+       check 'x=c; echo ${x#$(echo a)}$(echo b)'      'cb' 0   #37
+       check 'x=c; echo ${x##$(echo a)}$(echo b)'     'cb' 0   #38
+       check 'x=aa; echo ${x#$(echo "*a")}$(echo b)'  'ab' 0   #39
+       check 'x=aa; echo ${x##$(echo "*a")}$(echo b)' 'b'  0   #40
+
+       results
+}
+
 atf_init_test_cases() {
        atf_add_test_case dollar_at
        atf_add_test_case dollar_at_with_text
@@ -377,4 +434,5 @@
        atf_add_test_case iteration_on_null_or_null_parameter
        atf_add_test_case iteration_on_null_or_missing_parameter
        atf_add_test_case shell_params
+       atf_add_test_case var_with_embedded_cmdsub
 }



Home | Main Index | Thread Index | Old Index