xref: /freebsd/contrib/bmake/unit-tests/directive-elif.mk (revision 148ee84570001f46b7b667c86573d378101c3801)
1*148ee845SSimon J. Gerraty# $NetBSD: directive-elif.mk,v 1.8 2023/06/01 20:56:35 rillig Exp $
22c3632d1SSimon J. Gerraty#
32c3632d1SSimon J. Gerraty# Tests for the .elif directive.
406b9b3e0SSimon J. Gerraty#
506b9b3e0SSimon J. Gerraty# Misspellings of the .elif directive are not always detected.  They are only
606b9b3e0SSimon J. Gerraty# detected if the conditional branch directly above it is taken.  In all other
706b9b3e0SSimon J. Gerraty# cases, make skips over the skipped branch as fast as possible, looking only
806b9b3e0SSimon J. Gerraty# at the initial '.' of the line and whether the directive is one of the known
906b9b3e0SSimon J. Gerraty# conditional directives.  All other directives are silently ignored, as they
1006b9b3e0SSimon J. Gerraty# could be variable assignments or dependency declarations as well, and
1106b9b3e0SSimon J. Gerraty# deciding this would cost time.
1206b9b3e0SSimon J. Gerraty
132c3632d1SSimon J. Gerraty
142c3632d1SSimon J. Gerraty# TODO: Implementation
152c3632d1SSimon J. Gerraty
1606b9b3e0SSimon J. Gerraty
1706b9b3e0SSimon J. Gerraty# Misspelling '.elsif' below an .if branch that is not taken.
1806b9b3e0SSimon J. Gerraty.if 0
1906b9b3e0SSimon J. Gerraty.  info This branch is not taken.
2006b9b3e0SSimon J. Gerraty# As of 2020-12-19, the misspelling is not recognized as a conditional
2106b9b3e0SSimon J. Gerraty# directive and is thus silently skipped.
2206b9b3e0SSimon J. Gerraty#
2306b9b3e0SSimon J. Gerraty# Since the .if condition evaluated to false, this whole branch is not taken.
2406b9b3e0SSimon J. Gerraty.elsif 0
2506b9b3e0SSimon J. Gerraty.  info XXX: This misspelling is not detected.
2606b9b3e0SSimon J. Gerraty.  info This branch is not taken.
2706b9b3e0SSimon J. Gerraty# Even if the misspelling were detected, the branch would not be taken
2806b9b3e0SSimon J. Gerraty# since the condition of the '.elsif' evaluates to false as well.
2906b9b3e0SSimon J. Gerraty.endif
3006b9b3e0SSimon J. Gerraty
3106b9b3e0SSimon J. Gerraty
3206b9b3e0SSimon J. Gerraty# Misspelling '.elsif' below an .if branch that is not taken.
3306b9b3e0SSimon J. Gerraty.if 0
3406b9b3e0SSimon J. Gerraty.  info This branch is not taken.
3506b9b3e0SSimon J. Gerraty# As of 2020-12-19, the misspelling is not recognized as a conditional
3606b9b3e0SSimon J. Gerraty# directive and is thus silently skipped.  Since the .if condition evaluated
3706b9b3e0SSimon J. Gerraty# to false, this whole branch is not taken.
3806b9b3e0SSimon J. Gerraty.elsif 1
3906b9b3e0SSimon J. Gerraty.  info XXX: This misspelling is not detected.
4006b9b3e0SSimon J. Gerraty# If the misspelling were detected, this branch would be taken.
4106b9b3e0SSimon J. Gerraty.endif
4206b9b3e0SSimon J. Gerraty
4306b9b3e0SSimon J. Gerraty
4406b9b3e0SSimon J. Gerraty# Misspelling '.elsif' below an .if branch that is taken.
45e2eeea75SSimon J. Gerraty.if 1
4606b9b3e0SSimon J. Gerraty# This misspelling is in an active branch and is therefore detected.
47*148ee845SSimon J. Gerraty# expect+1: Unknown directive "elsif"
4806b9b3e0SSimon J. Gerraty.elsif 0
4906b9b3e0SSimon J. Gerraty# The only thing that make detects here is a misspelled directive, make
5006b9b3e0SSimon J. Gerraty# doesn't recognize that it was meant to be a conditional directive.
5106b9b3e0SSimon J. Gerraty# Therefore the branch continues here, even though the '.elsif' condition
5206b9b3e0SSimon J. Gerraty# evaluates to false.
53*148ee845SSimon J. Gerraty# expect+1: This branch is taken.
5406b9b3e0SSimon J. Gerraty.  info This branch is taken.
55e2eeea75SSimon J. Gerraty.endif
56e2eeea75SSimon J. Gerraty
5706b9b3e0SSimon J. Gerraty
5806b9b3e0SSimon J. Gerraty# Misspelling '.elsif' below an .if branch that is taken.
5906b9b3e0SSimon J. Gerraty.if 1
60*148ee845SSimon J. Gerraty# The misspelling is in an active branch and is therefore detected.
61*148ee845SSimon J. Gerraty# expect+1: Unknown directive "elsif"
6206b9b3e0SSimon J. Gerraty.elsif 1
6306b9b3e0SSimon J. Gerraty# Since both conditions evaluate to true, this branch is taken no matter
6406b9b3e0SSimon J. Gerraty# whether make detects a misspelling or not.
65*148ee845SSimon J. Gerraty# expect+1: This branch is taken.
6606b9b3e0SSimon J. Gerraty.  info This branch is taken.
6706b9b3e0SSimon J. Gerraty.endif
6806b9b3e0SSimon J. Gerraty
6906b9b3e0SSimon J. Gerraty
7006b9b3e0SSimon J. Gerraty# Misspelling '.elsif' in a skipped branch below a branch that was taken.
7106b9b3e0SSimon J. Gerraty.if 1
72*148ee845SSimon J. Gerraty# expect+1: This branch is taken.
7306b9b3e0SSimon J. Gerraty.  info This branch is taken.
7406b9b3e0SSimon J. Gerraty.elif 0
7506b9b3e0SSimon J. Gerraty.  info This branch is not taken.
7606b9b3e0SSimon J. Gerraty.elsif 1
7706b9b3e0SSimon J. Gerraty.  info XXX: This misspelling is not detected.
7806b9b3e0SSimon J. Gerraty.endif
7906b9b3e0SSimon J. Gerraty
8006b9b3e0SSimon J. Gerraty
8106b9b3e0SSimon J. Gerraty# Misspelling '.elsif' in an .else branch that is not taken.
8206b9b3e0SSimon J. Gerraty.if 1
8306b9b3e0SSimon J. Gerraty.else
8406b9b3e0SSimon J. Gerraty.  info This branch is not taken.
8506b9b3e0SSimon J. Gerraty.elsif 1
8606b9b3e0SSimon J. Gerraty.  info XXX: This misspelling is not detected.
8706b9b3e0SSimon J. Gerraty.endif
8806b9b3e0SSimon J. Gerraty
8906b9b3e0SSimon J. Gerraty
9006b9b3e0SSimon J. Gerraty# Misspelling '.elsif' in an .else branch that is taken.
91e2eeea75SSimon J. Gerraty.if 0
9206b9b3e0SSimon J. Gerraty.else
93*148ee845SSimon J. Gerraty# expect+1: Unknown directive "elsif"
9406b9b3e0SSimon J. Gerraty.elsif 1
95*148ee845SSimon J. Gerraty# expect+1: This misspelling is detected.
9606b9b3e0SSimon J. Gerraty.  info This misspelling is detected.
97*148ee845SSimon J. Gerraty# expect+1: This branch is taken because of the .else.
9806b9b3e0SSimon J. Gerraty.  info This branch is taken because of the .else.
9906b9b3e0SSimon J. Gerraty.endif
10006b9b3e0SSimon J. Gerraty
10106b9b3e0SSimon J. Gerraty
10206b9b3e0SSimon J. Gerraty# Misspellings for .elif in a .elif branch that is not taken.
10306b9b3e0SSimon J. Gerraty.if 0
10406b9b3e0SSimon J. Gerraty.  info This branch is not taken.
105e2eeea75SSimon J. Gerraty.elif 0				# ok
10606b9b3e0SSimon J. Gerraty.  info This branch is not taken.
10706b9b3e0SSimon J. Gerraty.elsif 0
10806b9b3e0SSimon J. Gerraty.  info XXX: This misspelling is not detected.
10906b9b3e0SSimon J. Gerraty.  info This branch is not taken.
11006b9b3e0SSimon J. Gerraty.elseif 0
11106b9b3e0SSimon J. Gerraty.  info XXX: This misspelling is not detected.
11206b9b3e0SSimon J. Gerraty.  info This branch is not taken.
113e2eeea75SSimon J. Gerraty.endif
114e2eeea75SSimon J. Gerraty
115e2eeea75SSimon J. Gerraty
116*148ee845SSimon J. Gerraty# expect+1: What happens on misspelling in a skipped branch?
11706b9b3e0SSimon J. Gerraty.info What happens on misspelling in a skipped branch?
118e2eeea75SSimon J. Gerraty.if 0
119e2eeea75SSimon J. Gerraty.  info 0-then
120e2eeea75SSimon J. Gerraty.elsif 1
12106b9b3e0SSimon J. Gerraty.  info XXX: This misspelling is not detected.
122e2eeea75SSimon J. Gerraty.  info 1-elsif
123e2eeea75SSimon J. Gerraty.elsif 2
12406b9b3e0SSimon J. Gerraty.  info XXX: This misspelling is not detected.
125e2eeea75SSimon J. Gerraty.  info 2-elsif
126e2eeea75SSimon J. Gerraty.else
127*148ee845SSimon J. Gerraty# expect+1: else
128e2eeea75SSimon J. Gerraty.  info else
129e2eeea75SSimon J. Gerraty.endif
130e2eeea75SSimon J. Gerraty
131*148ee845SSimon J. Gerraty# expect+1: What happens on misspelling in a taken branch?
13206b9b3e0SSimon J. Gerraty.info What happens on misspelling in a taken branch?
133e2eeea75SSimon J. Gerraty.if 1
134*148ee845SSimon J. Gerraty# expect+1: 1-then
135e2eeea75SSimon J. Gerraty.  info 1-then
136*148ee845SSimon J. Gerraty# expect+1: Unknown directive "elsif"
137e2eeea75SSimon J. Gerraty.elsif 1
138*148ee845SSimon J. Gerraty# expect+1: 1-elsif
139e2eeea75SSimon J. Gerraty.  info 1-elsif
140*148ee845SSimon J. Gerraty# expect+1: Unknown directive "elsif"
141e2eeea75SSimon J. Gerraty.elsif 2
142*148ee845SSimon J. Gerraty# expect+1: 2-elsif
143e2eeea75SSimon J. Gerraty.  info 2-elsif
144e2eeea75SSimon J. Gerraty.else
145e2eeea75SSimon J. Gerraty.  info else
146e2eeea75SSimon J. Gerraty.endif
147e2eeea75SSimon J. Gerraty
148*148ee845SSimon J. Gerraty# expect+1: if-less elif
149e2eeea75SSimon J. Gerraty.elif 0
150e2eeea75SSimon J. Gerraty
151e2eeea75SSimon J. Gerraty.if 1
152e2eeea75SSimon J. Gerraty.else
153*148ee845SSimon J. Gerraty# expect+1: warning: extra elif
154e2eeea75SSimon J. Gerraty.elif
155e2eeea75SSimon J. Gerraty.endif
156e2eeea75SSimon J. Gerraty
1572c3632d1SSimon J. Gerratyall:
158