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: demonstrate wrong quoting...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/7241acf99001
branches:  trunk
changeset: 321472:7241acf99001
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Fri Mar 22 20:56:16 2019 +0000

description:
regress/tools: demonstrate wrong quoting in tools wrapper logging

diffstat:

 regress/tools/Makefile              |   5 ++-
 regress/tools/files/logging-test.sh |  41 +++++++++++++++++++++++++++++++++++++
 regress/tools/files/tests.subr      |  10 +++-----
 3 files changed, 48 insertions(+), 8 deletions(-)

diffs (86 lines):

diff -r 5de2a2a5a29f -r 7241acf99001 regress/tools/Makefile
--- a/regress/tools/Makefile    Fri Mar 22 17:58:52 2019 +0000
+++ b/regress/tools/Makefile    Fri Mar 22 20:56:16 2019 +0000
@@ -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 @@
 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 -r 5de2a2a5a29f -r 7241acf99001 regress/tools/files/logging-test.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/tools/files/logging-test.sh       Fri Mar 22 20:56:16 2019 +0000
@@ -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 -r 5de2a2a5a29f -r 7241acf99001 regress/tools/files/tests.subr
--- a/regress/tools/files/tests.subr    Fri Mar 22 17:58:52 2019 +0000
+++ b/regress/tools/files/tests.subr    Fri Mar 22 20:56:16 2019 +0000
@@ -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 @@
 
 # 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
 }



Home | Main Index | Thread Index | Old Index