pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/regress/tools regress/tools: show that TOOLS_SCRIPT is...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/37065236301e
branches:  trunk
changeset: 393711:37065236301e
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sat Mar 23 22:59:11 2019 +0000

description:
regress/tools: show that TOOLS_SCRIPT is not always logged properly

diffstat:

 regress/tools/Makefile              |   12 ++-
 regress/tools/files/logging-test.sh |  140 ++++++++++++++++++++++++++---------
 regress/tools/files/tests.subr      |    4 +-
 3 files changed, 116 insertions(+), 40 deletions(-)

diffs (218 lines):

diff -r 0b1e1d538850 -r 37065236301e regress/tools/Makefile
--- a/regress/tools/Makefile    Sat Mar 23 18:12:32 2019 +0000
+++ b/regress/tools/Makefile    Sat Mar 23 22:59:11 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.12 2019/03/22 22:41:06 rillig Exp $
+# $NetBSD: Makefile,v 1.13 2019/03/23 22:59:11 rillig Exp $
 #
 
 DISTNAME=      # not applicable
@@ -33,6 +33,16 @@
 TOOLS_SCRIPT.world= \
                echo oops
 
+# The script for this example tool contains single quotes, double quotes
+# and backslashes to demonstrate that these are properly logged.
+TOOLS_CREATE+= for-loop
+TOOLS_SCRIPT.for-loop= \
+       printf '%s' "$$0"; \
+       for arg in "$$@"; do \
+               printf ' <%s>' "$$arg"; \
+       done; \
+       printf '\n'
+
 do-build:
 .for t in ${REGRESS_TESTS}
        ${RUN} cd ${WRKSRC};                                            \
diff -r 0b1e1d538850 -r 37065236301e regress/tools/files/logging-test.sh
--- a/regress/tools/files/logging-test.sh       Sat Mar 23 18:12:32 2019 +0000
+++ b/regress/tools/files/logging-test.sh       Sat Mar 23 22:59:11 2019 +0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: logging-test.sh,v 1.3 2019/03/22 22:41:06 rillig Exp $
+# $NetBSD: logging-test.sh,v 1.4 2019/03/23 22:59:11 rillig Exp $
 
 # Up to March 2019, the command logging for the wrapped tools didn't properly
 # quote the command line arguments. This meant the logging did not reflect
@@ -20,41 +20,51 @@
 
 rm -f "$tools_log" "$nopath_log"
 
-TOOLS_WRAPPER_LOG="$tools_log"
-export TOOLS_WRAPPER_LOG
+test_case() {
+       test_name="$1"
+}
 
