xref: /freebsd/contrib/bmake/unit-tests/directive-elif.mk (revision ba3c1f5972d7b90feb6e6da47905ff2757e0fe57)
1# $NetBSD: directive-elif.mk,v 1.8 2023/06/01 20:56:35 rillig Exp $
2#
3# Tests for the .elif directive.
4#
5# Misspellings of the .elif directive are not always detected.  They are only
6# detected if the conditional branch directly above it is taken.  In all other
7# cases, make skips over the skipped branch as fast as possible, looking only
8# at the initial '.' of the line and whether the directive is one of the known
9# conditional directives.  All other directives are silently ignored, as they
10# could be variable assignments or dependency declarations as well, and
11# deciding this would cost time.
12
13
14# TODO: Implementation
15
16
17# Misspelling '.elsif' below an .if branch that is not taken.
18.if 0
19.  info This branch is not taken.
20# As of 2020-12-19, the misspelling is not recognized as a conditional
21# directive and is thus silently skipped.
22#
23# Since the .if condition evaluated to false, this whole branch is not taken.
24.elsif 0
25.  info XXX: This misspelling is not detected.
26.  info This branch is not taken.
27# Even if the misspelling were detected, the branch would not be taken
28# since the condition of the '.elsif' evaluates to false as well.
29.endif
30
31
32# Misspelling '.elsif' below an .if branch that is not taken.
33.if 0
34.  info This branch is not taken.
35# As of 2020-12-19, the misspelling is not recognized as a conditional
36# directive and is thus silently skipped.  Since the .if condition evaluated
37# to false, this whole branch is not taken.
38.elsif 1
39.  info XXX: This misspelling is not detected.
40# If the misspelling were detected, this branch would be taken.
41.endif
42
43
44# Misspelling '.elsif' below an .if branch that is taken.
45.if 1
46# This misspelling is in an active branch and is therefore detected.
47# expect+1: Unknown directive "elsif"
48.elsif 0
49# The only thing that make detects here is a misspelled directive, make
50# doesn't recognize that it was meant to be a conditional directive.
51# Therefore the branch continues here, even though the '.elsif' condition
52# evaluates to false.
53# expect+1: This branch is taken.
54.  info This branch is taken.
55.endif
56
57
58# Misspelling '.elsif' below an .if branch that is taken.
59.if 1
60# The misspelling is in an active branch and is therefore detected.
61# expect+1: Unknown directive "elsif"
62.elsif 1
63# Since both conditions evaluate to true, this branch is taken no matter
64# whether make detects a misspelling or not.
65# expect+1: This branch is taken.
66.  info This branch is taken.
67.endif
68
69
70# Misspelling '.elsif' in a skipped branch below a branch that was taken.
71.if 1
72# expect+1: This branch is taken.
73.  info This branch is taken.
74.elif 0
75.  info This branch is not taken.
76.elsif 1
77.  info XXX: This misspelling is not detected.
78.endif
79
80
81# Misspelling '.elsif' in an .else branch that is not taken.
82.if 1
83.else
84.  info This branch is not taken.
85.elsif 1
86.  info XXX: This misspelling is not detected.
87.endif
88
89
90# Misspelling '.elsif' in an .else branch that is taken.
91.if 0
92.else
93# expect+1: Unknown directive "elsif"
94.elsif 1
95# expect+1: This misspelling is detected.
96.  info This misspelling is detected.
97# expect+1: This branch is taken because of the .else.
98.  info This branch is taken because of the .else.
99.endif
100
101
102# Misspellings for .elif in a .elif branch that is not taken.
103.if 0
104.  info This branch is not taken.
105.elif 0				# ok
106.  info This branch is not taken.
107.elsif 0
108.  info XXX: This misspelling is not detected.
109.  info This branch is not taken.
110.elseif 0
111.  info XXX: This misspelling is not detected.
112.  info This branch is not taken.
113.endif
114
115
116# expect+1: What happens on misspelling in a skipped branch?
117.info What happens on misspelling in a skipped branch?
118.if 0
119.  info 0-then
120.elsif 1
121.  info XXX: This misspelling is not detected.
122.  info 1-elsif
123.elsif 2
124.  info XXX: This misspelling is not detected.
125.  info 2-elsif
126.else
127# expect+1: else
128.  info else
129.endif
130
131# expect+1: What happens on misspelling in a taken branch?
132.info What happens on misspelling in a taken branch?
133.if 1
134# expect+1: 1-then
135.  info 1-then
136# expect+1: Unknown directive "elsif"
137.elsif 1
138# expect+1: 1-elsif
139.  info 1-elsif
140# expect+1: Unknown directive "elsif"
141.elsif 2
142# expect+1: 2-elsif
143.  info 2-elsif
144.else
145.  info else
146.endif
147
148# expect+1: if-less elif
149.elif 0
150
151.if 1
152.else
153# expect+1: warning: extra elif
154.elif
155.endif
156
157all:
158