Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make/unit-tests tests/make: demonstrate spaces and '...



details:   https://anonhg.NetBSD.org/src/rev/26d1916c7533
branches:  trunk
changeset: 366714:26d1916c7533
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jun 10 18:58:07 2022 +0000

description:
tests/make: demonstrate spaces and '#' in command line arguments

diffstat:

 usr.bin/make/unit-tests/cmdline.exp |   3 +++
 usr.bin/make/unit-tests/cmdline.mk  |  24 +++++++++++++++++++++++-
 2 files changed, 26 insertions(+), 1 deletions(-)

diffs (53 lines):

diff -r 52b8712f74ba -r 26d1916c7533 usr.bin/make/unit-tests/cmdline.exp
--- a/usr.bin/make/unit-tests/cmdline.exp       Fri Jun 10 18:29:01 2022 +0000
+++ b/usr.bin/make/unit-tests/cmdline.exp       Fri Jun 10 18:58:07 2022 +0000
@@ -2,4 +2,7 @@
 show-objdir: <tmpdir>/6a8899d2-d227-4b55-9b6b-f3c8eeb83fd5
 makeobjdir-indirect:
 show-objdir: <tmpdir>/a7b41170-53f8-4cc2-bc5c-e4c3dd93ec45/
+space-and-comment:
+value # no comment $
+value # no comment $
 exit status 0
diff -r 52b8712f74ba -r 26d1916c7533 usr.bin/make/unit-tests/cmdline.mk
--- a/usr.bin/make/unit-tests/cmdline.mk        Fri Jun 10 18:29:01 2022 +0000
+++ b/usr.bin/make/unit-tests/cmdline.mk        Fri Jun 10 18:58:07 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: cmdline.mk,v 1.3 2021/02/06 18:26:03 sjg Exp $
+# $NetBSD: cmdline.mk,v 1.4 2022/06/10 18:58:07 rillig Exp $
 #
 # Tests for command line parsing and related special variables.
 
@@ -11,6 +11,7 @@
 
 all: prepare-dirs
 all: makeobjdir-direct makeobjdir-indirect
+all: space-and-comment
 
 prepare-dirs:
        @rm -rf ${DIR2} ${DIR12}
@@ -34,3 +35,24 @@
 
 show-objdir:
        @echo $@: ${.OBJDIR:Q}
+
+
+# Variable assignments in the command line are handled differently from
+# variable assignments in makefiles.  In the command line, trailing whitespace
+# is preserved, and the '#' does not start a comment.  This is because the
+# low-level parsing from ParseRawLine does not take place.
+#
+# Preserving '#' and trailing whitespace has the benefit that when passing
+# such values to sub-makes via MAKEFLAGS, no special encoding is needed.
+# Leading whitespace in the variable value is discarded though, which makes
+# the behavior inconsistent.
+space-and-comment: .PHONY
+       @echo $@:
+
+       @env -i \
+           ${MAKE} -r -f /dev/null ' VAR= value # no comment ' -v VAR \
+       | sed 's,$$,$$,'
+
+       @env -i MAKEFLAGS="' VAR= value # no comment '" \
+           ${MAKE} -r -f /dev/null -v VAR \
+       | sed 's,$$,$$,'



Home | Main Index | Thread Index | Old Index