Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make/unit-tests tests/make: clean up tests for .for ...



details:   https://anonhg.NetBSD.org/src/rev/635ea13dc295
branches:  trunk
changeset: 374715:635ea13dc295
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed May 10 13:03:06 2023 +0000

description:
tests/make: clean up tests for .for loops

Most of the tests from forloop.mk were already in directive-for.mk.

diffstat:

 distrib/sets/lists/tests/mi               |   6 +-
 usr.bin/make/unit-tests/Makefile          |   3 +-
 usr.bin/make/unit-tests/directive-for.exp |  21 ++++++-----
 usr.bin/make/unit-tests/directive-for.mk  |  39 ++++++++++++++++-----
 usr.bin/make/unit-tests/forloop.exp       |  20 -----------
 usr.bin/make/unit-tests/forloop.mk        |  53 -------------------------------
 6 files changed, 44 insertions(+), 98 deletions(-)

diffs (230 lines):

diff -r 0e41b7e1fd93 -r 635ea13dc295 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Wed May 10 12:30:27 2023 +0000
+++ b/distrib/sets/lists/tests/mi       Wed May 10 13:03:06 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1259 2023/05/09 20:14:28 sjg Exp $
+# $NetBSD: mi,v 1.1260 2023/05/10 13:03:06 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -5746,8 +5746,8 @@
 ./usr/tests/usr.bin/make/unit-tests/export-variants.mk                         tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/export.exp                                 tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/export.mk                                  tests-usr.bin-tests     compattestfile,atf
-./usr/tests/usr.bin/make/unit-tests/forloop.exp                                        tests-usr.bin-tests     compattestfile,atf
-./usr/tests/usr.bin/make/unit-tests/forloop.mk                                 tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/forloop.exp                                        tests-obsolete          obsolete,atf
+./usr/tests/usr.bin/make/unit-tests/forloop.mk                                 tests-obsolete          obsolete,atf
 ./usr/tests/usr.bin/make/unit-tests/forsubst.exp                               tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/forsubst.mk                                        tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/gnode-submake.exp                          tests-usr.bin-tests     compattestfile,atf
diff -r 0e41b7e1fd93 -r 635ea13dc295 usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile  Wed May 10 12:30:27 2023 +0000
+++ b/usr.bin/make/unit-tests/Makefile  Wed May 10 13:03:06 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.334 2023/05/09 20:14:27 sjg Exp $
+# $NetBSD: Makefile,v 1.335 2023/05/10 13:03:06 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -212,7 +212,6 @@ TESTS+=             export
 TESTS+=                export-all
 TESTS+=                export-env
 TESTS+=                export-variants
-TESTS+=                forloop
 TESTS+=                forsubst
 TESTS+=                gnode-submake
 TESTS+=                hanoi-include