-# Forcibly call the tools from the tools directory, not the shell builtins.
-# The echo tool is a wrapped tool without additional arguments.
-# The mkdir tool is a wrapped tool that always gets the -p option.
-(exec echo "begin" "*" "*" "*" "end")
-(exec echo "dquot" "\"" "end")
-(exec echo "squot" "'" "end")
-(exec echo "five" '\\\\\' "end")
-(exec mkdir "directory with spaces")
-(exec script-dquot)
-(exec script-backslash)
+# usage: run_tool $tool $args...
+run_tool() {
+       TOOLS_WRAPPER_LOG="$tools_log"
+       export TOOLS_WRAPPER_LOG
 
-unset TOOLS_WRAPPER_LOG
+       # The exec makes sure that the tool from the tools directory is
+       # called, even for shell builtins.
+       (exec "$@")
 
-# usage: assert_file_equals $filename <<EOF ... EOF
-assert_file_equals() {
-       actual=`cat "$1"`
-       expected=`cat`
-       assert_equal "$1" "$expected" "$actual"
+       unset TOOLS_WRAPPER_LOG
+
 }
 
-# Replace the variable parts from the output with placeholders.
-sed < "$tools_log" > "$nopath_log"             \
-       -e 's,/.*/\.tools/,WRKDIR/.tools/,'     \
-       -e 's,^<.> /[^ ]*/,<.> BINDIR/,'
+# usage: assert_log <<EOF ... EOF
+assert_log() {
+       # Replace the variable parts from the output with placeholders.
+       sed < "$tools_log" > "$nopath_log"              \
+               -e 's,/.*/\.tools/,WRKDIR/.tools/,'     \
+               -e 's,^<.> /[^ ]*/,<.> BINDIR/,'
+
+       actual=`cat "$nopath_log"`
+       expected=`cat`
+       assert_equal "$test_name" "$expected" "$actual" || exit $?
 
-# The double space in the "echo  begin" below is because the echo command
-# doesn't get any additional arguments by the tool wrapper (TOOLS_ARGS.echo).
-#
-# The log doesn't show delimiters for the arguments, which makes the call to
-# mkdir ambiguous. Doing proper shell quoting would require code similar to
-# shquote from mk/scripts/shell-lib. This may make the tools wrapper slower.
-assert_file_equals "$nopath_log" <<'EOF'
+       rm -f "$tools_log" "$nopath_log"
+       unset test_name
+}
+
+test_case "TOOLS_PATH without TOOLS_ARGS"
+{
+       # The "*" ensure that there is no accidental file expansion.
+       run_tool echo "begin" "*" "*" "*" "end"
+       run_tool echo "dquot" "\"" "end"
+       run_tool echo "squot" "'" "end"
+       run_tool echo "five" '\\\\\' "end"
+
+       # In the <.> lines there are 2 spaces between echo and its first
+       # argument. This is because the echo command doesn't get any
+       # additional arguments by the tool wrapper (TOOLS_ARGS.echo).
+
+       assert_log <<'EOF'
 [*] WRKDIR/.tools/bin/echo begin * * * end
 <.> echo  begin * * * end
 [*] WRKDIR/.tools/bin/echo dquot " end
@@ -63,20 +73,76 @@
 <.> echo  squot ' end
 [*] WRKDIR/.tools/bin/echo five \\\\\ end
 <.> echo  five \\\\\ end
+EOF
+}
+
+test_case "TOOLS_PATH with TOOLS_ARGS"
+{
+       # The mkdir tool always gets the -p option.
+
+       run_tool mkdir "directory with spaces"
+
+       # The log doesn't show delimiters for the arguments, which makes
+       # the call to mkdir ambiguous. Doing proper shell quoting would
+       # require code similar to shquote from mk/scripts/shell-lib.
+       # This may make the tools wrapper slower.
+       assert_log <<'EOF'
 [*] WRKDIR/.tools/bin/mkdir directory with spaces
 <.> BINDIR/mkdir -p directory with spaces
+EOF
+}
+
+test_case "TOOLS_SCRIPT with dquot"
+{
+       run_tool script-dquot
+
+       # The following log output contains a trailing whitespace. This
+       # is because the tool didn't get any actual arguments.
+       #
+       # FIXME: the "echo oops" occurs because the script is not
+       # properly quoted during logging.
+       assert_log <<'EOF'
 [*] WRKDIR/.tools/bin/script-dquot 
 [*] WRKDIR/.tools/bin/world 
 <.> echo oops
 oops
+EOF
+}
+
+test_case "TOOLS_SCRIPT with backslashes"
+{
+       run_tool script-backslash
+
+       # The following log output contains a trailing whitespace. This
+       # is because the tool didn't get any actual arguments.
+       assert_log <<'EOF'
 [*] WRKDIR/.tools/bin/script-backslash 
 <.> echo hello\;\ world
 EOF
+}
 
-# FIXME: The tool wrapper log must contain [*] and <.> equally often.
-# Explanation:
-# In WRKDIR/.tools/bin/script-dquot, the shell quoting is obviously wrong.
-# This results in "hello" being echoed to stdout instead of the log file.
-# This also results in the "hello" tool to be run.
-# The output of that tool is appended to the log file, as can be seen in
-# the tool wrapper script.
+test_case "TOOLS_SCRIPT with complicated replacement"
+{
+       run_tool for-loop "one" "two" "three"
+
+       # TODO: Add proper quoting for the printf argument inside the loop.
+       assert_log <<'EOF'
+[*] WRKDIR/.tools/bin/for-loop one two three
+<.> printf '%s' WRKDIR/.tools/bin/for-loop;  for arg in one two three; do  printf ' <%s>' ;  done;  printf '\n'
+EOF
+}
+
+test_case "TOOLS_SCRIPT with actual arguments containing quotes"
+{
+       run_tool for-loop \
+               -DSD='"a b"' \
+               -DSS=''\''a b'\''' \
+               -DDD="\"a b\"" \
+               -DB=\"a\ b\"
+
+       # TODO: Add proper quoting for the arguments.
+       assert_log <<'EOF'
+[*] WRKDIR/.tools/bin/for-loop -DSD="a b" -DSS='a b' -DDD="a b" -DB="a b"
+<.> printf '%s' WRKDIR/.tools/bin/for-loop;  for arg in -DSD="a b" -DSS='a b' -DDD="a b" -DB="a b"; do  printf ' <%s>' ;  done;  printf '\n'
+EOF
+}
diff -r 0b1e1d538850 -r 37065236301e regress/tools/files/tests.subr
--- a/regress/tools/files/tests.subr    Sat Mar 23 18:12:32 2019 +0000
+++ b/regress/tools/files/tests.subr    Sat Mar 23 22:59:11 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: tests.subr,v 1.3 2019/03/22 20:56:16 rillig Exp $
+# $NetBSD: tests.subr,v 1.4 2019/03/23 22:59:11 rillig Exp $
 #
 
 # usage: testcase_start <testname>
@@ -9,6 +9,6 @@
 # usage: assert_equal <testname> <expected> <got>
 assert_equal() {
        [ "x$2" = "x$3" ] && return 0
-       printf "error: assert_equal failed for %s:\nexpected: %s\nbut got:  %s\n" "$1" "$2" "$3" 1>&2
+       printf "error: assert_equal failed for \"%s\":\nexpected: %s\nbut got:  %s\n" "$1" "$2" "$3" 1>&2
        return 1
 }



Home | Main Index | Thread Index | Old Index