pkgsrc-Changes archive

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

CVS commit: pkgsrc/regress/tools



Module Name:    pkgsrc
Committed By:   rillig
Date:           Sat Mar 23 22:59:11 UTC 2019

Modified Files:
        pkgsrc/regress/tools: Makefile
        pkgsrc/regress/tools/files: logging-test.sh tests.subr

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


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 pkgsrc/regress/tools/Makefile
cvs rdiff -u -r1.3 -r1.4 pkgsrc/regress/tools/files/logging-test.sh \
    pkgsrc/regress/tools/files/tests.subr

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/regress/tools/Makefile
diff -u pkgsrc/regress/tools/Makefile:1.12 pkgsrc/regress/tools/Makefile:1.13
--- pkgsrc/regress/tools/Makefile:1.12  Fri Mar 22 22:41:06 2019
+++ pkgsrc/regress/tools/Makefile       Sat Mar 23 22:59:11 2019
@@ -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_CREATE+=       world
 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};                                            \

Index: pkgsrc/regress/tools/files/logging-test.sh
diff -u pkgsrc/regress/tools/files/logging-test.sh:1.3 pkgsrc/regress/tools/files/logging-test.sh:1.4
--- pkgsrc/regress/tools/files/logging-test.sh:1.3      Fri Mar 22 22:41:06 2019
+++ pkgsrc/regress/tools/files/logging-test.sh  Sat Mar 23 22:59:11 2019
@@ -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 @@ nopath_log="./nopath.log"
 
 rm -f "$tools_log" "$nopath_log"
 
-TOOLS_WRAPPER_LOG="$tools_log"
-export TOOLS_WRAPPER_LOG
+test_case() {
+       test_name="$1"
+}
+
+# usage: run_tool $tool $args...
+run_tool() {
+       TOOLS_WRAPPER_LOG="$tools_log"
+       export TOOLS_WRAPPER_LOG
+
+       # The exec makes sure that the tool from the tools directory is
+       # called, even for shell builtins.
+       (exec "$@")
+
+       unset TOOLS_WRAPPER_LOG
+
+}
+
+# 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/,'
 
-# 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)
-
-unset TOOLS_WRAPPER_LOG
-
-# usage: assert_file_equals $filename <<EOF ... EOF
-assert_file_equals() {
-       actual=`cat "$1"`
+       actual=`cat "$nopath_log"`
        expected=`cat`
-       assert_equal "$1" "$expected" "$actual"
+       assert_equal "$test_name" "$expected" "$actual" || exit $?
+
+       rm -f "$tools_log" "$nopath_log"
+       unset test_name
 }
 
-# Replace the variable parts from the output with placeholders.
-sed < "$tools_log" > "$nopath_log"             \
-       -e 's,/.*/\.tools/,WRKDIR/.tools/,'     \
-       -e 's,^<.> /[^ ]*/,<.> BINDIR/,'
+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).
 
-# 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'
+       assert_log <<'EOF'
 [*] WRKDIR/.tools/bin/echo begin * * * end
 <.> echo  begin * * * end
 [*] WRKDIR/.tools/bin/echo dquot " end
@@ -63,20 +73,76 @@ assert_file_equals "$nopath_log" <<'EOF'
 <.> 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
+}
Index: pkgsrc/regress/tools/files/tests.subr
diff -u pkgsrc/regress/tools/files/tests.subr:1.3 pkgsrc/regress/tools/files/tests.subr:1.4
--- pkgsrc/regress/tools/files/tests.subr:1.3   Fri Mar 22 20:56:16 2019
+++ pkgsrc/regress/tools/files/tests.subr       Sat Mar 23 22:59:11 2019
@@ -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 @@ testcase_start() {
 # 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