make(1): move tests from cond2.mk to varmod-ifelse.mk

This commit is contained in:
rillig 2020-10-23 14:24:51 +00:00
parent 48d8e29d07
commit 4fa705e6c5
5 changed files with 52 additions and 41 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.945 2020/10/23 06:18:23 rillig Exp $
# $NetBSD: mi,v 1.946 2020/10/23 14:24:51 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@ -4617,8 +4617,8 @@
./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
./usr/tests/usr.bin/make/unit-tests/cond2.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/cond2.exp obsolete-tests obsolete
./usr/tests/usr.bin/make/unit-tests/cond2.mk obsolete-tests obsolete
./usr/tests/usr.bin/make/unit-tests/counter-append.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/counter-append.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/counter.exp tests-usr.bin-tests compattestfile,atf

View File

@ -1,7 +0,0 @@
make: Bad conditional expression ` == "empty"' in == "empty"?oops:ok
make: "cond2.mk" line 13: Malformed conditional ({TEST_TYPO} == "Ok")
TEST_NOT_SET is empty or not defined
make: "cond2.mk" line 20: Malformed conditional (${TEST_NOT_SET} == "empty")
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1

View File

@ -1,29 +0,0 @@
# $Id: cond2.mk,v 1.2 2015/12/02 00:28:24 sjg Exp $
TEST_UNAME_S= NetBSD
# this should be ok
X:= ${${TEST_UNAME_S} == "NetBSD":?Ok:fail}
.if $X == "Ok"
Y= good
.endif
# expect: Bad conditional expression ` == "empty"' in == "empty"?oops:ok
X:= ${${TEST_NOT_SET} == "empty":?oops:ok}
# expect: Malformed conditional ({TEST_TYPO} == "Ok")
.if {TEST_TYPO} == "Ok"
Y= oops
.endif
.if empty(TEST_NOT_SET)
Y!= echo TEST_NOT_SET is empty or not defined >&2; echo
.endif
# expect: Malformed conditional (${TEST_NOT_SET} == "empty")
.if ${TEST_NOT_SET} == "empty"
Y= oops
.endif
.if defined(.NDEF) && ${.NDEF} > 0
Z= yes
.endif
all:
@echo $@

View File

@ -1 +1,6 @@
exit status 0
make: Bad conditional expression `variable expression == "literal"' in variable expression == "literal"?bad:bad
make: "varmod-ifelse.mk" line 28: Malformed conditional (${${:Uvariable expression} == "literal":?bad:bad})
make: Bad conditional expression ` == ""' in == ""?oops:oops
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1

View File

@ -1,10 +1,52 @@
# $NetBSD: varmod-ifelse.mk,v 1.4 2020/10/09 07:03:20 rillig Exp $
# $NetBSD: varmod-ifelse.mk,v 1.5 2020/10/23 14:24:51 rillig Exp $
#
# Tests for the ${cond:?then:else} variable modifier, which evaluates either
# the then-expression or the else-expression, depending on the condition.
#
# The modifier was added on 1998-04-01.
#
# Until 2015-10-11, the modifier always evaluated both the "then" and the
# "else" expressions.
# TODO: Implementation
# The variable name of the expression is expanded and then taken as the
# condition. In this case it becomes:
#
# variable expression == "variable expression"
#
# This confuses the parser, which expects an operator instead of the bare
# word "expression". If the name were expanded lazily, everything would be
# fine since the condition would be:
#
# ${:Uvariable expression} == "literal"
#
# Evaluating the variable name lazily would require additional code in
# Var_Parse and ParseVarname, it would be more useful and predictable
# though.
.if ${${:Uvariable expression} == "literal":?bad:bad}
. error
.else
. error
.endif
# In a variable assignment, undefined variables are not an error.
# Because of the early expansion, the whole condition evaluates to
# ' == ""' though, which cannot be parsed because the left-hand side looks
# empty.
COND:= ${${UNDEF} == "":?bad-assign:bad-assign}
# In a condition, undefined variables generate a "Malformed conditional"
# error. That error message is wrong though. In lint mode, the correct
# "Undefined variable" error message is generated.
# The difference to the ':=' variable assignment is the additional
# "Malformed conditional" error message.
.if ${${UNDEF} == "":?bad-cond:bad-cond}
. error
.else
. error
.endif
# When the :? is parsed, it is greedy. The else branch spans all the
# text, up until the closing character '}', even if the text looks like
# another modifier.