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 undefined expr...



details:   https://anonhg.NetBSD.org/src/rev/57e41297030f
branches:  trunk
changeset: 954965:57e41297030f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Sep 14 06:44:50 2020 +0000

description:
make(1): add test for undefined expressions in conditions in lint mode

diffstat:

 distrib/sets/lists/tests/mi                 |   4 +-
 usr.bin/make/unit-tests/Makefile            |   3 +-
 usr.bin/make/unit-tests/cond-undef-lint.exp |   8 +++
 usr.bin/make/unit-tests/cond-undef-lint.mk  |  68 +++++++++++++++++++++++++++++
 4 files changed, 81 insertions(+), 2 deletions(-)

diffs (119 lines):

diff -r 4b706102765a -r 57e41297030f distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Mon Sep 14 06:22:59 2020 +0000
+++ b/distrib/sets/lists/tests/mi       Mon Sep 14 06:44:50 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.923 2020/09/14 06:22:59 rillig Exp $
+# $NetBSD: mi,v 1.924 2020/09/14 06:44:50 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4603,6 +4603,8 @@
 ./usr/tests/usr.bin/make/unit-tests/cond-token-string.mk                       tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond-token-var.exp                         tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond-token-var.mk                          tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-undef-lint.exp                                tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-undef-lint.mk                         tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond1.exp                                  tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond1.mk                                   tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond2.exp                                  tests-usr.bin-tests     compattestfile,atf
diff -r 4b706102765a -r 57e41297030f usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile  Mon Sep 14 06:22:59 2020 +0000
+++ b/usr.bin/make/unit-tests/Makefile  Mon Sep 14 06:44:50 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.141 2020/09/14 06:22:59 rillig Exp $
+# $NetBSD: Makefile,v 1.142 2020/09/14 06:44:50 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -67,6 +67,7 @@
 TESTS+=                cond-token-plain
 TESTS+=                cond-token-string
 TESTS+=                cond-token-var
+TESTS+=                cond-undef-lint
 TESTS+=                cond1
 TESTS+=                cond2
 TESTS+=                counter
diff -r 4b706102765a -r 57e41297030f usr.bin/make/unit-tests/cond-undef-lint.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/cond-undef-lint.exp       Mon Sep 14 06:44:50 2020 +0000
@@ -0,0 +1,8 @@
+make: "cond-undef-lint.mk" line 20: Variable "UNDEF" is undefined
+make: "cond-undef-lint.mk" line 35: Variable "UNDEF" is undefined
+make: "cond-undef-lint.mk" line 35: Variable "VAR." is undefined
+make: "cond-undef-lint.mk" line 42: Variable "VAR.defined" is undefined
+make: "cond-undef-lint.mk" line 66: Variable "NESTED_UNDEF" is undefined
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff -r 4b706102765a -r 57e41297030f usr.bin/make/unit-tests/cond-undef-lint.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/cond-undef-lint.mk        Mon Sep 14 06:44:50 2020 +0000
@@ -0,0 +1,68 @@
+# $NetBSD: cond-undef-lint.mk,v 1.1 2020/09/14 06:44:50 rillig Exp $
+#
+# Tests for defined and undefined variables in .if conditions, in lint mode.
+#
+# As of 2020-09-14, lint mode contains experimental code for printing
+# accurate error messages in case of undefined variables, instead of the
+# wrong "Malformed condition".
+
+.MAKEFLAGS: -dL
+
+# DEF is defined, UNDEF is not.
+DEF=           defined
+
+# An expression based on a defined variable is fine.
+.if !${DEF}
+.  error
+.endif
+
+# Since the condition fails to evaluate, neither of the branches is taken.
+.if ${UNDEF}
+.  error
+.else
+.  error
+.endif
+
+# The variable name depends on the undefined variable, which is probably a
+# mistake.  The variable UNDEF, as used here, can be easily turned into
+# an expression that is always defined, using the :U modifier.
+#
+# The outer expression does not generate an error message since there was
+# already an error evaluating this variable's name.
+#
+# TODO: Suppress the error message "Variable VAR. is undefined".  That part
+# of the expression must not be evaluated at all.
+.if ${VAR.${UNDEF}}
+.  error
+.else
+.  error
+.endif
+
+# The variable VAR.defined is not defined and thus generates an error message.
+.if ${VAR.${DEF}}
+.  error
+.else
+.  error
+.endif
+
+
+# Variables that are referenced indirectly may be undefined in a condition.
+#
+# A practical example for this is CFLAGS, which consists of CWARNS, COPTS
+# and a few others.  Just because these nested variables are not defined,
+# this does not make the condition invalid.
+#
+# The crucial point is that at the point where the variable appears in the
+# condition, there is no way to influence the definedness of the nested
+# variables.  In particular, there is no modifier that would turn undefined
+# nested variables into empty strings, as an equivalent to the :U modifier.
+INDIRECT=      ${NESTED_UNDEF} ${NESTED_DEF}
+NESTED_DEF=    nested-defined
+
+# Since NESTED_UNDEF is not controllable at this point, it must not generate
+# an error message.  This condition should generate no error message at all.
+#
+# TODO: Suppress the error message.
+.if !${INDIRECT}
+.  error
+.endif



Home | Main Index | Thread Index | Old Index