11.14Srillig# $NetBSD: directive-if.mk,v 1.14 2025/06/28 22:39:28 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.12Srillig# expect+1: 0 evaluates to false.
141.3Srillig.  info 0 evaluates to false.
151.3Srillig.endif
161.3Srillig
171.3Srillig.if 1
181.12Srillig# expect+1: 1 evaluates to true.
191.3Srillig.  info 1 evaluates to true.
201.3Srillig.else
211.3Srillig.  error
221.3Srillig.endif
231.3Srillig
241.3Srillig# There is no '.ifx'.
251.3Srillig#
261.3Srillig# The commit from 2005-05-01 intended to detect this situation, but it failed
271.4Srillig# to do this since the call to is_token had its arguments switched.  They were
281.4Srillig# expected as (str, token, token_len) but were actually passed as (token, str,
291.3Srillig# token_len).  This made is_token return true even if the directive was
301.4Srillig# directly followed by alphanumerical characters, which was wrong.  The
311.4Srillig# typical cases produced an error message such as "Malformed conditional
321.4Srillig# (x 123)", while the intended error message was "Unknown directive".
331.3Srillig#
341.3Srillig# Back at that time, the commits only modified the main code but did not add
351.3Srillig# the corresponding unit tests.  This allowed the bug to hide for more than
361.3Srillig# 15 years.
371.4Srillig#
381.4Srillig# Since 2020-11-10, the correct error message is produced.  The '.ifx' is no
391.4Srillig# longer interpreted as a variant of '.if', therefore the '.error' and '.else'
401.4Srillig# are interpreted as ordinary directives, producing the error messages
411.4Srillig# "if-less else" and "if-less endif".
421.11Srillig# expect+1: Unknown directive "ifx"
431.3Srillig.ifx 123
441.11Srillig# expect+1: This is not conditional.
451.9Srillig.info This is not conditional.
461.11Srillig# expect+1: if-less else
471.3Srillig.else
481.11Srillig# expect+1: This is not conditional.
491.9Srillig.info This is not conditional.
501.11Srillig# expect+1: if-less endif
511.3Srillig.endif
521.3Srillig
531.3Srillig# Missing condition.
541.14Srillig# expect+1: Malformed conditional ""
551.3Srillig.if
561.3Srillig.  error
571.3Srillig.else
581.3Srillig.  error
591.3Srillig.endif
601.3Srillig
611.5Srillig# A plain word must not start with a '"'.  It may contain a embedded quotes
621.5Srillig# though, which are kept.  The quotes need not be balanced.  The next space
631.5Srillig# ends the word, and the remaining " || 1" is parsed as "or true".
641.5Srillig.if ${:Uplain"""""} == plain""""" || 1
651.12Srillig# expect+1: Quotes in plain words are probably a mistake.
661.5Srillig.  info Quotes in plain words are probably a mistake.
671.5Srillig# XXX: Accepting quotes in plain words is probably a mistake as well.
681.5Srillig.else
691.5Srillig.  error
701.5Srillig.endif
711.5Srillig
721.6Srillig.if0
731.6Srillig.  error
741.6Srillig.else
751.12Srillig# expect+1: Don't do this, always put a space after a directive.
761.6Srillig.  info Don't do this, always put a space after a directive.
771.6Srillig.endif
781.6Srillig
791.6Srillig.if${:U-3}
801.12Srillig# expect+1: Don't do this, always put a space after a directive.
811.6Srillig.  info Don't do this, always put a space after a directive.
821.6Srillig.else
831.6Srillig.  error
841.6Srillig.endif
851.6Srillig
861.6Srillig.if${:U-3}>-4
871.12Srillig# expect+1: Don't do this, always put a space around comparison operators.
881.6Srillig.  info Don't do this, always put a space around comparison operators.
891.6Srillig.else
901.6Srillig.  error
911.6Srillig.endif
921.6Srillig
931.8Srillig.if(1)
941.12Srillig# expect+1: Don't do this, always put a space after a directive.
951.8Srillig.  info Don't do this, always put a space after a directive.
961.8Srillig.endif
971.8Srillig
981.8Srillig.if!0
991.12Srillig# expect+1: Don't do this, always put a space after a directive.
1001.8Srillig.  info Don't do this, always put a space after a directive.
1011.8Srillig.endif
1021.8Srillig
1031.10Srillig
1041.10Srillig# The directives '.ifdef' and '.ifmake' can be negated by inserting an 'n'.
1051.10Srillig# This doesn't work for a plain '.if' though.
1061.10Srillig#
1071.10Srillig# expect+1: Unknown directive "ifn"
1081.10Srillig.ifn 0
109