Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make: add tests for full code coverage of multi...



details:   https://anonhg.NetBSD.org/src/rev/6eed0f5e7745
branches:  trunk
changeset: 376468:6eed0f5e7745
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Jun 19 20:07:35 2023 +0000

description:
make: add tests for full code coverage of multiple-inclusion guards

diffstat:

 usr.bin/make/cond.c                                 |   9 +-
 usr.bin/make/unit-tests/directive-include-guard.exp |  14 +++-
 usr.bin/make/unit-tests/directive-include-guard.mk  |  64 ++++++++++++++++++--
 3 files changed, 73 insertions(+), 14 deletions(-)

diffs (147 lines):

diff -r e07e6589b1d6 -r 6eed0f5e7745 usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Mon Jun 19 17:30:56 2023 +0000
+++ b/usr.bin/make/cond.c       Mon Jun 19 20:07:35 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.348 2023/06/19 17:30:56 rillig Exp $        */
+/*     $NetBSD: cond.c,v 1.349 2023/06/19 20:07:35 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -92,7 +92,7 @@
 #include "dir.h"
 
 /*     "@(#)cond.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: cond.c,v 1.348 2023/06/19 17:30:56 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.349 2023/06/19 20:07:35 rillig Exp $");
 
 /*
  * Conditional expressions conform to this grammar:
@@ -1259,11 +1259,10 @@ ParseVarnameGuard(const char **pp, const
 char *
 Cond_ExtractGuard(const char *line)
 {
-       const char *p = line, *varname;
+       const char *p, *varname;
        Substring dir;
 
-       if (!skip_string(&p, "."))
-               return NULL;
+       p = line + 1;           /* skip the '.' */
        cpp_skip_hspace(&p);
 
        dir.start = p;
diff -r e07e6589b1d6 -r 6eed0f5e7745 usr.bin/make/unit-tests/directive-include-guard.exp
--- a/usr.bin/make/unit-tests/directive-include-guard.exp       Mon Jun 19 17:30:56 2023 +0000
+++ b/usr.bin/make/unit-tests/directive-include-guard.exp       Mon Jun 19 20:07:35 2023 +0000
@@ -6,10 +6,20 @@ Parse_PushInput: file guarded-if.tmp, li
 Skipping 'guarded-if.tmp' because 'GUARDED_IF' is already set
 Parse_PushInput: file triple-negation.tmp, line 1
 Parse_PushInput: file triple-negation.tmp, line 1
+Parse_PushInput: file ifdef-negated.tmp, line 1
+Parse_PushInput: file ifdef-negated.tmp, line 1
 Parse_PushInput: file varname-mismatch.tmp, line 1
 Parse_PushInput: file varname-mismatch.tmp, line 1
-Parse_PushInput: file varname-indirect.tmp, line 1
-Skipping 'varname-indirect.tmp' because 'VARNAME_INDIRECT' is already set
+Parse_PushInput: file ifndef-plus.tmp, line 1
+Parse_PushInput: file ifndef-plus.tmp, line 1
+Parse_PushInput: file if-plus.tmp, line 1
+Parse_PushInput: file if-plus.tmp, line 1
+Parse_PushInput: file ifndef-indirect.tmp, line 1
+Parse_PushInput: file ifndef-indirect.tmp, line 1
+Parse_PushInput: file if-indirect.tmp, line 1
+Parse_PushInput: file if-indirect.tmp, line 1
+Parse_PushInput: file varassign-indirect.tmp, line 1
+Skipping 'varassign-indirect.tmp' because 'VARASSIGN_INDIRECT' is already set
 Parse_PushInput: file late-assignment.tmp, line 1
 Skipping 'late-assignment.tmp' because 'LATE_ASSIGNMENT' is already set
 Parse_PushInput: file two-conditions.tmp, line 1
diff -r e07e6589b1d6 -r 6eed0f5e7745 usr.bin/make/unit-tests/directive-include-guard.mk
--- a/usr.bin/make/unit-tests/directive-include-guard.mk        Mon Jun 19 17:30:56 2023 +0000
+++ b/usr.bin/make/unit-tests/directive-include-guard.mk        Mon Jun 19 20:07:35 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: directive-include-guard.mk,v 1.5 2023/06/19 12:53:57 rillig Exp $
+# $NetBSD: directive-include-guard.mk,v 1.6 2023/06/19 20:07:35 rillig Exp $
 #
 # Tests for multiple-inclusion guards in makefiles.
 #
