directive-if.mk revision 1.8
11.8Srillig# $NetBSD: directive-if.mk,v 1.8 2020/12/14 21:02:25 rillig Exp $
21.1Srillig#
31.2Srillig# Tests for the .if directive.
41.7Srillig#
51.7Srillig# See also:
61.7Srillig#	cond-*.mk
71.1Srillig
81.1Srillig# TODO: Implementation
91.1Srillig
101.3Srillig.if 0
111.3Srillig.  error
121.3Srillig.else
131.3Srillig.  info 0 evaluates to false.
141.3Srillig.endif
151.3Srillig
161.3Srillig.if 1
171.3Srillig.  info 1 evaluates to true.
181.3Srillig.else
191.3Srillig.  error
201.3Srillig.endif
211.3Srillig
221.3Srillig# There is no '.ifx'.
231.3Srillig#
241.3Srillig# The commit from 2005-05-01 intended to detect this situation, but it failed
251.4Srillig# to do this since the call to is_token had its arguments switched.  They were
261.4Srillig# expected as (str, token, token_len) but were actually passed as (token, str,
271.3Srillig# token_len).  This made is_token return true even if the directive was
281.4Srillig# directly followed by alphanumerical characters, which was wrong.  The
291.4Srillig# typical cases produced an error message such as "Malformed conditional
301.4Srillig# (x 123)", while the intended error message was "Unknown directive".
311.3Srillig#
321.3Srillig# Back at that time, the commits only modified the main code but did not add
331.3Srillig# the corresponding unit tests.  This allowed the bug to hide for more than
341.3Srillig# 15 years.
351.4Srillig#
361.4Srillig# Since 2020-11-10, the correct error message is produced.  The '.ifx' is no
371.4Srillig# longer interpreted as a variant of '.if', therefore the '.error' and '.else'
381.4Srillig# are interpreted as ordinary directives, producing the error messages
391.4Srillig# "if-less else" and "if-less endif".
401.3Srillig.ifx 123
411.3Srillig.  error
421.3Srillig.else
431.3Srillig.  error
441.3Srillig.endif
451.3Srillig
461.3Srillig# Missing condition.
471.3Srillig.if
481.3Srillig.  error
491.3Srillig.else
501.3Srillig.  error
511.3Srillig.endif
521.3Srillig
531.5Srillig# A plain word must not start with a '"'.  It may contain a embedded quotes
541.5Srillig# though, which are kept.  The quotes need not be balanced.  The next space
551.5Srillig# ends the word, and the remaining " || 1" is parsed as "or true".
561.5Srillig.if ${:Uplain"""""} == plain""""" || 1
571.5Srillig.  info Quotes in plain words are probably a mistake.
581.5Srillig# XXX: Accepting quotes in plain words is probably a mistake as well.
591.5Srillig.else
601.5Srillig.  error
611.5Srillig.endif
621.5Srillig
631.6Srillig.if0
641.6Srillig.  error
651.6Srillig.else
661.6Srillig.  info Don't do this, always put a space after a directive.
671.6Srillig.endif
681.6Srillig
691.6Srillig.if${:U-3}
701.6Srillig.  info Don't do this, always put a space after a directive.
711.6Srillig.else
721.6Srillig.  error
731.6Srillig.endif
741.6Srillig
751.6Srillig.if${:U-3}>-4
761.6Srillig.  info Don't do this, always put a space around comparison operators.
771.6Srillig.else
781.6Srillig.  error
791.6Srillig.endif
801.6Srillig
811.8Srillig.if(1)
821.8Srillig.  info Don't do this, always put a space after a directive.
831.8Srillig.endif
841.8Srillig
851.8Srillig.if!0
861.8Srillig.  info Don't do this, always put a space after a directive.
871.8Srillig.endif
881.8Srillig
891.1Srilligall:
90