Module Name: src
Committed By: rillig
Date: Sun Jan 2 01:35:32 UTC 2022
Modified Files:
src/usr.bin/make/unit-tests: directive-for.exp directive-for.mk
Log Message:
tests/make: test edge cases in .for loops
To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/directive-for.exp
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/make/unit-tests/directive-for.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-for.exp
diff -u src/usr.bin/make/unit-tests/directive-for.exp:1.9 src/usr.bin/make/unit-tests/directive-for.exp:1.10
--- src/usr.bin/make/unit-tests/directive-for.exp:1.9 Tue Feb 23 15:19:41 2021
+++ src/usr.bin/make/unit-tests/directive-for.exp Sun Jan 2 01:35:31 2022
@@ -19,6 +19,13 @@ make: "directive-for.mk" line 148: outer
make: "directive-for.mk" line 154: Unknown modifier "Z"
make: "directive-for.mk" line 155: XXX: Not reached word1
make: "directive-for.mk" line 155: XXX: Not reached word3
+make: "directive-for.mk" line 160: no iteration variables in for
+make: "directive-for.mk" line 162: Missing argument for ".error"
+make: "directive-for.mk" line 163: for-less endfor
+make: "directive-for.mk" line 187: 1 open conditional
+make: "directive-for.mk" line 203: for-less endfor
+make: "directive-for.mk" line 204: if-less endif
+make: "directive-for.mk" line 212: if-less endif
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
Index: src/usr.bin/make/unit-tests/directive-for.mk
diff -u src/usr.bin/make/unit-tests/directive-for.mk:1.10 src/usr.bin/make/unit-tests/directive-for.mk:1.11
--- src/usr.bin/make/unit-tests/directive-for.mk:1.10 Sun Dec 27 09:58:35 2020
+++ src/usr.bin/make/unit-tests/directive-for.mk Sun Jan 2 01:35:31 2022
@@ -1,4 +1,4 @@
-# $NetBSD: directive-for.mk,v 1.10 2020/12/27 09:58:35 rillig Exp $
+# $NetBSD: directive-for.mk,v 1.11 2022/01/02 01:35:31 rillig Exp $
#
# Tests for the .for directive.
#
@@ -11,7 +11,7 @@
# Using the .for loop, lists of values can be produced.
# In simple cases, the :@var@${var}@ variable modifier can be used to
-# reach the same effects.
+# achieve the same effects.
#
.undef NUMBERS
.for num in 1 2 3
@@ -135,7 +135,7 @@ EXPANSION${plus}= value
# Ensure that braces and parentheses are properly escaped by the .for loop.
# Each line must print the same word 3 times.
-# See GetEscapes.
+# See ForLoop_SubstBody.
.for v in ( [ { ) ] } (()) [[]] {{}} )( ][ }{
. info $v ${v} $(v)
.endfor
@@ -155,5 +155,60 @@ var= outer
. info XXX: Not reached ${var}
.endfor
-all:
- @:;
+
+# An empty list of variables to the left of the 'in' is a parse error.
+.for in value # expect: no iteration variables in for
+# XXX: The loop body is evaluated once, even with the parse error above.
+. error # expect: Missing argument for ".error"
+.endfor # expect: for-less endfor
+
+# An empty list of iteration values to the right of the 'in' is accepted.
+# Unlike in the shell, it is not a parse error.
+.for var in
+. error
+.endfor
+
+# If the iteration values become empty after expanding the expressions, the
+# body of the loop is not evaluated. It is not a parse error.
+.for var in ${:U}
+. error
+.endfor
+
+
+# The loop body can be empty.
+.for var in 1 2 3
+.endfor
+
+
+# A mismatched .if inside a .for loop is detected each time when the loop body
+# is processed.
+.for var in value
+. if 0
+.endfor # expect: 1 open conditional
+
+# If there are no iteration values, the loop body is not processed, and the
+# check for mismatched conditionals is not performed.
+.for var in ${:U}
+. if 0
+.endfor
+
+
+# When a .for without the corresponding .endfor occurs in an inactive branch
+# of an .if, the .for directive is just skipped, it does not even need a
+# corresponding .endfor. In other words, the behavior of the parser depends
+# on the actual values of the conditions in the .if clauses.
+.if 0
+. for var in value # does not need a corresponding .endfor
+.endif
+.endfor # expect: for-less endfor
+.endif # expect: if-less endif
+
+
+# When a .for without the corresponding .endfor occurs in an active branch of
+# an .if, the parser just counts the number of .for and .endfor directives,
+# without looking at any other directives.
+.if 1
+. for var in value
+. endif # expect: if-less endif
+. endfor # no 'for-less endfor'
+.endif # no 'if-less endif'