Module Name:    src
Committed By:   rillig
Date:           Sat Jan 22 16:23:56 UTC 2022

Modified Files:
        src/usr.bin/make/unit-tests: Makefile directive-elifdef.mk
            directive-ifmake.exp directive-ifmake.mk

Log Message:
tests/make: explore edge cases involving .ifmake


To generate a diff of this commit:
cvs rdiff -u -r1.296 -r1.297 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/directive-elifdef.mk
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/directive-ifmake.exp
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/directive-ifmake.mk

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

Modified files:

Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.296 src/usr.bin/make/unit-tests/Makefile:1.297
--- src/usr.bin/make/unit-tests/Makefile:1.296	Wed Jan 19 22:10:41 2022
+++ src/usr.bin/make/unit-tests/Makefile	Sat Jan 22 16:23:56 2022
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.296 2022/01/19 22:10:41 rillig Exp $
+# $NetBSD: Makefile,v 1.297 2022/01/22 16:23:56 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -478,7 +478,6 @@ ENV.varname-vpath+=	VPATH=varname-vpath.
 # If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of
 # settings FLAGS.test=-dv here, since that is closer to the test code.
 FLAGS.cond-func-make=		via-cmdline
-FLAGS.directive-ifmake=		first second
 FLAGS.doterror=			# none, especially not -k
 FLAGS.jobs-error-indirect=	# none, especially not -k
 FLAGS.jobs-error-nested=	# none, especially not -k

Index: src/usr.bin/make/unit-tests/directive-elifdef.mk
diff -u src/usr.bin/make/unit-tests/directive-elifdef.mk:1.2 src/usr.bin/make/unit-tests/directive-elifdef.mk:1.3
--- src/usr.bin/make/unit-tests/directive-elifdef.mk:1.2	Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/directive-elifdef.mk	Sat Jan 22 16:23:56 2022
@@ -1,8 +1,21 @@
-# $NetBSD: directive-elifdef.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: directive-elifdef.mk,v 1.3 2022/01/22 16:23:56 rillig Exp $
 #
-# Tests for the .elifdef directive.
+# Tests for the .elifdef directive, which is seldom used.  Instead of writing
+# '.elifdef VAR', the usual form is the more versatile '.elif defined(VAR)'.
 
-# TODO: Implementation
+# At this point, VAR is not defined, so the condition evaluates to false.
+.if 0
+.elifdef VAR
+.  error
+.endif
+
+VAR=	# defined
+
+# At this point, VAR is defined, so the condition evaluates to true.
+.if 0
+.elifdef VAR
+.else
+.  error
+.endif
 
 all:
-	@:;

Index: src/usr.bin/make/unit-tests/directive-ifmake.exp
diff -u src/usr.bin/make/unit-tests/directive-ifmake.exp:1.5 src/usr.bin/make/unit-tests/directive-ifmake.exp:1.6
--- src/usr.bin/make/unit-tests/directive-ifmake.exp:1.5	Sun Nov 15 20:20:58 2020
+++ src/usr.bin/make/unit-tests/directive-ifmake.exp	Sat Jan 22 16:23:56 2022
@@ -8,4 +8,8 @@ make: "directive-ifmake.mk" line 75: ok
 : first
 : second
 : late-target
-exit status 0
+make: don't know how to make !edge (continuing)
+
+Stop.
+make: stopped in unit-tests
+exit status 1

Index: src/usr.bin/make/unit-tests/directive-ifmake.mk
diff -u src/usr.bin/make/unit-tests/directive-ifmake.mk:1.8 src/usr.bin/make/unit-tests/directive-ifmake.mk:1.9
--- src/usr.bin/make/unit-tests/directive-ifmake.mk:1.8	Sun Nov 15 20:20:58 2020
+++ src/usr.bin/make/unit-tests/directive-ifmake.mk	Sat Jan 22 16:23:56 2022
@@ -1,12 +1,12 @@
-# $NetBSD: directive-ifmake.mk,v 1.8 2020/11/15 20:20:58 rillig Exp $
+# $NetBSD: directive-ifmake.mk,v 1.9 2022/01/22 16:23:56 rillig Exp $
 #
 # Tests for the .ifmake directive, which provides a shortcut for asking
 # whether a certain target is requested to be made from the command line.
 #
 # TODO: Describe why the shortcut may be useful (if it's useful at all),
-# instead of sticking to the simple '.if' only.
+# instead of using the more versatile '.if make(target)'.
 
-# The targets 'first' and 'second' are passed in on the command line.
+.MAKEFLAGS: first second
 
 # This is the most basic form.
 .ifmake first
@@ -15,9 +15,9 @@
 .  warning positive condition fails
 .endif
 
-# The not operator works as expected.
-# An alternative interpretation were that this condition is asking whether
-# the target "!first" was requested.  To distinguish this, see the next test.
+# The '!' is interpreted as 'not'.  A possible alternative interpretation of
+# this condition is whether the target named "!first" was requested.  To
+# distinguish these cases, see the next test.
 .ifmake !first
 .  warning unexpected
 .else
@@ -78,5 +78,30 @@
 .endif
 
 
-first second unmentioned late-target:
+# As an edge case, a target can actually be named "!first" on the command
+# line.  There is no way to define a target of this name though since in a
+# dependency line, a plain '!' is interpreted as a dependency operator.
+
+.MAKEFLAGS: !edge
+.ifmake edge
+.  error
+.endif
+
+# The '\!edge' in the following condition is parsed as a bare word.  For such
+# a bare word, there is no escaping mechanism so the backslash passes through.
+# Since the condition function 'make' accepts a pattern instead of a plain
+# target name, the '\' is finally discarded in Str_Match.
+.ifmake \!edge
+.else
+.  error
+.endif
+
+# In a dependency line, a plain '!' is interpreted as a dependency operator
+# (the other two are ':' and '::').  If the '!' is escaped by a '\', as
+# implemented in ParseDependencyTargetWord, the additional backslash is never
+# removed though.  The target name thus becomes '\!edge' instead of the
+# intended '!edge'.  Defining a target whose name contains a '!' will either
+# require additional tricks, or it may even be impossible.
+
+first second unmentioned late-target \!edge:
 	: $@

Reply via email to