Module Name:    src
Committed By:   rillig
Date:           Wed Dec  6 22:28:20 UTC 2023

Modified Files:
        src/usr.bin/make/unit-tests: directive-for.exp directive-for.mk

Log Message:
tests/make: show how global variables are unaffected by .for loops


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/make/unit-tests/directive-for.exp
cvs rdiff -u -r1.23 -r1.24 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.20 src/usr.bin/make/unit-tests/directive-for.exp:1.21
--- src/usr.bin/make/unit-tests/directive-for.exp:1.20	Thu Oct 19 18:24:33 2023
+++ src/usr.bin/make/unit-tests/directive-for.exp	Wed Dec  6 22:28:20 2023
@@ -17,15 +17,15 @@ make: "directive-for.mk" line 146: }{ }{
 make: "directive-for.mk" line 166: invalid character ':' in .for loop variable name
 make: "directive-for.mk" line 173: invalid character '$' in .for loop variable name
 make: "directive-for.mk" line 185: invalid character '$' in .for loop variable name
-make: "directive-for.mk" line 196: Unknown modifier "Z"
-make: "directive-for.mk" line 197: XXX: Should not reach word1
-make: "directive-for.mk" line 197: XXX: Should not reach before--after
-make: "directive-for.mk" line 197: XXX: Should not reach word3
-make: "directive-for.mk" line 205: no iteration variables in for
-make: "directive-for.mk" line 231: 1 open conditional
-make: "directive-for.mk" line 247: for-less endfor
-make: "directive-for.mk" line 248: if-less endif
-make: "directive-for.mk" line 256: if-less endif
+make: "directive-for.mk" line 210: Unknown modifier "Z"
+make: "directive-for.mk" line 211: XXX: Should not reach word1
+make: "directive-for.mk" line 211: XXX: Should not reach before--after
+make: "directive-for.mk" line 211: XXX: Should not reach word3
+make: "directive-for.mk" line 219: no iteration variables in for
+make: "directive-for.mk" line 245: 1 open conditional
+make: "directive-for.mk" line 261: for-less endfor
+make: "directive-for.mk" line 262: if-less endif
+make: "directive-for.mk" line 270: if-less endif
 For: new loop 2
 For: end for 2
 For: end for 1
@@ -36,7 +36,7 @@ For: loop body with outer = o:
    endfor
 For: end for 1
 For: loop body with inner = i:
-make: "directive-for.mk" line 304: newline-item=(a)
+make: "directive-for.mk" line 318: newline-item=(a)
 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.23 src/usr.bin/make/unit-tests/directive-for.mk:1.24
--- src/usr.bin/make/unit-tests/directive-for.mk:1.23	Thu Oct 19 18:24:33 2023
+++ src/usr.bin/make/unit-tests/directive-for.mk	Wed Dec  6 22:28:20 2023
@@ -1,4 +1,4 @@
-# $NetBSD: directive-for.mk,v 1.23 2023/10/19 18:24:33 rillig Exp $
+# $NetBSD: directive-for.mk,v 1.24 2023/12/06 22:28:20 rillig Exp $
 #
 # Tests for the .for directive.
 #
@@ -25,7 +25,7 @@ NUMBERS+=	${num}
 
 
 # The .for loop also works for multiple iteration variables.
-# This is something that the modifier :@ cannot do.
+# This is something that the modifier :@ cannot do as easily.
 .for name value in VARNAME value NAME2 value2
 ${name}=	${value}
 .endfor
@@ -189,6 +189,20 @@ INDIRECT=	direct
 .endfor
 
 
+# Regular global variables and the "variables" from the .for loop don't
+# interfere with each other.  In the following snippet, the variable 'DIRECT'
+# is used both as a global variable, as well as an iteration variable in the
+# .for loop.  The expression '${INDIRECT}' refers to the global variable, not
+# to the one from the .for loop.
+DIRECT=		global
+INDIRECT=	${DIRECT}
+.for DIRECT in iteration
+.  if "${DIRECT} ${INDIRECT}" != "iteration global"
+.    error
+.  endif
+.endfor
+
+
 # XXX: A parse error or evaluation error in the items of the .for loop
 # should skip the whole loop.  As of 2023-05-09, the loop is expanded as
 # usual.

Reply via email to