Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/bin/sh PR bin/52090
details: https://anonhg.NetBSD.org/src/rev/940a7472a56d
branches: trunk
changeset: 352170:940a7472a56d
user: kre <kre%NetBSD.org@localhost>
date: Sun Mar 19 20:29:30 2017 +0000
description:
PR bin/52090
Add 5 new test cases to test various ways that $* can be expanded.
Currently 3 of the 5 are marked as "expected to fail" because of the
bug in this PR.
diffstat:
tests/bin/sh/t_expand.sh | 254 ++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 250 insertions(+), 4 deletions(-)
diffs (300 lines):
diff -r ca266977dc22 -r 940a7472a56d tests/bin/sh/t_expand.sh
--- a/tests/bin/sh/t_expand.sh Sun Mar 19 16:51:45 2017 +0000
+++ b/tests/bin/sh/t_expand.sh Sun Mar 19 20:29:30 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_expand.sh,v 1.9 2017/03/12 00:39:47 kre Exp $
+# $NetBSD: t_expand.sh,v 1.10 2017/03/19 20:29:30 kre Exp $
#
# Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -227,6 +227,8 @@
'N=; set -- ${N:-}; for X; do echo "[$X]"; done'
}
+####### The remaining tests use the following helper functions ...
+
nl='
'
reset()
@@ -311,6 +313,8 @@
results()
{
+ test -n "$1" && atf_expect_fail "$1"
+
test -z "${TEST_ID}" && return 0
test -z "${TEST_FAILURES}" && return 0
@@ -318,10 +322,13 @@
echo >&2 "While testing '${TEST_ID}'"
echo >&2 " - - - - - - - - - - - - - - - - -"
echo >&2 "${TEST_FAILURES}"
+
atf_fail \
"Test ${TEST_ID}: $TEST_FAIL_COUNT (of $TEST_NUM) subtests failed - see stderr"
}
+####### End helpers
+
atf_test_case shell_params
shell_params_head() {
atf_set "descr" "Test correct operation of the numeric parameters"
@@ -423,16 +430,255 @@
results
}
+atf_test_case dollar_star
+dollar_star_head() {
+ atf_set "descr" 'Test expansion of various aspects of $*'
+}
+dollar_star_body() {
+
+ reset # dollar_star
+
+ check 'set -- a b c; echo $# $*' '3 a b c' 0 # 1
+ check 'set -- a b c; echo $# "$*"' '3 a b c' 0 # 2
+ check 'set -- a "b c"; echo $# $*' '2 a b c' 0 # 3
+ check 'set -- a "b c"; echo $# "$*"' '2 a b c' 0 # 4
+ check 'set -- a b c; set -- $* ; echo $# $*' '3 a b c' 0 # 5
+ check 'set -- a b c; set -- "$*" ; echo $# $*' '1 a b c' 0 # 6
+ check 'set -- a "b c"; set -- $* ; echo $# $*' '3 a b c' 0 # 7
+ check 'set -- a "b c"; set -- "$*" ; echo $# $*' \
+ '1 a b c' 0 # 8
+
+ check 'IFS=". "; set -- a b c; echo $# $*' '3 a b c' 0 # 9
+ check 'IFS=". "; set -- a b c; echo $# "$*"' '3 a.b.c' 0 #10
+ check 'IFS=". "; set -- a "b c"; echo $# $*' '2 a b c' 0 #11
+ check 'IFS=". "; set -- a "b c"; echo $# "$*"' '2 a.b c' 0 #12
+ check 'IFS=". "; set -- a "b.c"; echo $# $*' '2 a b c' 0 #13
+ check 'IFS=". "; set -- a "b.c"; echo $# "$*"' '2 a.b.c' 0 #14
+ check 'IFS=". "; set -- a b c; set -- $* ; echo $# $*' \
+ '3 a b c' 0 #15
+ check 'IFS=". "; set -- a b c; set -- "$*" ; echo $# $*' \
+ '1 a b c' 0 #16
+ check 'IFS=". "; set -- a "b c"; set -- $* ; echo $# $*' \
+ '3 a b c' 0 #17
+ check 'IFS=". "; set -- a "b c"; set -- "$*" ; echo $# $*' \
+ '1 a b c' 0 #18
+ check 'IFS=". "; set -- a b c; set -- $* ; echo $# "$*"' \
+ '3 a.b.c' 0 #19
+ check 'IFS=". "; set -- a b c; set -- "$*" ; echo $# "$*"' \
+ '1 a.b.c' 0 #20
+ check 'IFS=". "; set -- a "b c"; set -- $* ; echo $# "$*"' \
+ '3 a.b.c' 0 #21
+ check 'IFS=". "; set -- a "b c"; set -- "$*" ; echo $# "$*"' \
+ '1 a.b c' 0 #22
+
+ results
+}
+
+atf_test_case dollar_star_in_word
+dollar_star_in_word_head() {
+ atf_set "descr" 'Test expansion $* occurring in word of ${var:-word}'
+}
+dollar_star_in_word_body() {
+
+ reset dollar_star_in_word
+
+ unset xXx ; # just in case!
+
+ # Note that the expected results for these tests are identical
+ # to those from the dollar_star test. It should never make
+ # a difference whether we expand $* or ${unset:-$*}
+
+ # (note expanding ${unset:-"$*"} is different, that is not tested here)
+
+ check 'set -- a b c; echo $# ${xXx:-$*}' '3 a b c' 0 # 1
+ check 'set -- a b c; echo $# "${xXx:-$*}"' '3 a b c' 0 # 2
+ check 'set -- a "b c"; echo $# ${xXx:-$*}' '2 a b c' 0 # 3
+ check 'set -- a "b c"; echo $# "${xXx:-$*}"' '2 a b c' 0 # 4
+ check 'set -- a b c; set -- ${xXx:-$*} ; echo $# $*' '3 a b c' 0 # 5
+ check 'set -- a b c; set -- "${xXx:-$*}" ; echo $# $*' '1 a b c' 0 # 6
+ check 'set -- a "b c"; set -- ${xXx:-$*} ; echo $# $*' '3 a b c' 0 # 7
+ check 'set -- a "b c"; set -- "${xXx:-$*}" ; echo $# $*' \
+ '1 a b c' 0 # 8
+
+ check 'IFS=". "; set -- a b c; echo $# ${xXx:-$*}' '3 a b c' 0 # 9
+ check 'IFS=". "; set -- a b c; echo $# "${xXx:-$*}"' '3 a.b.c' 0 #10
+ check 'IFS=". "; set -- a "b c"; echo $# ${xXx:-$*}' '2 a b c' 0 #11
+ check 'IFS=". "; set -- a "b c"; echo $# "${xXx:-$*}"' '2 a.b c' 0 #12
+ check 'IFS=". "; set -- a "b.c"; echo $# ${xXx:-$*}' '2 a b c' 0 #13
+ check 'IFS=". "; set -- a "b.c"; echo $# "${xXx:-$*}"' '2 a.b.c' 0 #14
+ check 'IFS=". ";set -- a b c;set -- ${xXx:-$*};echo $# ${xXx:-$*}' \
+ '3 a b c' 0 #15
+ check 'IFS=". ";set -- a b c;set -- "${xXx:-$*}";echo $# ${xXx:-$*}' \
+ '1 a b c' 0 #16
+ check 'IFS=". ";set -- a "b c";set -- ${xXx:-$*};echo $# ${xXx:-$*}' \
+ '3 a b c' 0 #17
+ check 'IFS=". ";set -- a "b c";set -- "${xXx:-$*}";echo $# ${xXx:-$*}' \
+ '1 a b c' 0 #18
+ check 'IFS=". ";set -- a b c;set -- ${xXx:-$*};echo $# "${xXx:-$*}"' \
+ '3 a.b.c' 0 #19
+ check 'IFS=". ";set -- a b c;set -- "$*";echo $# "$*"' \
+ '1 a.b.c' 0 #20
+ check 'IFS=". ";set -- a "b c";set -- $*;echo $# "$*"' \
+ '3 a.b.c' 0 #21
+ check 'IFS=". ";set -- a "b c";set -- "$*";echo $# "$*"' \
+ '1 a.b c' 0 #22
+
+ results
+}
+
+atf_test_case dollar_star_with_empty_ifs
+dollar_star_with_empty_ifs_head() {
+ atf_set "descr" 'Test expansion of $* with IFS=""'
+}
+dollar_star_with_empty_ifs_body() {
+
+ reset dollar_star_with_empty_ifs
+
+ check 'IFS=""; set -- a b c; echo $# $*' '3 a b c' 0 # 1
+ check 'IFS=""; set -- a b c; echo $# "$*"' '3 abc' 0 # 2
+ check 'IFS=""; set -- a "b c"; echo $# $*' '2 a b c' 0 # 3
+ check 'IFS=""; set -- a "b c"; echo $# "$*"' '2 ab c' 0 # 4
+ check 'IFS=""; set -- a "b.c"; echo $# $*' '2 a b.c' 0 # 5
+ check 'IFS=""; set -- a "b.c"; echo $# "$*"' '2 ab.c' 0 # 6
+ check 'IFS=""; set -- a b c; set -- $* ; echo $# $*' \
+ '3 a b c' 0 # 7
+ check 'IFS=""; set -- a b c; set -- "$*" ; echo $# $*' \
+ '1 abc' 0 # 8
+ check 'IFS=""; set -- a "b c"; set -- $* ; echo $# $*' \
+ '2 a b c' 0 # 9
+ check 'IFS=""; set -- a "b c"; set -- "$*" ; echo $# $*' \
+ '1 ab c' 0 #10
+ check 'IFS=""; set -- a b c; set -- $* ; echo $# "$*"' \
+ '3 abc' 0 #11
+ check 'IFS=""; set -- a b c; set -- "$*" ; echo $# "$*"' \
+ '1 abc' 0 #12
+ check 'IFS=""; set -- a "b c"; set -- $* ; echo $# "$*"' \
+ '2 ab c' 0 #13
+ check 'IFS=""; set -- a "b c"; set -- "$*" ; echo $# "$*"' \
+ '1 ab c' 0 #14
+
+ results 'PR bin/52090 expect 7 of 14 subtests to fail'
+}
+
+atf_test_case dollar_star_in_word_empty_ifs
+dollar_star_in_word_empty_ifs_head() {
+ atf_set "descr" 'Test expansion of ${unset:-$*} with IFS=""'
+}
+dollar_star_in_word_empty_ifs_body() {
+
+ reset dollar_star_in_word_empty_ifs
+
+ unset xXx ; # just in case
+
+ # Note that the expected results for these tests are identical
+ # to those from the dollar_star_with_empty_ifs test. It should
+ # never make a difference whether we expand $* or ${unset:-$*}
+
+ # (note expanding ${unset:-"$*"} is different, that is not tested here)
+
+ check 'IFS="";set -- a b c;echo $# ${xXx:-$*}' '3 a b c' 0 # 1
+ check 'IFS="";set -- a b c;echo $# "${xXx:-$*}"' '3 abc' 0 # 2
+ check 'IFS="";set -- a "b c";echo $# ${xXx:-$*}' '2 a b c' 0 # 3
+ check 'IFS="";set -- a "b c";echo $# "${xXx:-$*}"' '2 ab c' 0 # 4
+ check 'IFS="";set -- a "b.c";echo $# ${xXx:-$*}' '2 a b.c' 0 # 5
+ check 'IFS="";set -- a "b.c";echo $# "${xXx:-$*}"' '2 ab.c' 0 # 6
+ check 'IFS="";set -- a b c;set -- ${xXx:-$*};echo $# ${xXx:-$*}' \
+ '3 a b c' 0 # 7
+ check 'IFS="";set -- a b c;set -- "${xXx:-$*}";echo $# ${xXx:-$*}' \
+ '1 abc' 0 # 8
+ check 'IFS="";set -- a "b c";set -- ${xXx:-$*};echo $# ${xXx:-$*}' \
+ '2 a b c' 0 # 9
+ check 'IFS="";set -- a "b c";set -- "${xXx:-$*}";echo $# ${xXx:-$*}' \
+ '1 ab c' 0 #10
+ check 'IFS="";set -- a b c;set -- ${xXx:-$*};echo $# "${xXx:-$*}"' \
+ '3 abc' 0 #11
+ check 'IFS="";set -- a b c;set -- "${xXx:-$*}";echo $# "${xXx:-$*}"' \
+ '1 abc' 0 #12
+ check 'IFS="";set -- a "b c";set -- ${xXx:-$*};echo $# "${xXx:-$*}"' \
+ '2 ab c' 0 #13
+ check 'IFS="";set -- a "b c";set -- "${xXx:-$*}";echo $# "${xXx:-$*}"' \
+ '1 ab c' 0 #14
+
+ results 'PR bin/52090 expect 7 of 14 subtests to fail'
+}
+
+atf_test_case dollar_star_in_quoted_word
+dollar_star_in_quoted_word_head() {
+ atf_set "descr" 'Test expansion $* occurring in word of ${var:-"word"}'
+}
+dollar_star_in_quoted_word_body() {
+
+ reset dollar_star_in_quoted_word
+
+ unset xXx ; # just in case!
+
+ check 'set -- a b c; echo $# ${xXx:-"$*"}' '3 a b c' 0 # 1
+ check 'set -- a "b c"; echo $# ${xXx:-"$*"}' '2 a b c' 0 # 2
+ check 'set -- a b c; set -- ${xXx:-"$*"} ; echo $# ${xXx-"$*"}' \
+ '1 a b c' 0 # 3
+ check 'set -- a "b c"; set -- ${xXx:-"$*"} ; echo $# ${xXx-"$*"}' \
+ '1 a b c' 0 # 4
+ check 'set -- a b c; set -- ${xXx:-"$*"} ; echo $# ${xXx-"$*"}' \
+ '1 a b c' 0 # 5
+ check 'set -- a "b c"; set -- ${xXx:-"$*"} ; echo $# ${xXx-$*}' \
+ '1 a b c' 0 # 6
+ check 'set -- a b c; set -- ${xXx:-$*} ; echo $# ${xXx-"$*"}' \
+ '3 a b c' 0 # 7
+ check 'set -- a "b c"; set -- ${xXx:-$*} ; echo $# ${xXx-"$*"}' \
+ '3 a b c' 0 # 8
+
+ check 'IFS=". "; set -- a b c; echo $# ${xXx:-"$*"}' '3 a.b.c' 0 # 9
+ check 'IFS=". "; set -- a "b c"; echo $# ${xXx:-"$*"}' '2 a.b c' 0 #10
+ check 'IFS=". "; set -- a "b.c"; echo $# ${xXx:-"$*"}' '2 a.b.c' 0 #11
+ check 'IFS=". ";set -- a b c;set -- ${xXx:-"$*"};echo $# ${xXx:-"$*"}' \
+ '1 a.b.c' 0 #12
+ check 'IFS=". ";set -- a "b c";set -- ${xXx:-"$*"};echo $# ${xXx:-"$*"}' \
+ '1 a.b c' 0 #13
+ check 'IFS=". ";set -- a b c;set -- ${xXx:-$*};echo $# ${xXx:-"$*"}' \
+ '3 a.b.c' 0 #14
+ check 'IFS=". ";set -- a "b c";set -- ${xXx:-$*};echo $# ${xXx:-"$*"}' \
+ '3 a.b.c' 0 #15
+ check 'IFS=". ";set -- a b c;set -- ${xXx:-"$*"};echo $# ${xXx:-$*}' \
+ '1 a b c' 0 #16
+ check 'IFS=". ";set -- a "b c";set -- ${xXx:-"$*"};echo $# ${xXx:-$*}' \
+ '1 a b c' 0 #17
+
+ check 'IFS="";set -- a b c;echo $# ${xXx:-"$*"}' '3 abc' 0 #18
+ check 'IFS="";set -- a "b c";echo $# ${xXx:-"$*"}' '2 ab c' 0 #19
+ check 'IFS="";set -- a "b.c";echo $# ${xXx:-"$*"}' '2 ab.c' 0 #20
+ check 'IFS="";set -- a b c;set -- ${xXx:-"$*"};echo $# ${xXx:-"$*"}' \
+ '1 abc' 0 #21
+ check 'IFS="";set -- a "b c";set -- ${xXx:-"$*"};echo $# ${xXx:-"$*"}' \
+ '1 ab c' 0 #22
+ check 'IFS="";set -- a b c;set -- ${xXx:-$*};echo $# ${xXx:-"$*"}' \
+ '3 abc' 0 #23
+ check 'IFS="";set -- a "b c";set -- ${xXx:-$*};echo $# ${xXx:-"$*"}' \
+ '2 ab c' 0 #24
+ check 'IFS="";set -- a b c;set -- ${xXx:-"$*"};echo $# ${xXx:-$*}' \
+ '1 abc' 0 #25
+ check 'IFS="";set -- a "b c";set -- ${xXx:-"$*"};echo $# ${xXx:-$*}' \
+ '1 ab c' 0 #26
+
+ results 'PR bin/52090 - 2 of 26 subtests expected to fail'
+}
+
atf_init_test_cases() {
+ # Listed here in the order ATF runs them, not the order from above
+
+ atf_add_test_case arithmetic
atf_add_test_case dollar_at
atf_add_test_case dollar_at_with_text
- atf_add_test_case strip
- atf_add_test_case varpattern_backslashes
- atf_add_test_case arithmetic
+ atf_add_test_case dollar_star
+ atf_add_test_case dollar_star_in_quoted_word
+ atf_add_test_case dollar_star_in_word
+ atf_add_test_case dollar_star_in_word_empty_ifs
+ atf_add_test_case dollar_star_with_empty_ifs
atf_add_test_case iteration_on_null_parameter
atf_add_test_case iteration_on_quoted_null_parameter
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 strip
atf_add_test_case var_with_embedded_cmdsub
+ atf_add_test_case varpattern_backslashes
}
Home |
Main Index |
Thread Index |
Old Index