Module Name: src Committed By: rillig Date: Tue Nov 10 22:23:37 UTC 2020
Modified Files: src/distrib/sets/lists/tests: mi src/usr.bin/make/unit-tests: Makefile cond-token-string.exp cond-token-string.mk directive-elif.exp directive-elif.mk directive-if.exp directive-if.mk Added Files: src/usr.bin/make/unit-tests: directive-if-nested.exp directive-if-nested.mk Log Message: make(1): add more tests for parsing .if directives The details of parsing are quite tricky and not documented in the manual page. Record the current behavior to be a little safer in future refactorings. To generate a diff of this commit: cvs rdiff -u -r1.966 -r1.967 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.196 -r1.197 src/usr.bin/make/unit-tests/Makefile cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/cond-token-string.exp cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/cond-token-string.mk \ src/usr.bin/make/unit-tests/directive-elif.exp cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/directive-elif.mk \ src/usr.bin/make/unit-tests/directive-if.exp cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/directive-if-nested.exp \ src/usr.bin/make/unit-tests/directive-if-nested.mk cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/directive-if.mk Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.966 src/distrib/sets/lists/tests/mi:1.967 --- src/distrib/sets/lists/tests/mi:1.966 Mon Nov 9 20:39:46 2020 +++ src/distrib/sets/lists/tests/mi Tue Nov 10 22:23:37 2020 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.966 2020/11/09 20:39:46 rillig Exp $ +# $NetBSD: mi,v 1.967 2020/11/10 22:23:37 rillig Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -5037,6 +5037,8 @@ ./usr/tests/usr.bin/make/unit-tests/directive-for.mk tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/directive-hyphen-include.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/directive-hyphen-include.mk tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/make/unit-tests/directive-if-nested.exp tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/make/unit-tests/directive-if-nested.mk tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/directive-if.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/directive-if.mk tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/directive-ifdef.exp tests-usr.bin-tests compattestfile,atf Index: src/usr.bin/make/unit-tests/Makefile diff -u src/usr.bin/make/unit-tests/Makefile:1.196 src/usr.bin/make/unit-tests/Makefile:1.197 --- src/usr.bin/make/unit-tests/Makefile:1.196 Tue Nov 10 00:19:19 2020 +++ src/usr.bin/make/unit-tests/Makefile Tue Nov 10 22:23:37 2020 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.196 2020/11/10 00:19:19 rillig Exp $ +# $NetBSD: Makefile,v 1.197 2020/11/10 22:23:37 rillig Exp $ # # Unit tests for make(1) # @@ -150,6 +150,7 @@ TESTS+= directive-for TESTS+= directive-for-generating-endif TESTS+= directive-hyphen-include TESTS+= directive-if +TESTS+= directive-if-nested TESTS+= directive-ifdef TESTS+= directive-ifmake TESTS+= directive-ifndef Index: src/usr.bin/make/unit-tests/cond-token-string.exp diff -u src/usr.bin/make/unit-tests/cond-token-string.exp:1.1 src/usr.bin/make/unit-tests/cond-token-string.exp:1.2 --- src/usr.bin/make/unit-tests/cond-token-string.exp:1.1 Sun Aug 16 12:07:51 2020 +++ src/usr.bin/make/unit-tests/cond-token-string.exp Tue Nov 10 22:23:37 2020 @@ -1 +1,8 @@ -exit status 0 +make: Unknown modifier 'Z' +make: "cond-token-string.mk" line 12: Malformed conditional ("" != "${:Uvalue:Z}") +make: "cond-token-string.mk" line 21: xvalue is not defined. +make: "cond-token-string.mk" line 27: Malformed conditional (x${:Uvalue} == "") +make: "cond-token-string.mk" line 34: Expected. +make: Fatal errors encountered -- cannot continue +make: stopped in unit-tests +exit status 1 Index: src/usr.bin/make/unit-tests/cond-token-string.mk diff -u src/usr.bin/make/unit-tests/cond-token-string.mk:1.2 src/usr.bin/make/unit-tests/cond-token-string.mk:1.3 --- src/usr.bin/make/unit-tests/cond-token-string.mk:1.2 Sun Aug 16 14:25:16 2020 +++ src/usr.bin/make/unit-tests/cond-token-string.mk Tue Nov 10 22:23:37 2020 @@ -1,8 +1,39 @@ -# $NetBSD: cond-token-string.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $ +# $NetBSD: cond-token-string.mk,v 1.3 2020/11/10 22:23:37 rillig Exp $ # # Tests for quoted and unquoted string literals in .if conditions. # TODO: Implementation +# Cover the code in CondParser_String that frees the memory after parsing +# a variable expression based on an undefined variable. +.if "" != "${:Uvalue:Z}" +. error +.else +. error +.endif + +.if x${:Uvalue} +. error +.else +. info xvalue is not defined. +.endif + +# The 'x' produces a "Malformed conditional" since the left-hand side of a +# comparison in an .if directive must be either a variable expression, a +# quoted string literal or a number that starts with a digit. +.if x${:Uvalue} == "" +. error +.else +. error +.endif + +# In plain words, a '\' can be used to escape any character, just as in +# double-quoted string literals. See CondParser_String. +.if \x${:Uvalue} == "xvalue" +. info Expected. +.else +. error +.endif + all: @:; Index: src/usr.bin/make/unit-tests/directive-elif.exp diff -u src/usr.bin/make/unit-tests/directive-elif.exp:1.2 src/usr.bin/make/unit-tests/directive-elif.exp:1.3 --- src/usr.bin/make/unit-tests/directive-elif.exp:1.2 Tue Nov 3 17:17:31 2020 +++ src/usr.bin/make/unit-tests/directive-elif.exp Tue Nov 10 22:23:37 2020 @@ -10,6 +10,8 @@ make: "directive-elif.mk" line 55: Unkno 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: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 Index: src/usr.bin/make/unit-tests/directive-elif.mk diff -u src/usr.bin/make/unit-tests/directive-elif.mk:1.3 src/usr.bin/make/unit-tests/directive-elif.mk:1.4 --- src/usr.bin/make/unit-tests/directive-elif.mk:1.3 Tue Nov 3 17:17:31 2020 +++ src/usr.bin/make/unit-tests/directive-elif.mk Tue Nov 10 22:23:37 2020 @@ -1,4 +1,4 @@ -# $NetBSD: directive-elif.mk,v 1.3 2020/11/03 17:17:31 rillig Exp $ +# $NetBSD: directive-elif.mk,v 1.4 2020/11/10 22:23:37 rillig Exp $ # # Tests for the .elif directive. @@ -60,5 +60,14 @@ . info else .endif +# Expect: "if-less elif" +.elif 0 + +.if 1 +.else +# Expect: "warning: if-less elif" +.elif +.endif + all: @:; Index: src/usr.bin/make/unit-tests/directive-if.exp diff -u src/usr.bin/make/unit-tests/directive-if.exp:1.3 src/usr.bin/make/unit-tests/directive-if.exp:1.4 --- src/usr.bin/make/unit-tests/directive-if.exp:1.3 Tue Nov 10 20:52:28 2020 +++ src/usr.bin/make/unit-tests/directive-if.exp Tue Nov 10 22:23:37 2020 @@ -6,6 +6,7 @@ make: "directive-if.mk" line 39: if-less make: "directive-if.mk" line 40: Unknown directive "error" make: "directive-if.mk" line 41: if-less endif make: "directive-if.mk" line 44: Malformed conditional () +make: "directive-if.mk" line 54: Quotes in plain words are probably a mistake. make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 Index: src/usr.bin/make/unit-tests/directive-if.mk diff -u src/usr.bin/make/unit-tests/directive-if.mk:1.4 src/usr.bin/make/unit-tests/directive-if.mk:1.5 --- src/usr.bin/make/unit-tests/directive-if.mk:1.4 Tue Nov 10 20:52:28 2020 +++ src/usr.bin/make/unit-tests/directive-if.mk Tue Nov 10 22:23:37 2020 @@ -1,4 +1,4 @@ -# $NetBSD: directive-if.mk,v 1.4 2020/11/10 20:52:28 rillig Exp $ +# $NetBSD: directive-if.mk,v 1.5 2020/11/10 22:23:37 rillig Exp $ # # Tests for the .if directive. @@ -47,4 +47,14 @@ . error .endif +# A plain word must not start with a '"'. It may contain a embedded quotes +# though, which are kept. The quotes need not be balanced. The next space +# ends the word, and the remaining " || 1" is parsed as "or true". +.if ${:Uplain"""""} == plain""""" || 1 +. info Quotes in plain words are probably a mistake. +# XXX: Accepting quotes in plain words is probably a mistake as well. +.else +. error +.endif + all: Added files: Index: src/usr.bin/make/unit-tests/directive-if-nested.exp diff -u /dev/null src/usr.bin/make/unit-tests/directive-if-nested.exp:1.1 --- /dev/null Tue Nov 10 22:23:37 2020 +++ src/usr.bin/make/unit-tests/directive-if-nested.exp Tue Nov 10 22:23:37 2020 @@ -0,0 +1,2 @@ +make: "directive-if-nested.inc" line 1001: deeply nested .if directives +exit status 0 Index: src/usr.bin/make/unit-tests/directive-if-nested.mk diff -u /dev/null src/usr.bin/make/unit-tests/directive-if-nested.mk:1.1 --- /dev/null Tue Nov 10 22:23:37 2020 +++ src/usr.bin/make/unit-tests/directive-if-nested.mk Tue Nov 10 22:23:37 2020 @@ -0,0 +1,25 @@ +# $NetBSD: directive-if-nested.mk,v 1.1 2020/11/10 22:23:37 rillig Exp $ +# +# Tests for deeply nested .if directives. By default, memory for 128 nested +# .if directives is pre-allocated, any deeper nesting is reallocated. +# +# See also: +# Cond_EvalLine + +GEN= directive-if-nested.inc + +all: set-up test tear-down + +set-up: .PHONY + @{ printf '.if %s\n' ${:U:range=1000}; \ + printf '.info deeply nested .if directives\n'; \ + printf '.endif # %s\n' ${:U:range=1000}; \ + printf '\n'; \ + printf 'all:\n'; \ + } > ${GEN} + +test: .PHONY + @${MAKE} -f ${GEN} + +tear-down: .PHONY + @rm -f ${GEN}