Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[.joined/src/trunk]: .joined/src/usr.bin/make/unit-tests tests/make: test edg...



details:   https://anonhg.NetBSD.org/.joined/src/rev/090552d18b1b
branches:  trunk
changeset: 359394:090552d18b1b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jan 02 01:35:31 2022 +0000

description:
tests/make: test edge cases in .for loops

diffstat:

 usr.bin/make/unit-tests/directive-for.exp |   7 +++
 usr.bin/make/unit-tests/directive-for.mk  |  65 ++++++++++++++++++++++++++++--
 2 files changed, 67 insertions(+), 5 deletions(-)

diffs (107 lines):

diff -r ea2ab38dfa00 -r 090552d18b1b usr.bin/make/unit-tests/directive-for.exp
--- a/usr.bin/make/unit-tests/directive-for.exp Sun Jan 02 00:12:47 2022 +0000
+++ b/usr.bin/make/unit-tests/directive-for.exp Sun Jan 02 01:35:31 2022 +0000
@@ -19,6 +19,13 @@
 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
diff -r ea2ab38dfa00 -r 090552d18b1b usr.bin/make/unit-tests/directive-for.mk
--- a/usr.bin/make/unit-tests/directive-for.mk  Sun Jan 02 00:12:47 2022 +0000
+++ b/usr.bin/make/unit-tests/directive-for.mk  Sun Jan 02 01:35:31 2022 +0000
@@ -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 @@
 
 # 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 @@
 .  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'



Home | Main Index | Thread Index | Old Index