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 a new test case wrap_strip based upon strip...



details:   https://anonhg.NetBSD.org/src/rev/ed26260d5a0c
branches:  trunk
changeset: 824258:ed26260d5a0c
user:      kre <kre%NetBSD.org@localhost>
date:      Mon May 29 22:27:47 2017 +0000

description:
Add a new test case wrap_strip based upon strip (ie: cut&paste.. to start)
but with \ newline line continuations inserted at strange places.

For the shell as it is today, since strip passes, wrap_strip should
automaticallty pass as well (and does), as the \ newline combination
is simply removed, producing identical input to that of strip.

However, for accurate line counting ($LINENO: coming soon) newlines (no
matter the context) cannot simply "go away" - we have to know where they
occur(ed) (perhaps long after the text was read)  so we know what line
number we are actually processing.   This new test case is (perhaps just
part) of future-proofing that the modified code does not break anything.

diffstat:

 tests/bin/sh/t_expand.sh |  47 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 46 insertions(+), 1 deletions(-)

diffs (68 lines):

diff -r 046f3499e6c6 -r ed26260d5a0c tests/bin/sh/t_expand.sh
--- a/tests/bin/sh/t_expand.sh  Mon May 29 22:21:00 2017 +0000
+++ b/tests/bin/sh/t_expand.sh  Mon May 29 22:27:47 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_expand.sh,v 1.13 2017/05/15 19:53:40 kre Exp $
+# $NetBSD: t_expand.sh,v 1.14 2017/05/29 22:27:47 kre Exp $
 #
 # Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -156,6 +156,50 @@
        done
 }
 
+atf_test_case wrap_strip
+wrap_strip_head() {
+       atf_set "descr" "Checks that the %% operator works and strips" \
+                       "the contents of a variable from the given point" \
+                       'to the end, and that \ \n sequences do not break it'
+}
+wrap_strip_body() {
+       line='#define bindir "/usr/bin" /* comment */'
+       stripped='#define bindir "/usr/bin" '
+
+       for exp in                              \
+               '${line\
+%%/\**}'                                       \
+               '${line%%"/\
+*"*}'                                          \
+               '${line%%'"'"'/*'"'"'\
+*}'                                            \
+               '"${li\
+ne%%/\**}"'                                    \
+               '"${line%%"\
+/*"*}"'                                                \
+               '"${line%\
+%'"'"'/*'"'"'*}"'                              \
+               '${line\
+%\
+/\*\
+*\
+}'                                             \
+               '${line%"/*\
+"*\
+}'                                             \
+               '${line\
+%\
+'"'"'/*'"'"'*}'                                        \
+               '"$\
+{li\
+ne%\
+'"'"'/*'"'"'*}"'
+       do
+               atf_check -o inline:":$stripped:\n" -e empty ${TEST_SH} -c \
+                       "line='${line}'; echo :${exp}:"
+       done
+}
+
 atf_test_case varpattern_backslashes
 varpattern_backslashes_head() {
        atf_set "descr" "Tests that protecting wildcards with backslashes" \
@@ -896,6 +940,7 @@
        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 wrap_strip
        atf_add_test_case var_with_embedded_cmdsub
        atf_add_test_case varpattern_backslashes
 }



Home | Main Index | Thread Index | Old Index