Module Name: src
Committed By: rillig
Date: Sat Aug 29 19:07:32 UTC 2020
Modified Files:
src/usr.bin/make/unit-tests: Makefile directive-ifmake.exp
directive-ifmake.mk
Log Message:
make(1): add test for the .ifmake directive
To generate a diff of this commit:
cvs rdiff -u -r1.127 -r1.128 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/directive-ifmake.exp
cvs rdiff -u -r1.2 -r1.3 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.127 src/usr.bin/make/unit-tests/Makefile:1.128
--- src/usr.bin/make/unit-tests/Makefile:1.127 Sat Aug 29 18:50:25 2020
+++ src/usr.bin/make/unit-tests/Makefile Sat Aug 29 19:07:32 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.127 2020/08/29 18:50:25 rillig Exp $
+# $NetBSD: Makefile,v 1.128 2020/08/29 19:07:32 rillig Exp $
#
# Unit tests for make(1)
#
@@ -329,6 +329,7 @@ ENV.varmisc+= FROM_ENV_AFTER=env
# settings FLAGS.test=-dv here, since that is closer to the test code.
FLAGS.archive= -dA
FLAGS.counter= -dv
+FLAGS.directive-ifmake= first second
FLAGS.doterror= # none
FLAGS.envfirst= -e
FLAGS.export= # none
Index: src/usr.bin/make/unit-tests/directive-ifmake.exp
diff -u src/usr.bin/make/unit-tests/directive-ifmake.exp:1.1 src/usr.bin/make/unit-tests/directive-ifmake.exp:1.2
--- src/usr.bin/make/unit-tests/directive-ifmake.exp:1.1 Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/directive-ifmake.exp Sat Aug 29 19:07:32 2020
@@ -1 +1,8 @@
+make: "directive-ifmake.mk" line 8: ok: positive condition works
+make: "directive-ifmake.mk" line 19: ok: negation works
+make: "directive-ifmake.mk" line 25: ok: double negation works
+make: "directive-ifmake.mk" line 32: ok: both mentioned
+make: "directive-ifmake.mk" line 39: ok: only those mentioned
+: first
+: second
exit status 0
Index: src/usr.bin/make/unit-tests/directive-ifmake.mk
diff -u src/usr.bin/make/unit-tests/directive-ifmake.mk:1.2 src/usr.bin/make/unit-tests/directive-ifmake.mk:1.3
--- src/usr.bin/make/unit-tests/directive-ifmake.mk:1.2 Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/directive-ifmake.mk Sat Aug 29 19:07:32 2020
@@ -1,8 +1,45 @@
-# $NetBSD: directive-ifmake.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: directive-ifmake.mk,v 1.3 2020/08/29 19:07:32 rillig Exp $
#
-# Tests for the .ifmake directive.
+# 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: Implementation
+# This is the most basic form.
+.ifmake first
+.info ok: positive condition works
+.else
+.warning positive condition fails
+.endif
-all:
- @:;
+# 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.
+.ifmake !first
+.warning unexpected
+.else
+.info ok: negation works
+.endif
+
+# See if the exclamation mark really means "not", or if it is just part of
+# the target name.
+.ifmake !!first
+.info ok: double negation works
+.else
+.warning double negation fails
+.endif
+
+# Multiple targets can be combined using the && and || operators.
+.ifmake first && second
+.info ok: both mentioned
+.else
+.warning && does not work as expected
+.endif
+
+# Negation also works in complex conditions.
+.ifmake first && !unmentioned
+.info ok: only those mentioned
+.else
+.warning && with ! does not work as expected
+.endif
+
+first second unmentioned:
+ : $@