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 make(1): add more tests for parsing ...
details: https://anonhg.NetBSD.org/src/rev/fc074973b63e
branches: trunk
changeset: 942430:fc074973b63e
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Nov 08 02:31:24 2020 +0000
description:
make(1): add more tests for parsing .MAKEFLAGS lines
diffstat:
usr.bin/make/unit-tests/deptgt-makeflags.exp | 1 +
usr.bin/make/unit-tests/deptgt-makeflags.mk | 51 ++++++++++++++++++++++++---
2 files changed, 46 insertions(+), 6 deletions(-)
diffs (102 lines):
diff -r 503af3b95e1d -r fc074973b63e usr.bin/make/unit-tests/deptgt-makeflags.exp
--- a/usr.bin/make/unit-tests/deptgt-makeflags.exp Sun Nov 08 02:05:34 2020 +0000
+++ b/usr.bin/make/unit-tests/deptgt-makeflags.exp Sun Nov 08 02:31:24 2020 +0000
@@ -6,4 +6,5 @@
lhs = "$$", rhs = "$$", op = !=
Global:.MAKEFLAGS = -r -k -D VAR -D VAR -d cv -d
Global:.MAKEFLAGS = -r -k -D VAR -D VAR -d cv -d 0
+make: Unterminated quoted string [make VAR=initial UNBALANCED=']
exit status 0
diff -r 503af3b95e1d -r fc074973b63e usr.bin/make/unit-tests/deptgt-makeflags.mk
--- a/usr.bin/make/unit-tests/deptgt-makeflags.mk Sun Nov 08 02:05:34 2020 +0000
+++ b/usr.bin/make/unit-tests/deptgt-makeflags.mk Sun Nov 08 02:31:24 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: deptgt-makeflags.mk,v 1.4 2020/10/23 14:48:49 rillig Exp $
+# $NetBSD: deptgt-makeflags.mk,v 1.5 2020/11/08 02:31:24 rillig Exp $
#
# Tests for the special target .MAKEFLAGS in dependency declarations,
# which adds command line options later, at parse time.
@@ -6,25 +6,27 @@
# The -D option sets a variable in the "Global" scope and thus can be
# undefined later.
.MAKEFLAGS: -D VAR
-
.if ${VAR} != 1
. error
.endif
+# Variables that are set via the -D command line option are normal global
+# variables and can thus be undefined later.
.undef VAR
-
.if defined(VAR)
. error
.endif
+# The -D command line option can define a variable again, after it has been
+# undefined.
.MAKEFLAGS: -D VAR
-
.if ${VAR} != 1
. error
.endif
+# The "dependency" for .MAKEFLAGS is split into words, interpreting the usual
+# quotes and escape sequences from the backslash.
.MAKEFLAGS: VAR="value"' with'\ spaces
-
.if ${VAR} != "value with spaces"
. error
.endif
@@ -32,7 +34,6 @@
# Variables set on the command line as VAR=value are placed in the
# "Command" scope and thus cannot be undefined.
.undef VAR
-
.if ${VAR} != "value with spaces"
. error
.endif
@@ -47,5 +48,43 @@
.endif
.MAKEFLAGS: -d0
+# An empty command line is skipped.
+.MAKEFLAGS: # none
+
+# Escape sequences like \n are interpreted.
+# The following line looks as if it assigned a newline to nl, but it doesn't.
+# Instead, the \n ends up as a line that is then interpreted as a variable
+# assignment. At that point, the line is simply "nl=\n", and the \n is
+# skipped since it is whitespace (see Parse_IsVar).
+.MAKEFLAGS: nl="\n"
+.if ${nl} != ""
+. error
+.endif
+
+# Next try at defining another newline variable. Since whitespace around the
+# variable value is trimmed, two empty variable expressions surround the
+# literal newline now. This prevents the newline from being skipped during
+# parsing. The ':=' assignment operator expands the empty variable
+# expressions, leaving only the newline as the variable value.
+#
+# This is one of the very few ways (maybe even the only one) to inject literal
+# newlines into a line that is being parsed. This may confuse the parser.
+# For example, in cond.c the parser only expects horizontal whitespace (' '
+# and '\t'), but no newlines.
+#.MAKEFLAGS: -dcpv
+.MAKEFLAGS: nl:="$${:U}\n$${:U}"
+.if ${nl} != ${.newline}
+. error
+.endif
+#.MAKEFLAGS: -d0
+
+# Unbalanced quotes produce an error message. If they occur anywhere in the
+# command line, the whole command line is skipped.
+.MAKEFLAGS: VAR=previous
+.MAKEFLAGS: VAR=initial UNBALANCED='
+.if ${VAR} != "previous"
+. error
+.endif
+
all:
@:;
Home |
Main Index |
Thread Index |
Old Index