Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make/unit-tests make(1): rewrite tests for misspelle...
details: https://anonhg.NetBSD.org/src/rev/ce7628c4c635
branches: trunk
changeset: 979206:ce7628c4c635
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Dec 19 19:49:01 2020 +0000
description:
make(1): rewrite tests for misspelled .elif directive
Put the simple tests at the top, demonstrating that there are already
some cases in which the misspelled directive is detected. It's not
detected though if the surrounding conditional branch is skipped.
diffstat:
usr.bin/make/unit-tests/directive-elif.exp | 32 +++---
usr.bin/make/unit-tests/directive-elif.mk | 132 ++++++++++++++++++++++------
2 files changed, 119 insertions(+), 45 deletions(-)
diffs (207 lines):
diff -r ca6f6fec977d -r ce7628c4c635 usr.bin/make/unit-tests/directive-elif.exp
--- a/usr.bin/make/unit-tests/directive-elif.exp Sat Dec 19 19:12:02 2020 +0000
+++ b/usr.bin/make/unit-tests/directive-elif.exp Sat Dec 19 19:49:01 2020 +0000
@@ -1,17 +1,21 @@
-make: "directive-elif.mk" line 7: begin .elif misspellings tests, part 1
-make: "directive-elif.mk" line 9: 1-then
-make: "directive-elif.mk" line 18: begin .elif misspellings tests, part 2
-make: "directive-elif.mk" line 29: begin .elif misspellings tests, part 3
-make: "directive-elif.mk" line 41: which branch is taken on misspelling after false?
-make: "directive-elif.mk" line 49: else
-make: "directive-elif.mk" line 52: which branch is taken on misspelling after true?
-make: "directive-elif.mk" line 54: 1-then
-make: "directive-elif.mk" line 55: Unknown directive "elsif"
-make: "directive-elif.mk" line 56: 1-elsif
-make: "directive-elif.mk" line 57: Unknown directive "elsif"
-make: "directive-elif.mk" line 58: 2-elsif
-make: "directive-elif.mk" line 64: if-less elif
-make: "directive-elif.mk" line 69: warning: extra elif
+make: "directive-elif.mk" line 47: Unknown directive "elsif"
+make: "directive-elif.mk" line 52: This branch is taken.
+make: "directive-elif.mk" line 60: Unknown directive "elsif"
+make: "directive-elif.mk" line 63: This branch is taken.
+make: "directive-elif.mk" line 69: This branch is taken.
+make: "directive-elif.mk" line 89: Unknown directive "elsif"
+make: "directive-elif.mk" line 90: This misspelling is detected.
+make: "directive-elif.mk" line 91: This branch is taken because of the .else.
+make: "directive-elif.mk" line 109: What happens on misspelling in a skipped branch?
+make: "directive-elif.mk" line 119: else
+make: "directive-elif.mk" line 122: What happens on misspelling in a taken branch?
+make: "directive-elif.mk" line 124: 1-then
+make: "directive-elif.mk" line 125: Unknown directive "elsif"
+make: "directive-elif.mk" line 126: 1-elsif
+make: "directive-elif.mk" line 127: Unknown directive "elsif"
+make: "directive-elif.mk" line 128: 2-elsif
+make: "directive-elif.mk" line 134: if-less elif
+make: "directive-elif.mk" line 139: warning: extra elif
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff -r ca6f6fec977d -r ce7628c4c635 usr.bin/make/unit-tests/directive-elif.mk
--- a/usr.bin/make/unit-tests/directive-elif.mk Sat Dec 19 19:12:02 2020 +0000
+++ b/usr.bin/make/unit-tests/directive-elif.mk Sat Dec 19 19:49:01 2020 +0000
@@ -1,55 +1,125 @@
-# $NetBSD: directive-elif.mk,v 1.6 2020/11/12 19:46:36 rillig Exp $
+# $NetBSD: directive-elif.mk,v 1.7 2020/12/19 19:49:01 rillig Exp $
#
# Tests for the .elif directive.
+#
+# Misspellings of the .elif directive are not always detected. They are only
+# detected if the conditional branch directly above it is taken. In all other
+# cases, make skips over the skipped branch as fast as possible, looking only
+# at the initial '.' of the line and whether the directive is one of the known
+# conditional directives. All other directives are silently ignored, as they
+# could be variable assignments or dependency declarations as well, and
+# deciding this would cost time.
+
# TODO: Implementation
-.info begin .elif misspellings tests, part 1
+
+# Misspelling '.elsif' below an .if branch that is not taken.
+.if 0
+. info This branch is not taken.
+# As of 2020-12-19, the misspelling is not recognized as a conditional
+# directive and is thus silently skipped.
+#
+# Since the .if condition evaluated to false, this whole branch is not taken.
+.elsif 0
+. info XXX: This misspelling is not detected.
+. info This branch is not taken.
+# Even if the misspelling were detected, the branch would not be taken
+# since the condition of the '.elsif' evaluates to false as well.
+.endif
+
+
+# Misspelling '.elsif' below an .if branch that is not taken.
+.if 0
+. info This branch is not taken.
+# As of 2020-12-19, the misspelling is not recognized as a conditional
+# directive and is thus silently skipped. Since the .if condition evaluated
+# to false, this whole branch is not taken.
+.elsif 1
+. info XXX: This misspelling is not detected.
+# If the misspelling were detected, this branch would be taken.
+.endif
+
+
+# Misspelling '.elsif' below an .if branch that is taken.
.if 1
-. info 1-then
-.elif 1 # ok
-. info 1-elif
-.elsif 1 # oops: misspelled
-. info 1-elsif
-.elseif 1 # oops: misspelled
-. info 1-elseif
+# This misspelling is in an active branch and is therefore detected.
+.elsif 0
+# The only thing that make detects here is a misspelled directive, make
+# doesn't recognize that it was meant to be a conditional directive.
+# Therefore the branch continues here, even though the '.elsif' condition
+# evaluates to false.
+. info This branch is taken.
.endif
-.info begin .elif misspellings tests, part 2
-.if 0
-. info 0-then
-.elif 0 # ok
-. info 0-elif
-.elsif 0 # oops: misspelled
-. info 0-elsif
-.elseif 0 # oops: misspelled
-. info 0-elseif
+
+# Misspelling '.elsif' below an .if branch that is taken.
+.if 1
+# As of 2020-12-19, the misspelling is in an active branch and is therefore
+# detected.
+.elsif 1
+# Since both conditions evaluate to true, this branch is taken no matter
+# whether make detects a misspelling or not.
+. info This branch is taken.
+.endif
+
+
+# Misspelling '.elsif' in a skipped branch below a branch that was taken.
+.if 1
+. info This branch is taken.
+.elif 0
+. info This branch is not taken.
+.elsif 1
+. info XXX: This misspelling is not detected.
.endif
-.info begin .elif misspellings tests, part 3
-.if 0
-. info 0-then
-.elsif 0 # oops: misspelled
-. info 0-elsif
-.endif
-.if 0
-. info 0-then
-.elseif 0 # oops: misspelled
-. info 0-elseif
+
+# Misspelling '.elsif' in an .else branch that is not taken.
+.if 1
+.else
+. info This branch is not taken.
+.elsif 1
+. info XXX: This misspelling is not detected.
.endif
-.info which branch is taken on misspelling after false?
+
+# Misspelling '.elsif' in an .else branch that is taken.
+.if 0
+.else
+.elsif 1
+. info This misspelling is detected.
+. info This branch is taken because of the .else.
+.endif
+
+
+# Misspellings for .elif in a .elif branch that is not taken.
+.if 0
+. info This branch is not taken.
+.elif 0 # ok
+. info This branch is not taken.
+.elsif 0
+. info XXX: This misspelling is not detected.
+. info This branch is not taken.
+.elseif 0
+. info XXX: This misspelling is not detected.
+. info This branch is not taken.
+.endif
+
+
+.info What happens on misspelling in a skipped branch?
.if 0
. info 0-then
.elsif 1
+. info XXX: This misspelling is not detected.
. info 1-elsif
.elsif 2
+. info XXX: This misspelling is not detected.
. info 2-elsif
.else
. info else
.endif
-.info which branch is taken on misspelling after true?
+.info What happens on misspelling in a taken branch?
.if 1
. info 1-then
.elsif 1
@@ -65,7 +135,7 @@
.if 1
.else
-# Expect: "warning: if-less elif"
+# Expect: "warning: extra elif"
.elif
.endif
Home |
Main Index |
Thread Index |
Old Index