]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bmake/unit-tests/directive-if.mk
Merge bmake-20201117
[FreeBSD/FreeBSD.git] / contrib / bmake / unit-tests / directive-if.mk
1 # $NetBSD: directive-if.mk,v 1.7 2020/11/15 20:20:58 rillig Exp $
2 #
3 # Tests for the .if directive.
4 #
5 # See also:
6 #       cond-*.mk
7
8 # TODO: Implementation
9
10 .if 0
11 .  error
12 .else
13 .  info 0 evaluates to false.
14 .endif
15
16 .if 1
17 .  info 1 evaluates to true.
18 .else
19 .  error
20 .endif
21
22 # There is no '.ifx'.
23 #
24 # The commit from 2005-05-01 intended to detect this situation, but it failed
25 # to do this since the call to is_token had its arguments switched.  They were
26 # expected as (str, token, token_len) but were actually passed as (token, str,
27 # token_len).  This made is_token return true even if the directive was
28 # directly followed by alphanumerical characters, which was wrong.  The
29 # typical cases produced an error message such as "Malformed conditional
30 # (x 123)", while the intended error message was "Unknown directive".
31 #
32 # Back at that time, the commits only modified the main code but did not add
33 # the corresponding unit tests.  This allowed the bug to hide for more than
34 # 15 years.
35 #
36 # Since 2020-11-10, the correct error message is produced.  The '.ifx' is no
37 # longer interpreted as a variant of '.if', therefore the '.error' and '.else'
38 # are interpreted as ordinary directives, producing the error messages
39 # "if-less else" and "if-less endif".
40 .ifx 123
41 .  error
42 .else
43 .  error
44 .endif
45
46 # Missing condition.
47 .if
48 .  error
49 .else
50 .  error
51 .endif
52
53 # A plain word must not start with a '"'.  It may contain a embedded quotes
54 # though, which are kept.  The quotes need not be balanced.  The next space
55 # ends the word, and the remaining " || 1" is parsed as "or true".
56 .if ${:Uplain"""""} == plain""""" || 1
57 .  info Quotes in plain words are probably a mistake.
58 # XXX: Accepting quotes in plain words is probably a mistake as well.
59 .else
60 .  error
61 .endif
62
63 .if0
64 .  error
65 .else
66 .  info Don't do this, always put a space after a directive.
67 .endif
68
69 .if${:U-3}
70 .  info Don't do this, always put a space after a directive.
71 .else
72 .  error
73 .endif
74
75 .if${:U-3}>-4
76 .  info Don't do this, always put a space around comparison operators.
77 .else
78 .  error
79 .endif
80
81 all: