diff options
Diffstat (limited to 'unit-tests/cond-token-plain.mk')
-rw-r--r-- | unit-tests/cond-token-plain.mk | 97 |
1 files changed, 96 insertions, 1 deletions
diff --git a/unit-tests/cond-token-plain.mk b/unit-tests/cond-token-plain.mk index a5ffa37a5c84..89f2247e077c 100644 --- a/unit-tests/cond-token-plain.mk +++ b/unit-tests/cond-token-plain.mk @@ -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.10 2021/01/21 14:08:09 rillig Exp $ # # Tests for plain tokens (that is, string literals without quotes) # in .if conditions. @@ -93,5 +93,100 @@ . 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 + +# If the right-hand side is missing, it's a parse error. +.if "" == +. error +.else +. error +.endif + +# If the left-hand side is missing, it's a parse error as well, but without +# a specific error message. +.if == "" +. error +.else +. error +.endif + +# The '\\' is not a line continuation. Neither is it an unquoted string +# literal. Instead, it is parsed as a function argument (ParseFuncArg), +# and in that context, the backslash is just an ordinary character. The +# function argument thus stays '\\' (2 backslashes). This string is passed +# to FuncDefined, and since there is no variable named '\\', the condition +# evaluates to false. +.if \\ +. error +.else +. info The variable '\\' is not defined. +.endif + +${:U\\\\}= backslash +.if \\ +. info Now the variable '\\' is defined. +.else +. error +.endif + +# Anything that doesn't start with a double quote is considered a "bare word". +# Strangely, a bare word may contain double quotes inside. Nobody should ever +# depend on this since it may well be unintended. See CondParser_String. +.if "unquoted\"quoted" != unquoted"quoted +. error +.endif + +# FIXME: In CondParser_String, Var_Parse returns var_Error without a +# corresponding error message. +.if $$$$$$$$ != "" +. error +.else +. error +.endif + +# See cond-token-string.mk for similar tests where the condition is enclosed +# in "quotes". + all: @:; |