1# $NetBSD: directive-elif.mk,v 1.7 2020/12/19 19:49:01 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.elsif 0 48# The only thing that make detects here is a misspelled directive, make 49# doesn't recognize that it was meant to be a conditional directive. 50# Therefore the branch continues here, even though the '.elsif' condition 51# evaluates to false. 52. info This branch is taken. 53.endif 54 55 56# Misspelling '.elsif' below an .if branch that is taken. 57.if 1 58# As of 2020-12-19, the misspelling is in an active branch and is therefore 59# detected. 60.elsif 1 61# Since both conditions evaluate to true, this branch is taken no matter 62# whether make detects a misspelling or not. 63. info This branch is taken. 64.endif 65 66 67# Misspelling '.elsif' in a skipped branch below a branch that was taken. 68.if 1 69. info This branch is taken. 70.elif 0 71. info This branch is not taken. 72.elsif 1 73. info XXX: This misspelling is not detected. 74.endif 75 76 77# Misspelling '.elsif' in an .else branch that is not taken. 78.if 1 79.else 80. info This branch is not taken. 81.elsif 1 82. info XXX: This misspelling is not detected. 83.endif 84 85 86# Misspelling '.elsif' in an .else branch that is taken. 87.if 0 88.else 89.elsif 1 90. info This misspelling is detected. 91. info This branch is taken because of the .else. 92.endif 93 94 95# Misspellings for .elif in a .elif branch that is not taken. 96.if 0 97. info This branch is not taken. 98.elif 0 # ok 99. info This branch is not taken. 100.elsif 0 101. info XXX: This misspelling is not detected. 102. info This branch is not taken. 103.elseif 0 104. info XXX: This misspelling is not detected. 105. info This branch is not taken. 106.endif 107 108 109.info What happens on misspelling in a skipped branch? 110.if 0 111. info 0-then 112.elsif 1 113. info XXX: This misspelling is not detected. 114. info 1-elsif 115.elsif 2 116. info XXX: This misspelling is not detected. 117. info 2-elsif 118.else 119. info else 120.endif 121 122.info What happens on misspelling in a taken branch? 123.if 1 124. info 1-then 125.elsif 1 126. info 1-elsif 127.elsif 2 128. info 2-elsif 129.else 130. info else 131.endif 132 133# Expect: "if-less elif" 134.elif 0 135 136.if 1 137.else 138# Expect: "warning: extra elif" 139.elif 140.endif 141 142all: 143