Module Name: src
Committed By: rillig
Date: Sat Aug 29 18:50:25 UTC 2020
Modified Files:
src/distrib/sets/lists/tests: mi
src/usr.bin/make/unit-tests: Makefile directive-else.exp
directive-else.mk
Added Files:
src/usr.bin/make/unit-tests: directive-for-generating-endif.exp
directive-for-generating-endif.mk
Log Message:
make(1): add tests for .else and .for + .endif
To generate a diff of this commit:
cvs rdiff -u -r1.913 -r1.914 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.126 -r1.127 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/directive-else.exp
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/directive-else.mk
cvs rdiff -u -r0 -r1.1 \
src/usr.bin/make/unit-tests/directive-for-generating-endif.exp \
src/usr.bin/make/unit-tests/directive-for-generating-endif.mk
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.913 src/distrib/sets/lists/tests/mi:1.914
--- src/distrib/sets/lists/tests/mi:1.913 Sat Aug 29 14:47:26 2020
+++ src/distrib/sets/lists/tests/mi Sat Aug 29 18:50:25 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.913 2020/08/29 14:47:26 rillig Exp $
+# $NetBSD: mi,v 1.914 2020/08/29 18:50:25 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -4730,6 +4730,8 @@
./usr/tests/usr.bin/make/unit-tests/directive-export-literal.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/directive-export.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/directive-export.mk tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/directive-for-generating-endif.exp tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/directive-for-generating-endif.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/directive-if.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/directive-if.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/directive-ifdef.exp tests-usr.bin-tests compattestfile,atf
Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.126 src/usr.bin/make/unit-tests/Makefile:1.127
--- src/usr.bin/make/unit-tests/Makefile:1.126 Sat Aug 29 14:47:26 2020
+++ src/usr.bin/make/unit-tests/Makefile Sat Aug 29 18:50:25 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.126 2020/08/29 14:47:26 rillig Exp $
+# $NetBSD: Makefile,v 1.127 2020/08/29 18:50:25 rillig Exp $
#
# Unit tests for make(1)
#
@@ -132,6 +132,7 @@ TESTS+= directive-error
TESTS+= directive-export
TESTS+= directive-export-env
TESTS+= directive-export-literal
+TESTS+= directive-for-generating-endif
TESTS+= directive-if
TESTS+= directive-ifdef
TESTS+= directive-ifmake
Index: src/usr.bin/make/unit-tests/directive-else.exp
diff -u src/usr.bin/make/unit-tests/directive-else.exp:1.1 src/usr.bin/make/unit-tests/directive-else.exp:1.2
--- src/usr.bin/make/unit-tests/directive-else.exp:1.1 Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/directive-else.exp Sat Aug 29 18:50:25 2020
@@ -1 +1,8 @@
-exit status 0
+make: "directive-else.mk" line 10: ok
+make: "directive-else.mk" line 14: ok
+make: "directive-else.mk" line 20: if-less else
+make: "directive-else.mk" line 26: ok
+make: "directive-else.mk" line 27: warning: extra else
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
Index: src/usr.bin/make/unit-tests/directive-else.mk
diff -u src/usr.bin/make/unit-tests/directive-else.mk:1.2 src/usr.bin/make/unit-tests/directive-else.mk:1.3
--- src/usr.bin/make/unit-tests/directive-else.mk:1.2 Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/directive-else.mk Sat Aug 29 18:50:25 2020
@@ -1,8 +1,32 @@
-# $NetBSD: directive-else.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: directive-else.mk,v 1.3 2020/08/29 18:50:25 rillig Exp $
#
# Tests for the .else directive.
-# TODO: Implementation
+# The .else directive does not take any arguments.
+# As of 2020-08-29, make doesn't warn about this.
+.if 0
+.warning must not be reached
+.else 123
+.info ok
+.endif
+
+.if 1
+.info ok
+.else 123
+.warning must not be reached
+.endif
+
+# An .else without a corresponding .if is an error.
+.else
+
+# Accidental extra .else directives are detected too.
+.if 0
+.warning must not be reached
+.else
+.info ok
+.else
+.info After an extra .else, everything is skipped.
+.endif
all:
@:;
Added files:
Index: src/usr.bin/make/unit-tests/directive-for-generating-endif.exp
diff -u /dev/null src/usr.bin/make/unit-tests/directive-for-generating-endif.exp:1.1
--- /dev/null Sat Aug 29 18:50:25 2020
+++ src/usr.bin/make/unit-tests/directive-for-generating-endif.exp Sat Aug 29 18:50:25 2020
@@ -0,0 +1,7 @@
+make: "directive-for-generating-endif.mk" line 21: if-less endif
+make: "directive-for-generating-endif.mk" line 21: if-less endif
+make: "directive-for-generating-endif.mk" line 21: if-less endif
+make: "directive-for-generating-endif.mk" line 0: 3 open conditionals
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
Index: src/usr.bin/make/unit-tests/directive-for-generating-endif.mk
diff -u /dev/null src/usr.bin/make/unit-tests/directive-for-generating-endif.mk:1.1
--- /dev/null Sat Aug 29 18:50:25 2020
+++ src/usr.bin/make/unit-tests/directive-for-generating-endif.mk Sat Aug 29 18:50:25 2020
@@ -0,0 +1,25 @@
+# $NetBSD: directive-for-generating-endif.mk,v 1.1 2020/08/29 18:50:25 rillig Exp $
+#
+# Test whether a .for loop can be used to generate multiple .endif
+# directives to close nested .if directives. Depending on the exact
+# implementation, this might have been possible.
+#
+# If it were possible, the 3 .if directives would perfectly match the
+# 3 .endif directives generated by the .for loop.
+#
+# After the "included file" from the .for loop, the 3 .if directives
+# are still open.
+#
+# See For_Run and ParseReadLine. Each .for loop is treated like a separately
+# included file, and in each included file the .if/.endif directives must be
+# balanced.
+
+.if 1
+. if 2
+. if 3
+.for i in 3 2 1
+.endif
+.endfor
+
+all:
+ @:;