aboutsummaryrefslogtreecommitdiff
path: root/contrib/bmake/unit-tests/directive-if.mk
blob: 7a68c0041415a28e2090a534c01c81cb2d8adf05 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# $NetBSD: directive-if.mk,v 1.12 2023/06/01 20:56:35 rillig Exp $
#
# Tests for the .if directive.
#
# See also:
#	cond-*.mk

# TODO: Implementation

.if 0
.  error
.else
# expect+1: 0 evaluates to false.
.  info 0 evaluates to false.
.endif

.if 1
# expect+1: 1 evaluates to true.
.  info 1 evaluates to true.
.else
.  error
.endif

# There is no '.ifx'.
#
# The commit from 2005-05-01 intended to detect this situation, but it failed
# to do this since the call to is_token had its arguments switched.  They were
# expected as (str, token, token_len) but were actually passed as (token, str,
# token_len).  This made is_token return true even if the directive was
# directly followed by alphanumerical characters, which was wrong.  The
# typical cases produced an error message such as "Malformed conditional
# (x 123)", while the intended error message was "Unknown directive".
#
# Back at that time, the commits only modified the main code but did not add
# the corresponding unit tests.  This allowed the bug to hide for more than
# 15 years.
#
# Since 2020-11-10, the correct error message is produced.  The '.ifx' is no
# longer interpreted as a variant of '.if', therefore the '.error' and '.else'
# are interpreted as ordinary directives, producing the error messages
# "if-less else" and "if-less endif".
# expect+1: Unknown directive "ifx"
.ifx 123
# expect+1: This is not conditional.
.info This is not conditional.
# expect+1: if-less else
.else
# expect+1: This is not conditional.
.info This is not conditional.
# expect+1: if-less endif
.endif

# Missing condition.
# expect+1: Malformed conditional ()
.if
.  error
.else
.  error
.endif

# A plain word must not start with a '"'.  It may contain a embedded quotes
# though, which are kept.  The quotes need not be balanced.  The next space
# ends the word, and the remaining " || 1" is parsed as "or true".
.if ${:Uplain"""""} == plain""""" || 1
# expect+1: Quotes in plain words are probably a mistake.
.  info Quotes in plain words are probably a mistake.
# XXX: Accepting quotes in plain words is probably a mistake as well.
.else
.  error
.endif

.if0
.  error
.else
# expect+1: Don't do this, always put a space after a directive.
.  info Don't do this, always put a space after a directive.
.endif

.if${:U-3}
# expect+1: Don't do this, always put a space after a directive.
.  info Don't do this, always put a space after a directive.
.else
.  error
.endif

.if${:U-3}>-4
# expect+1: Don't do this, always put a space around comparison operators.
.  info Don't do this, always put a space around comparison operators.
.else
.  error
.endif

.if(1)
# expect+1: Don't do this, always put a space after a directive.
.  info Don't do this, always put a space after a directive.
.endif

.if!0
# expect+1: Don't do this, always put a space after a directive.
.  info Don't do this, always put a space after a directive.
.endif


# The directives '.ifdef' and '.ifmake' can be negated by inserting an 'n'.
# This doesn't work for a plain '.if' though.
#
# expect+1: Unknown directive "ifn"
.ifn 0