summaryrefslogtreecommitdiff
path: root/regress/tools
diff options
context:
space:
mode:
authorrillig <rillig@pkgsrc.org>2019-03-22 20:56:16 +0000
committerrillig <rillig@pkgsrc.org>2019-03-22 20:56:16 +0000
commit24a1a1cc212eea5501293f04afa9f622e17950b2 (patch)
tree9749ea730c0629dbd11cc468255d63c45e5ef4c4 /regress/tools
parentd55af289d33d5e9db4ca73426d57bdc67c2ffd23 (diff)
downloadpkgsrc-24a1a1cc212eea5501293f04afa9f622e17950b2.tar.gz
regress/tools: demonstrate wrong quoting in tools wrapper logging
Diffstat (limited to 'regress/tools')
-rw-r--r--regress/tools/Makefile5
-rwxr-xr-xregress/tools/files/logging-test.sh41
-rw-r--r--regress/tools/files/tests.subr10
3 files changed, 48 insertions, 8 deletions
diff --git a/regress/tools/Makefile b/regress/tools/Makefile
index 065b7d0cd34..c8928a77719 100644
--- a/regress/tools/Makefile
+++ b/regress/tools/Makefile
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.10 2016/06/11 11:36:14 rillig Exp $
+# $NetBSD: Makefile,v 1.11 2019/03/22 20:56:16 rillig Exp $
#
DISTNAME= # not applicable
@@ -14,7 +14,8 @@ LICENSE= 2-clause-bsd
WRKSRC= ${WRKDIR}
NO_CHECKSUM= yes
PLIST_SRC= # none
-REGRESS_TESTS= awk sed sh sort tar tr
+REGRESS_TESTS+= logging
+REGRESS_TESTS+= awk sed sh sort tar tr
USE_TOOLS+= awk sed sh sort tar tr
do-build:
diff --git a/regress/tools/files/logging-test.sh b/regress/tools/files/logging-test.sh
new file mode 100755
index 00000000000..50831bbd14d
--- /dev/null
+++ b/regress/tools/files/logging-test.sh
@@ -0,0 +1,41 @@
+#! /bin/sh
+# $NetBSD: logging-test.sh,v 1.1 2019/03/22 20:56:16 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
+# the actual tool command line.
+
+set -eu
+
+mydir=`dirname "$0"`
+. "${mydir}/tests.subr"
+
+tools_log="./tools.log"
+nopath_log="./nopath.log"
+
+rm -f "$tools_log" "$nopath_log"
+
+TOOLS_WRAPPER_LOG="$tools_log"
+export TOOLS_WRAPPER_LOG
+
+# Forcibly call the echo from the tools directory. This tool is wrapped and
+# logged.
+(exec echo "begin" "*" "*" "*" "end")
+
+unset TOOLS_WRAPPER_LOG
+
+# usage: assert_file_equals $filename <<EOF ... EOF
+assert_file_equals() {
+ actual=`cat "$1"`
+ expected=`cat`
+ assert_equal "$1" "$expected" "$actual"
+}
+
+sed 's,/.*/\.tools/,WRKDIR/.tools/,' < "$tools_log" > "$nopath_log"
+
+assert_file_equals "$nopath_log" <<EOF
+[*] WRKDIR/.tools/bin/echo begin * * * end
+<.> echo begin tools.log tools.log tools.log end
+EOF
+# FIXME: the above output is not quoted correctly.
+# The tools.log should not appear there.
diff --git a/regress/tools/files/tests.subr b/regress/tools/files/tests.subr
index 8079dfbc55d..aefdd9ea6ca 100644
--- a/regress/tools/files/tests.subr
+++ b/regress/tools/files/tests.subr
@@ -1,4 +1,4 @@
-# $NetBSD: tests.subr,v 1.2 2005/11/24 19:20:18 rillig Exp $
+# $NetBSD: tests.subr,v 1.3 2019/03/22 20:56:16 rillig Exp $
#
# usage: testcase_start <testname>
@@ -8,9 +8,7 @@ testcase_start() {
# usage: assert_equal <testname> <expected> <got>
assert_equal() {
- case $2 in
- "$3") ;;
- *) echo "[assert_equal:$1] expected \"$2\", got \"$3\"." 1>&2
- return 1;;
- esac
+ [ "x$2" = "x$3" ] && return 0
+ printf "error: assert_equal failed for %s:\nexpected: %s\nbut got: %s\n" "$1" "$2" "$3" 1>&2
+ return 1
}