1*6a7405f5SSimon J. Gerraty# $NetBSD: directive-if.mk,v 1.13 2024/08/06 18:00:17 rillig Exp $ 22c3632d1SSimon J. Gerraty# 32c3632d1SSimon J. Gerraty# Tests for the .if directive. 4e2eeea75SSimon J. Gerraty# 5e2eeea75SSimon J. Gerraty# See also: 6e2eeea75SSimon J. Gerraty# cond-*.mk 72c3632d1SSimon J. Gerraty 82c3632d1SSimon J. Gerraty# TODO: Implementation 92c3632d1SSimon J. Gerraty 10e2eeea75SSimon J. Gerraty.if 0 11e2eeea75SSimon J. Gerraty. error 12e2eeea75SSimon J. Gerraty.else 13148ee845SSimon J. Gerraty# expect+1: 0 evaluates to false. 14e2eeea75SSimon J. Gerraty. info 0 evaluates to false. 15e2eeea75SSimon J. Gerraty.endif 16e2eeea75SSimon J. Gerraty 17e2eeea75SSimon J. Gerraty.if 1 18148ee845SSimon J. Gerraty# expect+1: 1 evaluates to true. 19e2eeea75SSimon J. Gerraty. info 1 evaluates to true. 20e2eeea75SSimon J. Gerraty.else 21e2eeea75SSimon J. Gerraty. error 22e2eeea75SSimon J. Gerraty.endif 23e2eeea75SSimon J. Gerraty 24e2eeea75SSimon J. Gerraty# There is no '.ifx'. 25e2eeea75SSimon J. Gerraty# 26e2eeea75SSimon J. Gerraty# The commit from 2005-05-01 intended to detect this situation, but it failed 27e2eeea75SSimon J. Gerraty# to do this since the call to is_token had its arguments switched. They were 28e2eeea75SSimon J. Gerraty# expected as (str, token, token_len) but were actually passed as (token, str, 29e2eeea75SSimon J. Gerraty# token_len). This made is_token return true even if the directive was 30e2eeea75SSimon J. Gerraty# directly followed by alphanumerical characters, which was wrong. The 31e2eeea75SSimon J. Gerraty# typical cases produced an error message such as "Malformed conditional 32e2eeea75SSimon J. Gerraty# (x 123)", while the intended error message was "Unknown directive". 33e2eeea75SSimon J. Gerraty# 34e2eeea75SSimon J. Gerraty# Back at that time, the commits only modified the main code but did not add 35e2eeea75SSimon J. Gerraty# the corresponding unit tests. This allowed the bug to hide for more than 36e2eeea75SSimon J. Gerraty# 15 years. 37e2eeea75SSimon J. Gerraty# 38e2eeea75SSimon J. Gerraty# Since 2020-11-10, the correct error message is produced. The '.ifx' is no 39e2eeea75SSimon J. Gerraty# longer interpreted as a variant of '.if', therefore the '.error' and '.else' 40e2eeea75SSimon J. Gerraty# are interpreted as ordinary directives, producing the error messages 41e2eeea75SSimon J. Gerraty# "if-less else" and "if-less endif". 429f45a3c8SSimon J. Gerraty# expect+1: Unknown directive "ifx" 43e2eeea75SSimon J. Gerraty.ifx 123 449f45a3c8SSimon J. Gerraty# expect+1: This is not conditional. 4506b9b3e0SSimon J. Gerraty.info This is not conditional. 469f45a3c8SSimon J. Gerraty# expect+1: if-less else 47e2eeea75SSimon J. Gerraty.else 489f45a3c8SSimon J. Gerraty# expect+1: This is not conditional. 4906b9b3e0SSimon J. Gerraty.info This is not conditional. 509f45a3c8SSimon J. Gerraty# expect+1: if-less endif 51e2eeea75SSimon J. Gerraty.endif 52e2eeea75SSimon J. Gerraty 53e2eeea75SSimon J. Gerraty# Missing condition. 54*6a7405f5SSimon J. Gerraty# expect+1: Malformed conditional '' 55e2eeea75SSimon J. Gerraty.if 56e2eeea75SSimon J. Gerraty. error 57e2eeea75SSimon J. Gerraty.else 58e2eeea75SSimon J. Gerraty. error 59e2eeea75SSimon J. Gerraty.endif 60e2eeea75SSimon J. Gerraty 61e2eeea75SSimon J. Gerraty# A plain word must not start with a '"'. It may contain a embedded quotes 62e2eeea75SSimon J. Gerraty# though, which are kept. The quotes need not be balanced. The next space 63e2eeea75SSimon J. Gerraty# ends the word, and the remaining " || 1" is parsed as "or true". 64e2eeea75SSimon J. Gerraty.if ${:Uplain"""""} == plain""""" || 1 65148ee845SSimon J. Gerraty# expect+1: Quotes in plain words are probably a mistake. 66e2eeea75SSimon J. Gerraty. info Quotes in plain words are probably a mistake. 67e2eeea75SSimon J. Gerraty# XXX: Accepting quotes in plain words is probably a mistake as well. 68e2eeea75SSimon J. Gerraty.else 69e2eeea75SSimon J. Gerraty. error 70e2eeea75SSimon J. Gerraty.endif 71e2eeea75SSimon J. Gerraty 72e2eeea75SSimon J. Gerraty.if0 73e2eeea75SSimon J. Gerraty. error 74e2eeea75SSimon J. Gerraty.else 75148ee845SSimon J. Gerraty# expect+1: Don't do this, always put a space after a directive. 76e2eeea75SSimon J. Gerraty. info Don't do this, always put a space after a directive. 77e2eeea75SSimon J. Gerraty.endif 78e2eeea75SSimon J. Gerraty 79e2eeea75SSimon J. Gerraty.if${:U-3} 80148ee845SSimon J. Gerraty# expect+1: Don't do this, always put a space after a directive. 81e2eeea75SSimon J. Gerraty. info Don't do this, always put a space after a directive. 82e2eeea75SSimon J. Gerraty.else 83e2eeea75SSimon J. Gerraty. error 84e2eeea75SSimon J. Gerraty.endif 85e2eeea75SSimon J. Gerraty 86e2eeea75SSimon J. Gerraty.if${:U-3}>-4 87148ee845SSimon J. Gerraty# expect+1: Don't do this, always put a space around comparison operators. 88e2eeea75SSimon J. Gerraty. info Don't do this, always put a space around comparison operators. 89e2eeea75SSimon J. Gerraty.else 90e2eeea75SSimon J. Gerraty. error 91e2eeea75SSimon J. Gerraty.endif 92e2eeea75SSimon J. Gerraty 9306b9b3e0SSimon J. Gerraty.if(1) 94148ee845SSimon J. Gerraty# expect+1: Don't do this, always put a space after a directive. 9506b9b3e0SSimon J. Gerraty. info Don't do this, always put a space after a directive. 9606b9b3e0SSimon J. Gerraty.endif 9706b9b3e0SSimon J. Gerraty 9806b9b3e0SSimon J. Gerraty.if!0 99148ee845SSimon J. Gerraty# expect+1: Don't do this, always put a space after a directive. 10006b9b3e0SSimon J. Gerraty. info Don't do this, always put a space after a directive. 10106b9b3e0SSimon J. Gerraty.endif 10206b9b3e0SSimon J. Gerraty 1039f45a3c8SSimon J. Gerraty 1049f45a3c8SSimon J. Gerraty# The directives '.ifdef' and '.ifmake' can be negated by inserting an 'n'. 1059f45a3c8SSimon J. Gerraty# This doesn't work for a plain '.if' though. 1069f45a3c8SSimon J. Gerraty# 1079f45a3c8SSimon J. Gerraty# expect+1: Unknown directive "ifn" 1089f45a3c8SSimon J. Gerraty.ifn 0 109