make(1): add more tests for tokens in conditionals

This commit is contained in:
rillig 2021-01-21 00:38:28 +00:00
parent 8c601f6c5a
commit 78ff715cb8
4 changed files with 119 additions and 8 deletions

View File

@ -26,4 +26,16 @@ CondParser_Eval: ${:Uvar}&&name != "var&&name"
lhs = "var&&name", rhs = "var&&name", op = !=
CondParser_Eval: ${:Uvar}||name != "var||name"
lhs = "var||name", rhs = "var||name", op = !=
CondParser_Eval: bare
make: "cond-token-plain.mk" line 102: A bare word is treated like defined(...), and the variable 'bare' is not defined.
CondParser_Eval: VAR
make: "cond-token-plain.mk" line 107: A bare word is treated like defined(...).
CondParser_Eval: V${:UA}R
make: "cond-token-plain.mk" line 114: ok
CondParser_Eval: V${UNDEF}AR
make: "cond-token-plain.mk" line 122: Undefined variables in bare words expand to an empty string.
CondParser_Eval: 0${:Ux00}
make: "cond-token-plain.mk" line 130: Numbers can be composed from literals and variable expressions.
CondParser_Eval: 0${:Ux01}
make: "cond-token-plain.mk" line 134: Numbers can be composed from literals and variable expressions.
exit status 0

View File

@ -1,4 +1,4 @@
# $NetBSD: cond-token-plain.mk,v 1.6 2020/11/15 14:58:14 rillig Exp $
# $NetBSD: cond-token-plain.mk,v 1.7 2021/01/21 00:38:28 rillig Exp $
#
# Tests for plain tokens (that is, string literals without quotes)
# in .if conditions.
@ -93,5 +93,51 @@
. error
.endif
# A bare word may appear alone in a condition, without any comparison
# operator. It is implicitly converted into defined(bare).
.if bare
. error
.else
. info A bare word is treated like defined(...), and the variable $\
'bare' is not defined.
.endif
VAR= defined
.if VAR
. info A bare word is treated like defined(...).
.else
. error
.endif
# Bare words may be intermixed with variable expressions.
.if V${:UA}R
. info ok
.else
. error
.endif
# In bare words, even undefined variables are allowed. Without the bare
# words, undefined variables are not allowed. That feels inconsistent.
.if V${UNDEF}AR
. info Undefined variables in bare words expand to an empty string.
.else
. error
.endif
.if 0${:Ux00}
. error
.else
. info Numbers can be composed from literals and variable expressions.
.endif
.if 0${:Ux01}
. info Numbers can be composed from literals and variable expressions.
.else
. error
.endif
# See cond-token-string.mk for similar tests where the condition is enclosed
# in "quotes".
all:
@:;

View File

@ -1,8 +1,18 @@
make: "cond-token-string.mk" line 9: Unknown modifier 'Z'
make: "cond-token-string.mk" line 9: Malformed conditional ("" != "${:Uvalue:Z}")
make: "cond-token-string.mk" line 18: xvalue is not defined.
make: "cond-token-string.mk" line 24: Malformed conditional (x${:Uvalue} == "")
make: "cond-token-string.mk" line 33: Expected.
make: "cond-token-string.mk" line 13: Unknown modifier 'Z'
make: "cond-token-string.mk" line 13: Malformed conditional ("" != "${:Uvalue:Z}")
make: "cond-token-string.mk" line 22: xvalue is not defined.
make: "cond-token-string.mk" line 28: Malformed conditional (x${:Uvalue} == "")
make: "cond-token-string.mk" line 37: Expected.
CondParser_Eval: "UNDEF"
make: "cond-token-string.mk" line 46: The string literal "UNDEF" is not empty.
CondParser_Eval: " "
make: "cond-token-string.mk" line 55: The string literal " " is not empty, even though it consists of whitespace only.
CondParser_Eval: "${UNDEF}"
make: "cond-token-string.mk" line 64: An undefined variable in quotes expands to an empty string, which then evaluates to false.
CondParser_Eval: "${:Uvalue}"
make: "cond-token-string.mk" line 68: A nonempty variable expression evaluates to true.
CondParser_Eval: "${:U}"
make: "cond-token-string.mk" line 76: An empty variable evaluates to false.
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1

View File

@ -1,6 +1,10 @@
# $NetBSD: cond-token-string.mk,v 1.3 2020/11/10 22:23:37 rillig Exp $
# $NetBSD: cond-token-string.mk,v 1.4 2021/01/21 00:38:28 rillig Exp $
#
# Tests for quoted and unquoted string literals in .if conditions.
# Tests for quoted string literals in .if conditions.
#
# See also:
# cond-token-plain.mk
# Covers string literals without quotes (called "bare words").
# TODO: Implementation
@ -35,5 +39,44 @@
. error
.endif
.MAKEFLAGS: -dc
# A string in quotes is checked whether it is not empty.
.if "UNDEF"
. info The string literal "UNDEF" is not empty.
.else
. error
.endif
# A space is not empty as well.
# This differs from many other places where whitespace is trimmed.
.if " "
. info The string literal " " is not empty, even though it consists of $\
whitespace only.
.else
. error
.endif
.if "${UNDEF}"
. error
.else
. info An undefined variable in quotes expands to an empty string, which $\
then evaluates to false.
.endif
.if "${:Uvalue}"
. info A nonempty variable expression evaluates to true.
.else
. error
.endif
.if "${:U}"
. error
.else
. info An empty variable evaluates to false.
.endif
.MAKEFLAGS: -d0
all:
@:;