Module Name: src
Committed By: rillig
Date: Sun Oct 4 22:41:18 UTC 2020
Modified Files:
src/usr.bin/make/unit-tests: directive-ifndef.exp directive-ifndef.mk
directive-ifnmake.exp directive-ifnmake.mk
Log Message:
make(1): add tests for .ifndef and .ifnmake
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/directive-ifndef.exp \
src/usr.bin/make/unit-tests/directive-ifnmake.exp
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/directive-ifndef.mk \
src/usr.bin/make/unit-tests/directive-ifnmake.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/directive-ifndef.exp
diff -u src/usr.bin/make/unit-tests/directive-ifndef.exp:1.1 src/usr.bin/make/unit-tests/directive-ifndef.exp:1.2
--- src/usr.bin/make/unit-tests/directive-ifndef.exp:1.1 Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/directive-ifndef.exp Sun Oct 4 22:41:18 2020
@@ -1 +1,2 @@
+make: "directive-ifndef.mk" line 10: guarded section
exit status 0
Index: src/usr.bin/make/unit-tests/directive-ifnmake.exp
diff -u src/usr.bin/make/unit-tests/directive-ifnmake.exp:1.1 src/usr.bin/make/unit-tests/directive-ifnmake.exp:1.2
--- src/usr.bin/make/unit-tests/directive-ifnmake.exp:1.1 Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/directive-ifnmake.exp Sun Oct 4 22:41:18 2020
@@ -1 +1,3 @@
+Don't forget to run the tests (1)
+Running the tests
exit status 0
Index: src/usr.bin/make/unit-tests/directive-ifndef.mk
diff -u src/usr.bin/make/unit-tests/directive-ifndef.mk:1.2 src/usr.bin/make/unit-tests/directive-ifndef.mk:1.3
--- src/usr.bin/make/unit-tests/directive-ifndef.mk:1.2 Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/directive-ifndef.mk Sun Oct 4 22:41:18 2020
@@ -1,8 +1,24 @@
-# $NetBSD: directive-ifndef.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: directive-ifndef.mk,v 1.3 2020/10/04 22:41:18 rillig Exp $
#
-# Tests for the .ifndef directive.
+# Tests for the .ifndef directive, which can be used for multiple-inclusion
+# guards. In contrast to C, where #ifndef and #define nicely line up the
+# macro name, there is no such syntax in make. Therefore, it is more
+# common to use .if !defined(GUARD) instead.
-# TODO: Implementation
+.ifndef GUARD
+GUARD= # defined
+.info guarded section
+.endif
+
+.ifndef GUARD
+GUARD= # defined
+.info guarded section
+.endif
+
+.if !defined(GUARD)
+GUARD= # defined
+.info guarded section
+.endif
all:
@:;
Index: src/usr.bin/make/unit-tests/directive-ifnmake.mk
diff -u src/usr.bin/make/unit-tests/directive-ifnmake.mk:1.2 src/usr.bin/make/unit-tests/directive-ifnmake.mk:1.3
--- src/usr.bin/make/unit-tests/directive-ifnmake.mk:1.2 Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/directive-ifnmake.mk Sun Oct 4 22:41:18 2020
@@ -1,8 +1,22 @@
-# $NetBSD: directive-ifnmake.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: directive-ifnmake.mk,v 1.3 2020/10/04 22:41:18 rillig Exp $
#
-# Tests for the .ifnmake directive.
-
-# TODO: Implementation
+# Tests for the .ifnmake directive, which evaluates to true if its argument
+# is _not_ listed in the command-line targets to be created.
all:
@:;
+
+.ifnmake(test)
+.BEGIN:
+ @echo "Don't forget to run the tests (1)"
+.endif
+
+.MAKEFLAGS: test
+
+.ifnmake(test)
+.BEGIN:
+ @echo "Don't forget to run the tests (2)"
+.endif
+
+test:
+ @echo "Running the tests"