directive-if.mk revision 1.4
1# $NetBSD: directive-if.mk,v 1.4 2020/11/10 20:52:28 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
50all:
51