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: explore edge cases invol...



details:   https://anonhg.NetBSD.org/src/rev/bc7357e7ad3f
branches:  trunk
changeset: 359785:bc7357e7ad3f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jan 22 16:23:56 2022 +0000

description:
tests/make: explore edge cases involving .ifmake

diffstat:

 usr.bin/make/unit-tests/Makefile             |   3 +-
 usr.bin/make/unit-tests/directive-elifdef.mk |  21 ++++++++++++--
 usr.bin/make/unit-tests/directive-ifmake.exp |   6 +++-
 usr.bin/make/unit-tests/directive-ifmake.mk  |  39 ++++++++++++++++++++++-----
 4 files changed, 55 insertions(+), 14 deletions(-)

diffs (123 lines):

diff -r 7fdc2a5c2e80 -r bc7357e7ad3f usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile  Sat Jan 22 15:16:37 2022 +0000
+++ b/usr.bin/make/unit-tests/Makefile  Sat Jan 22 16:23:56 2022 +0000
@@ -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 @@
 # 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
diff -r 7fdc2a5c2e80 -r bc7357e7ad3f usr.bin/make/unit-tests/directive-elifdef.mk
--- a/usr.bin/make/unit-tests/directive-elifdef.mk      Sat Jan 22 15:16:37 2022 +0000
+++ b/usr.bin/make/unit-tests/directive-elifdef.mk      Sat Jan 22 16:23:56 2022 +0000
@@ -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)'.
+
+# At this point, VAR is not defined, so the condition evaluates to false.
+.if 0
+.elifdef VAR
+.  error
+.endif
 
-# TODO: Implementation
+VAR=   # defined
+
+# At this point, VAR is defined, so the condition evaluates to true.
+.if 0
+.elifdef VAR
+.else
+.  error
+.endif
 
 all:
-       @:;
diff -r 7fdc2a5c2e80 -r bc7357e7ad3f usr.bin/make/unit-tests/directive-ifmake.exp
--- a/usr.bin/make/unit-tests/directive-ifmake.exp      Sat Jan 22 15:16:37 2022 +0000
+++ b/usr.bin/make/unit-tests/directive-ifmake.exp      Sat Jan 22 16:23:56 2022 +0000
@@ -8,4 +8,8 @@
 : 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
diff -r 7fdc2a5c2e80 -r bc7357e7ad3f usr.bin/make/unit-tests/directive-ifmake.mk
--- a/usr.bin/make/unit-tests/directive-ifmake.mk       Sat Jan 22 15:16:37 2022 +0000
+++ b/usr.bin/make/unit-tests/directive-ifmake.mk       Sat Jan 22 16:23:56 2022 +0000
@@ -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:
        : $@



Home | Main Index | Thread Index | Old Index