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