]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bmake/unit-tests/directive-undef.mk
OpenSSL: Merge OpenSSL 1.1.1k
[FreeBSD/FreeBSD.git] / contrib / bmake / unit-tests / directive-undef.mk
1 # $NetBSD: directive-undef.mk,v 1.9 2020/12/22 20:10:21 rillig Exp $
2 #
3 # Tests for the .undef directive.
4 #
5 # See also:
6 #       directive-misspellings.mk
7
8 # Before var.c 1.737 from 2020-12-19, .undef only undefined the first
9 # variable, silently skipping all further variable names.
10 #
11 # Before var.c 1.761 from 2020-12-22, .undef complained about too many
12 # arguments.
13 #
14 # Since var.c 1.761 from 2020-12-22, .undef handles multiple variable names
15 # just like the .export directive.
16 1=              1
17 2=              2
18 3=              3
19 .undef 1 2 3
20 .if ${1:U_}${2:U_}${3:U_} != ___
21 .  warning $1$2$3
22 .endif
23
24
25 # Without any arguments, until var.c 1.736 from 2020-12-19, .undef tried
26 # to delete the variable with the empty name, which never exists; see
27 # varname-empty.mk.  Since var.c 1.737 from 2020-12-19, .undef complains
28 # about a missing argument.
29 .undef
30
31
32 # Trying to delete the variable with the empty name is ok, it just won't
33 # ever do anything since that variable is never defined.
34 .undef ${:U}
35
36
37 # The argument of .undef is first expanded exactly once and then split into
38 # words, just like everywhere else.  This prevents variables whose names
39 # contain spaces or unbalanced 'single' or "double" quotes from being
40 # undefined, but these characters do not appear in variables names anyway.
41 1=              1
42 2=              2
43 3=              3
44 ${:U1 2 3}=     one two three
45 VARNAMES=       1 2 3
46 .undef ${VARNAMES}              # undefines the variable "1 2 3"
47 .if !defined(${:U1 2 3})
48 .  error
49 .endif
50 .if ${1:U_}${2:U_}${3:U_} != "___"      # these are still defined
51 .  error
52 .endif
53
54
55 # A variable named " " cannot be undefined.  There's no practical use case
56 # for such variables anyway.
57 SPACE=          ${:U }
58 ${SPACE}=       space
59 .if !defined(${SPACE})
60 .  error
61 .endif
62 .undef ${SPACE}
63 .if !defined(${SPACE})
64 .  error
65 .endif
66
67
68 # A variable named "$" can be undefined since the argument to .undef is
69 # expanded exactly once, before being split into words.
70 DOLLAR=         $$
71 ${DOLLAR}=      dollar
72 .if !defined(${DOLLAR})
73 .  error
74 .endif
75 .undef ${DOLLAR}
76 .if defined(${DOLLAR})
77 .  error
78 .endif
79
80
81 # Since var.c 1.762 from 2020-12-22, parse errors in the argument should be
82 # properly detected and should stop the .undef directive from doing any work.
83 #
84 # As of var.c 1.762, this doesn't happen though because the error handling
85 # in Var_Parse and Var_Subst is not done properly.
86 .undef ${VARNAMES:L:Z}
87
88
89 all:
90         @:;