diff -r 0e41b7e1fd93 -r 635ea13dc295 usr.bin/make/unit-tests/directive-for.exp
--- a/usr.bin/make/unit-tests/directive-for.exp Wed May 10 12:30:27 2023 +0000
+++ b/usr.bin/make/unit-tests/directive-for.exp Wed May 10 13:03:06 2023 +0000
@@ -15,16 +15,16 @@ make: "directive-for.mk" line 148: )( )(
 make: "directive-for.mk" line 148: ][ ][ ][
 make: "directive-for.mk" line 148: }{ }{ }{
 make: "directive-for.mk" line 168: invalid character ':' in .for loop variable name
-make: "directive-for.mk" line 174: invalid character '$' in .for loop variable name
-make: "directive-for.mk" line 179: invalid character '$' in .for loop variable name
-make: "directive-for.mk" line 188: Unknown modifier "Z"
-make: "directive-for.mk" line 189: XXX: Not reached word1
-make: "directive-for.mk" line 189: XXX: Not reached word3
-make: "directive-for.mk" line 196: no iteration variables in for
-make: "directive-for.mk" line 222: 1 open conditional
-make: "directive-for.mk" line 238: for-less endfor
-make: "directive-for.mk" line 239: if-less endif
-make: "directive-for.mk" line 247: if-less endif
+make: "directive-for.mk" line 175: invalid character '$' in .for loop variable name
+make: "directive-for.mk" line 187: invalid character '$' in .for loop variable name
+make: "directive-for.mk" line 198: Unknown modifier "Z"
+make: "directive-for.mk" line 199: XXX: Not reached word1
+make: "directive-for.mk" line 199: XXX: Not reached word3
+make: "directive-for.mk" line 206: no iteration variables in for
+make: "directive-for.mk" line 232: 1 open conditional
+make: "directive-for.mk" line 248: for-less endfor
+make: "directive-for.mk" line 249: if-less endif
+make: "directive-for.mk" line 257: if-less endif
 For: new loop 2
 For: end for 2
 For: end for 1
@@ -35,6 +35,7 @@ For: loop body:
    endfor
 For: end for 1
 For: loop body:
+make: "directive-for.mk" line 305: newline-item=(a)
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1
diff -r 0e41b7e1fd93 -r 635ea13dc295 usr.bin/make/unit-tests/directive-for.mk
--- a/usr.bin/make/unit-tests/directive-for.mk  Wed May 10 12:30:27 2023 +0000
+++ b/usr.bin/make/unit-tests/directive-for.mk  Wed May 10 13:03:06 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: directive-for.mk,v 1.19 2023/05/09 19:43:12 rillig Exp $
+# $NetBSD: directive-for.mk,v 1.20 2023/05/10 13:03:06 rillig Exp $
 #
 # Tests for the .for directive.
 #
@@ -60,7 +60,7 @@ WORDS+=       counted
 # A noticeable effect of this implementation technique is that the .for
 # iteration variables and the normal global variables live in separate
 # namespaces and do not influence each other.  The "scope" of the .for loop
-# variables is restricted to the current makefile, it does not each over to
+# variables is restricted to the current makefile, it does not reach over to
 # any included makefiles.
 var=   value before
 var2=  value before
@@ -160,24 +160,34 @@ EXPANSION${plus}= value
 # expect-12: ][ ][ ][
 # expect-13: }{ }{ }{
 
-# As of 2020-10-25, the variable names may contain arbitrary characters,
-# except for whitespace.  This allows for creative side effects. Hopefully
-# nobody is misusing this "feature".
+# Before 2023-05-09, the variable names could contain arbitrary characters,
+# except for whitespace, allowing for creative side effects, as usual for
+# arbitrary code injection.
 var=   outer
 # expect+1: invalid character ':' in .for loop variable name
 .for var:Q in value "quoted"
 .  info <${var}> <${var:Q}> <${var:Q:Q}>
 .endfor
-# The short expression '$$' is preserved, the long expressions are
-# substituted.
+
+# Before 2023-05-09, when variable names could contain '$', the short
+# expression '$$' was preserved, the long expressions were substituted.
 # expect+1: invalid character '$' in .for loop variable name
 .for $ in value
 .  info <$$> <${$}> <$($)>
 .endfor
-# From https://gnats.netbsd.org/53146.
+
+
+# https://gnats.netbsd.org/53146 mentions the idea of using a dynamic
+# variable name in .for loops, based on some other variable.  The .for loops
+# are already tricky enough to understand in detail, even without this
+# possibility, therefore the variable names are restricted to using harmless
+# characters only.
+INDIRECT=      direct
 # expect+1: invalid character '$' in .for loop variable name
-.for $(FOO) in a b
-.  info <$(FOO)> <$(foo)> <$($(FOO))>
+.for $(INDIRECT) in value
+# If the variable name could be chosen dynamically, the iteration variable
+# might have been 'direct', thereby expanding the expression '${direct}'.
+.  info <$(INDIRECT)> <$(direct)> <$($(INDIRECT))>
 .endfor
 
 
@@ -286,3 +296,12 @@ var=       outer
 .    error
 .  endif
 .endfor
+
+
+# Since at least 1993, iteration stops at the first newline.
+# Back then, the .newline variable didn't exist, therefore it was unlikely
+# that a newline ever occurred.
+.for var in a${.newline}b${.newline}c
+.  info newline-item=(${var})
+.endfor
+# expect-2: newline-item=(a)
diff -r 0e41b7e1fd93 -r 635ea13dc295 usr.bin/make/unit-tests/forloop.exp
--- a/usr.bin/make/unit-tests/forloop.exp       Wed May 10 12:30:27 2023 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-make: "forloop.mk" line 14: x=one
-make: "forloop.mk" line 14: x="two and three"
-make: "forloop.mk" line 14: x=four
-make: "forloop.mk" line 14: x="five"
-make: "forloop.mk" line 20: x=-I/this
-make: "forloop.mk" line 20: x=-I"This or that"
-make: "forloop.mk" line 20: x=-Ithat
-make: "forloop.mk" line 20: x="-DTHIS=\"this and that\""
-make: "forloop.mk" line 27: cfl=-I/this -I"This or that" -Ithat "-DTHIS=\"this and that\""
-make: "forloop.mk" line 41: newline-item=(a)
-make: "forloop.mk" line 47: a=one b="two and three"
-make: "forloop.mk" line 47: a=four b="five"
-make: "forloop.mk" line 47: a=ONE b="TWO AND THREE"
-make: "forloop.mk" line 47: a=FOUR b="FIVE"
-We expect an error next:
-make: "forloop.mk" line 46: Wrong number of words (9) in .for substitution list with 2 variables
-make: Fatal errors encountered -- cannot continue
-make: stopped in unit-tests
-OK
-exit status 0
diff -r 0e41b7e1fd93 -r 635ea13dc295 usr.bin/make/unit-tests/forloop.mk
--- a/usr.bin/make/unit-tests/forloop.mk        Wed May 10 12:30:27 2023 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,53 +0,0 @@
-# $NetBSD: forloop.mk,v 1.7 2020/11/03 17:37:57 rillig Exp $
-
-all: for-loop
-
-LIST=  one "two and three" four "five"
-
-.if make(for-fail)
-for-fail:
-
-XTRA_LIST=     xtra
-.else
-
-.  for x in ${LIST}
-.    info x=$x
-.  endfor
-
-CFL=   -I/this -I"This or that" -Ithat "-DTHIS=\"this and that\""
-cfl=
-.  for x in ${CFL}
-.    info x=$x
-.    if empty(cfl)
-cfl=   $x
-.    else
-cfl+=  $x
-.    endif
-.  endfor
-.  info cfl=${cfl}
-
-.  if ${cfl} != ${CFL}
-.    error ${.newline}${cfl} != ${.newline}${CFL}
-.  endif
-
-.  for a b in ${EMPTY}
-.    info a=$a b=$b
-.  endfor
-
-# Since at least 1993, iteration stops at the first newline.
-# Back then, the .newline variable didn't exist, therefore it was unlikely
-# that a newline ever occurred.
-.  for var in a${.newline}b${.newline}c
-.    info newline-item=(${var})
-.  endfor
-
-.endif # for-fail
-
-.for a b in ${LIST} ${LIST:tu} ${XTRA_LIST}
-.  info a=$a b=$b
-.endfor
-
-for-loop:
-       @echo We expect an error next:
-       @(cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} for-fail) && \
-       { echo "Oops that should have failed!"; exit 1; } || echo OK



Home | Main Index | Thread Index | Old Index