From 706a2d4f096dc1c6c52023f92015ccff807b9dc9 Mon Sep 17 00:00:00 2001 From: kre Date: Sun, 12 Mar 2017 00:39:47 +0000 Subject: [PATCH] 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. --- tests/bin/sh/t_expand.sh | 62 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/tests/bin/sh/t_expand.sh b/tests/bin/sh/t_expand.sh index e785e1f66c79..5443fa2ba350 100644 --- a/tests/bin/sh/t_expand.sh +++ b/tests/bin/sh/t_expand.sh @@ -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 @@ results() 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 @@ shell_params_body() { 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_init_test_cases() { 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 }