xref: /freebsd/contrib/bmake/unit-tests/cond-token-string.mk (revision fe6060f10f634930ff71b7c50291ddc610da2475)
1# $NetBSD: cond-token-string.mk,v 1.4 2021/01/21 00:38:28 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# a variable expression based on an undefined variable.
13.if "" != "${:Uvalue:Z}"
14.  error
15.else
16.  error
17.endif
18
19.if x${:Uvalue}
20.  error
21.else
22.  info xvalue is not defined.
23.endif
24
25# The 'x' produces a "Malformed conditional" since the left-hand side of a
26# comparison in an .if directive must be either a variable expression, a
27# quoted string literal or a number that starts with a digit.
28.if x${:Uvalue} == ""
29.  error
30.else
31.  error
32.endif
33
34# In plain words, a '\' can be used to escape any character, just as in
35# double-quoted string literals.  See CondParser_String.
36.if \x${:Uvalue} == "xvalue"
37.  info Expected.
38.else
39.  error
40.endif
41
42.MAKEFLAGS: -dc
43
44# A string in quotes is checked whether it is not empty.
45.if "UNDEF"
46.  info The string literal "UNDEF" is not empty.
47.else
48.  error
49.endif
50
51# A space is not empty as well.
52# This differs from many other places where whitespace is trimmed.
53.if " "
54.  info The string literal " " is not empty, even though it consists of $\
55	whitespace only.
56.else
57.  error
58.endif
59
60.if "${UNDEF}"
61.  error
62.else
63.  info An undefined variable in quotes expands to an empty string, which $\
64	then evaluates to false.
65.endif
66
67.if "${:Uvalue}"
68.  info A nonempty variable expression evaluates to true.
69.else
70.  error
71.endif
72
73.if "${:U}"
74.  error
75.else
76.  info An empty variable evaluates to false.
77.endif
78
79.MAKEFLAGS: -d0
80
81all:
82	@:;
83