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 make(1): add test for recursive vari...



details:   https://anonhg.NetBSD.org/src/rev/4bc4050dab9a
branches:  trunk
changeset: 945485:4bc4050dab9a
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Oct 31 11:30:56 2020 +0000

description:
make(1): add test for recursive variable expressions

diffstat:

 distrib/sets/lists/tests/mi               |   4 ++-
 usr.bin/make/unit-tests/Makefile          |   3 +-
 usr.bin/make/unit-tests/var-recursive.exp |   9 ++++++
 usr.bin/make/unit-tests/var-recursive.mk  |  41 +++++++++++++++++++++++++++++++
 4 files changed, 55 insertions(+), 2 deletions(-)

diffs (93 lines):

diff -r 6b2b32dff3ee -r 4bc4050dab9a distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sat Oct 31 11:06:24 2020 +0000
+++ b/distrib/sets/lists/tests/mi       Sat Oct 31 11:30:56 2020 +0000
@@ -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
diff -r 6b2b32dff3ee -r 4bc4050dab9a usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile  Sat Oct 31 11:06:24 2020 +0000
+++ b/usr.bin/make/unit-tests/Makefile  Sat Oct 31 11:30:56 2020 +0000
@@ -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-expand
 TESTS+=                var-op-shell
 TESTS+=                var-op-sunsh
+TESTS+=                var-recursive
 TESTS+=                varcmd
 TESTS+=                vardebug
 TESTS+=                varfind
diff -r 6b2b32dff3ee -r 4bc4050dab9a usr.bin/make/unit-tests/var-recursive.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/var-recursive.exp Sat Oct 31 11:30:56 2020 +0000
@@ -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
diff -r 6b2b32dff3ee -r 4bc4050dab9a usr.bin/make/unit-tests/var-recursive.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/var-recursive.mk  Sat Oct 31 11:30:56 2020 +0000
@@ -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:



Home | Main Index | Thread Index | Old Index