1# $NetBSD: cond-token-string.mk,v 1.15 2025/01/11 20:54:45 rillig Exp $ 2# 3# Tests for quoted string literals in .if conditions. 4# 5# See also: 6# cond-token-plain.mk 7# Covers string literals without quotes (called "bare words"). 8 9# TODO: Implementation 10 11# Cover the code in CondParser_String that frees the memory after parsing 12# an expression based on an undefined variable. 13# expect+1: Unknown modifier "Z" 14.if "" != "${:Uvalue:Z}" 15. error 16.else 17. error 18.endif 19 20.if x${:Uvalue} 21. error 22.else 23# expect+1: xvalue is not defined. 24. info xvalue is not defined. 25.endif 26 27# The 'x' produces a "Malformed conditional" since the left-hand side of a 28# comparison in an .if directive must be either an expression, a 29# quoted string literal or a number that starts with a digit. 30# expect+1: Malformed conditional 'x${:Uvalue} == ""' 31.if x${:Uvalue} == "" 32. error 33.else 34. error 35.endif 36 37# In plain words, a '\' can be used to escape any character, just as in 38# double-quoted string literals. See CondParser_String. 39.if \x${:Uvalue} == "xvalue" 40# expect+1: Expected. 41. info Expected. 42.else 43. error 44.endif 45 46.MAKEFLAGS: -dc 47 48# A string in quotes is checked whether it is not empty. 49.if "UNDEF" 50# expect+1: The string literal "UNDEF" is not empty. 51. info The string literal "UNDEF" is not empty. 52.else 53. error 54.endif 55 56# A space is not empty as well. 57# This differs from many other places where whitespace is trimmed. 58.if " " 59# expect+1: The string literal " " is not empty, even though it consists of whitespace only. 60. info The string literal " " is not empty, even though it consists of $\ 61 whitespace only. 62.else 63. error 64.endif 65 66.if "${UNDEF}" 67. error 68.else 69# expect+1: An undefined variable in quotes expands to an empty string, which then evaluates to false. 70. info An undefined variable in quotes expands to an empty string, which $\ 71 then evaluates to false. 72.endif 73 74.if "${:Uvalue}" 75# expect+1: A nonempty expression evaluates to true. 76. info A nonempty expression evaluates to true. 77.else 78. error 79.endif 80 81.if "${:U}" 82. error 83.else 84# expect+1: An empty variable evaluates to false. 85. info An empty variable evaluates to false. 86.endif 87 88# A non-empty string evaluates to true, no matter if it's a literal string or 89# if it contains expressions. The parentheses are not necessary for 90# the parser, in this case their only purpose is to make the code harder to 91# read for humans. 92VAR= value 93.if ("${VAR}") 94.else 95. error 96.endif 97 98# In the conditions in .if directives, the left-hand side of a comparison must 99# be enclosed in quotes. The right-hand side does not need to be enclosed in 100# quotes. 101.if "quoted" == quoted 102.else 103. error 104.endif 105 106.MAKEFLAGS: -d0 107 108all: .PHONY 109