@@ -59,6 +59,16 @@ LINES.triple-negation= \
 # expect: Parse_PushInput: file triple-negation.tmp, line 1
 # expect: Parse_PushInput: file triple-negation.tmp, line 1
 
+# A conditional other than '.if' or '.ifndef' marks the file as non-guarded,
+# even if it would actually work as a multiple-inclusion guard.
+INCS+= ifdef-negated
+LINES.ifdef-negated= \
+       '.ifdef !IFDEF_NEGATED' \
+       'IFDEF_NEGATED=' \
+       '.endif'
+# expect: Parse_PushInput: file ifdef-negated.tmp, line 1
+# expect: Parse_PushInput: file ifdef-negated.tmp, line 1
+
 # The variable names in the '.if' and the assignment must be the same.
 INCS+= varname-mismatch
 LINES.varname-mismatch= \
@@ -68,16 +78,56 @@ LINES.varname-mismatch= \
 # expect: Parse_PushInput: file varname-mismatch.tmp, line 1
 # expect: Parse_PushInput: file varname-mismatch.tmp, line 1
 
+# The guard condition must consist of only the guard variable, nothing else.
+INCS+= ifndef-plus
+LINES.ifndef-plus= \
+       '.ifndef IFNDEF_PLUS && IFNDEF_SECOND' \
+       'IFNDEF_PLUS=' \
+       'IFNDEF_SECOND=' \
+       '.endif'
+# expect: Parse_PushInput: file ifndef-plus.tmp, line 1
+# expect: Parse_PushInput: file ifndef-plus.tmp, line 1
+
+# The guard condition must consist of only the guard variable, nothing else.
+INCS+= if-plus
+LINES.if-plus= \
+       '.if !defined(IF_PLUS) && !defined(IF_SECOND)' \
+       'IF_PLUS=' \
+       'IF_SECOND=' \
+       '.endif'
+# expect: Parse_PushInput: file if-plus.tmp, line 1
+# expect: Parse_PushInput: file if-plus.tmp, line 1
+
+# The variable name in an '.ifndef' guard must be given directly, it must not
+# contain any '$' expression.
+INCS+= ifndef-indirect
+LINES.ifndef-indirect= \
+       '.ifndef $${IFNDEF_INDIRECT:L}' \
+       'IFNDEF_INDIRECT=' \
+       '.endif'
+# expect: Parse_PushInput: file ifndef-indirect.tmp, line 1
+# expect: Parse_PushInput: file ifndef-indirect.tmp, line 1
+
+# The variable name in an '.if' guard must be given directly, it must not contain
+# any '$' expression.
+INCS+= if-indirect
+LINES.if-indirect= \
+       '.if !defined($${IF_INDIRECT:L})' \
+       'IF_INDIRECT=' \
+       '.endif'
+# expect: Parse_PushInput: file if-indirect.tmp, line 1
+# expect: Parse_PushInput: file if-indirect.tmp, line 1
+
 # The variable name in the guard condition must only contain alphanumeric
 # characters and underscores.  The guard variable is more flexible, it can be
 # set anywhere, as long as it is set when the guarded file is included next.
-INCS+= varname-indirect
-LINES.varname-indirect= \
-       '.ifndef VARNAME_INDIRECT' \
-       'VARNAME_$${:UINDIRECT}=' \
+INCS+= varassign-indirect
+LINES.varassign-indirect= \
+       '.ifndef VARASSIGN_INDIRECT' \
+       '$${VARASSIGN_INDIRECT:L}=' \
        '.endif'
-# expect: Parse_PushInput: file varname-indirect.tmp, line 1
-# expect: Skipping 'varname-indirect.tmp' because 'VARNAME_INDIRECT' is already set
+# expect: Parse_PushInput: file varassign-indirect.tmp, line 1
+# expect: Skipping 'varassign-indirect.tmp' because 'VARASSIGN_INDIRECT' is already set
 
 # The time at which the guard variable is set doesn't matter, as long as it is
 # set when the file is included the next time.



Home | Main Index | Thread Index | Old Index