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): add more tests for parsing ...



details:   https://anonhg.NetBSD.org/src/rev/18c3eddea64d
branches:  trunk
changeset: 942575:18c3eddea64d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Nov 10 22:23:37 2020 +0000

description:
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.

diffstat:

 distrib/sets/lists/tests/mi                     |   4 ++-
 usr.bin/make/unit-tests/Makefile                |   3 +-
 usr.bin/make/unit-tests/cond-token-string.exp   |   9 ++++++-
 usr.bin/make/unit-tests/cond-token-string.mk    |  33 ++++++++++++++++++++++++-
 usr.bin/make/unit-tests/directive-elif.exp      |   2 +
 usr.bin/make/unit-tests/directive-elif.mk       |  11 +++++++-
 usr.bin/make/unit-tests/directive-if-nested.exp |   2 +
 usr.bin/make/unit-tests/directive-if-nested.mk  |  25 ++++++++++++++++++
 usr.bin/make/unit-tests/directive-if.exp        |   1 +
 usr.bin/make/unit-tests/directive-if.mk         |  12 ++++++++-
 10 files changed, 96 insertions(+), 6 deletions(-)

diffs (198 lines):

diff -r 3abd49dd78bf -r 18c3eddea64d distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Tue Nov 10 21:47:40 2020 +0000
+++ b/distrib/sets/lists/tests/mi       Tue Nov 10 22:23:37 2020 +0000
@@ -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
diff -r 3abd49dd78bf -r 18c3eddea64d usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile  Tue Nov 10 21:47:40 2020 +0000
+++ b/usr.bin/make/unit-tests/Makefile  Tue Nov 10 22:23:37 2020 +0000
@@ -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-generating-endif
 TESTS+=                directive-hyphen-include
 TESTS+=                directive-if
+TESTS+=                directive-if-nested
 TESTS+=                directive-ifdef
 TESTS+=                directive-ifmake
 TESTS+=                directive-ifndef
diff -r 3abd49dd78bf -r 18c3eddea64d usr.bin/make/unit-tests/cond-token-string.exp
--- a/usr.bin/make/unit-tests/cond-token-string.exp     Tue Nov 10 21:47:40 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-token-string.exp     Tue Nov 10 22:23:37 2020 +0000
@@ -1,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
diff -r 3abd49dd78bf -r 18c3eddea64d usr.bin/make/unit-tests/cond-token-string.mk
--- a/usr.bin/make/unit-tests/cond-token-string.mk      Tue Nov 10 21:47:40 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-token-string.mk      Tue Nov 10 22:23:37 2020 +0000
@@ -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:
        @:;
diff -r 3abd49dd78bf -r 18c3eddea64d usr.bin/make/unit-tests/directive-elif.exp
--- a/usr.bin/make/unit-tests/directive-elif.exp        Tue Nov 10 21:47:40 2020 +0000
+++ b/usr.bin/make/unit-tests/directive-elif.exp        Tue Nov 10 22:23:37 2020 +0000
@@ -10,6 +10,8 @@
 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
diff -r 3abd49dd78bf -r 18c3eddea64d usr.bin/make/unit-tests/directive-elif.mk
--- a/usr.bin/make/unit-tests/directive-elif.mk Tue Nov 10 21:47:40 2020 +0000
+++ b/usr.bin/make/unit-tests/directive-elif.mk Tue Nov 10 22:23:37 2020 +0000
@@ -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:
        @:;
diff -r 3abd49dd78bf -r 18c3eddea64d usr.bin/make/unit-tests/directive-if-nested.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/directive-if-nested.exp   Tue Nov 10 22:23:37 2020 +0000
@@ -0,0 +1,2 @@
+make: "directive-if-nested.inc" line 1001: deeply nested .if directives
+exit status 0
diff -r 3abd49dd78bf -r 18c3eddea64d usr.bin/make/unit-tests/directive-if-nested.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/directive-if-nested.mk    Tue Nov 10 22:23:37 2020 +0000
@@ -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}
diff -r 3abd49dd78bf -r 18c3eddea64d usr.bin/make/unit-tests/directive-if.exp
--- a/usr.bin/make/unit-tests/directive-if.exp  Tue Nov 10 21:47:40 2020 +0000
+++ b/usr.bin/make/unit-tests/directive-if.exp  Tue Nov 10 22:23:37 2020 +0000
@@ -6,6 +6,7 @@
 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
diff -r 3abd49dd78bf -r 18c3eddea64d usr.bin/make/unit-tests/directive-if.mk
--- a/usr.bin/make/unit-tests/directive-if.mk   Tue Nov 10 21:47:40 2020 +0000
+++ b/usr.bin/make/unit-tests/directive-if.mk   Tue Nov 10 22:23:37 2020 +0000
@@ -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:



Home | Main Index | Thread Index | Old Index