Module Name: src Committed By: rillig Date: Sat Oct 31 11:30:57 UTC 2020
Modified Files: src/distrib/sets/lists/tests: mi src/usr.bin/make/unit-tests: Makefile Added Files: src/usr.bin/make/unit-tests: var-recursive.exp var-recursive.mk Log Message: make(1): add test for recursive variable expressions To generate a diff of this commit: cvs rdiff -u -r1.953 -r1.954 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.178 -r1.179 src/usr.bin/make/unit-tests/Makefile cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/var-recursive.exp \ src/usr.bin/make/unit-tests/var-recursive.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.953 src/distrib/sets/lists/tests/mi:1.954 --- src/distrib/sets/lists/tests/mi:1.953 Sat Oct 31 11:06:24 2020 +++ src/distrib/sets/lists/tests/mi Sat Oct 31 11:30:56 2020 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.953 2020/10/31 11:06:24 rillig Exp $ +# $NetBSD: mi,v 1.954 2020/10/31 11:30:56 rillig Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -5300,6 +5300,8 @@ ./usr/tests/usr.bin/make/unit-tests/var-op-sunsh.mk tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/var-op.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/var-op.mk tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/make/unit-tests/var-recursive.exp tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/make/unit-tests/var-recursive.mk tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/varcmd.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/varcmd.mk tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/vardebug.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.178 src/usr.bin/make/unit-tests/Makefile:1.179 --- src/usr.bin/make/unit-tests/Makefile:1.178 Sat Oct 31 11:06:24 2020 +++ src/usr.bin/make/unit-tests/Makefile Sat Oct 31 11:30:57 2020 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.178 2020/10/31 11:06:24 rillig Exp $ +# $NetBSD: Makefile,v 1.179 2020/10/31 11:30:57 rillig Exp $ # # Unit tests for make(1) # @@ -278,6 +278,7 @@ TESTS+= var-op-default TESTS+= var-op-expand TESTS+= var-op-shell TESTS+= var-op-sunsh +TESTS+= var-recursive TESTS+= varcmd TESTS+= vardebug TESTS+= varfind Added files: Index: src/usr.bin/make/unit-tests/var-recursive.exp diff -u /dev/null src/usr.bin/make/unit-tests/var-recursive.exp:1.1 --- /dev/null Sat Oct 31 11:30:57 2020 +++ src/usr.bin/make/unit-tests/var-recursive.exp Sat Oct 31 11:30:57 2020 @@ -0,0 +1,9 @@ +make: "var-recursive.mk" line 20: still there +Variable DIRECT is recursive. + +make: stopped in unit-tests +Variable INDIRECT1 is recursive. + +make: stopped in unit-tests +make: "var-recursive.mk" line 35: ok +exit status 0 Index: src/usr.bin/make/unit-tests/var-recursive.mk diff -u /dev/null src/usr.bin/make/unit-tests/var-recursive.mk:1.1 --- /dev/null Sat Oct 31 11:30:57 2020 +++ src/usr.bin/make/unit-tests/var-recursive.mk Sat Oct 31 11:30:57 2020 @@ -0,0 +1,41 @@ +# $NetBSD: var-recursive.mk,v 1.1 2020/10/31 11:30:57 rillig Exp $ +# +# Tests for variable expressions that refer to themselves and thus +# cannot be evaluated. + +TESTS= direct indirect conditional + +# Since make exits immediately when it detects a recursive expression, +# the actual tests are run in sub-makes. +TEST?= # none +.if ${TEST} == "" +all: +.for test in ${TESTS} + @${.MAKE} -f ${MAKEFILE} TEST=${test} || : +.endfor + +.elif ${TEST} == direct + +DIRECT= ${DIRECT} # Defining a recursive variable is not yet an error. +. info still there # Therefore this line is printed. +. info ${DIRECT} # But expanding the variable is an error. + +.elif ${TEST} == indirect + +# The chain of variables that refer to each other may be long. +INDIRECT1= ${INDIRECT2} +INDIRECT2= ${INDIRECT1} +. info ${INDIRECT1} + +.elif ${TEST} == conditional + +# The variable refers to itself, but only in the branch of a condition that +# is never satisfied and is thus not evaluated. +CONDITIONAL= ${1:?ok:${CONDITIONAL}} +. info ${CONDITIONAL} + +.else +. error Unknown test "${TEST}" +.endif + +all: