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): in lint mode, only allow '&...



details:   https://anonhg.NetBSD.org/src/rev/8840b1804606
branches:  trunk
changeset: 956888:8840b1804606
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Nov 08 23:54:28 2020 +0000

description:
make(1): in lint mode, only allow '&&' and '||', not '&' and '|'

These variants of the condition operators are neither documented in the
manual page nor are they used in practice.

diffstat:

 distrib/sets/lists/tests/mi                  |   6 +++++-
 usr.bin/make/cond.c                          |  16 ++++++++++++----
 usr.bin/make/unit-tests/Makefile             |   4 +++-
 usr.bin/make/unit-tests/cond-op-and-lint.exp |   4 ++++
 usr.bin/make/unit-tests/cond-op-and-lint.mk  |  13 +++++++++++++
 usr.bin/make/unit-tests/cond-op-or-lint.exp  |   4 ++++
 usr.bin/make/unit-tests/cond-op-or-lint.mk   |  13 +++++++++++++
 7 files changed, 54 insertions(+), 6 deletions(-)

diffs (138 lines):

diff -r 943c3cf948d5 -r 8840b1804606 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sun Nov 08 23:38:02 2020 +0000
+++ b/distrib/sets/lists/tests/mi       Sun Nov 08 23:54:28 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.964 2020/11/08 16:44:47 rillig Exp $
+# $NetBSD: mi,v 1.965 2020/11/08 23:54:28 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4859,10 +4859,14 @@
 ./usr/tests/usr.bin/make/unit-tests/cond-func.mk                               tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond-late.exp                              tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond-late.mk                               tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-op-and-lint.exp                       tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-op-and-lint.mk                                tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond-op-and.exp                            tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond-op-and.mk                             tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond-op-not.exp                            tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond-op-not.mk                             tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-op-or-lint.exp                                tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-op-or-lint.mk                         tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond-op-or.exp                             tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond-op-or.mk                              tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond-op-parentheses.exp                    tests-usr.bin-tests     compattestfile,atf
diff -r 943c3cf948d5 -r 8840b1804606 usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Sun Nov 08 23:38:02 2020 +0000
+++ b/usr.bin/make/cond.c       Sun Nov 08 23:54:28 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.196 2020/11/08 23:20:19 rillig Exp $        */
+/*     $NetBSD: cond.c,v 1.197 2020/11/08 23:54:28 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -93,7 +93,7 @@
 #include "dir.h"
 
 /*     "@(#)cond.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: cond.c,v 1.196 2020/11/08 23:20:19 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.197 2020/11/08 23:54:28 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -836,15 +836,23 @@
 
     case '|':
        par->p++;
-       if (par->p[0] == '|') {
+       if (par->p[0] == '|')
            par->p++;
+       else if (opts.lint) {
+           Parse_Error(PARSE_FATAL, "Unknown operator '|'");
+           par->printedError = TRUE;
+           return TOK_ERROR;
        }
        return TOK_OR;
 
     case '&':
        par->p++;
-       if (par->p[0] == '&') {
+       if (par->p[0] == '&')
            par->p++;
+       else if (opts.lint) {
+           Parse_Error(PARSE_FATAL, "Unknown operator '&'");
+           par->printedError = TRUE;
+           return TOK_ERROR;
        }
        return TOK_AND;
 
diff -r 943c3cf948d5 -r 8840b1804606 usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile  Sun Nov 08 23:38:02 2020 +0000
+++ b/usr.bin/make/unit-tests/Makefile  Sun Nov 08 23:54:28 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.191 2020/11/08 16:44:47 rillig Exp $
+# $NetBSD: Makefile,v 1.192 2020/11/08 23:54:28 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -62,8 +62,10 @@
 TESTS+=                cond-late
 TESTS+=                cond-op
 TESTS+=                cond-op-and
+TESTS+=                cond-op-and-lint
 TESTS+=                cond-op-not
 TESTS+=                cond-op-or
+TESTS+=                cond-op-or-lint
 TESTS+=                cond-op-parentheses
 TESTS+=                cond-short
 TESTS+=                cond-token-number
diff -r 943c3cf948d5 -r 8840b1804606 usr.bin/make/unit-tests/cond-op-and-lint.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/cond-op-and-lint.exp      Sun Nov 08 23:54:28 2020 +0000
@@ -0,0 +1,4 @@
+make: "cond-op-and-lint.mk" line 9: Unknown operator '&'
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff -r 943c3cf948d5 -r 8840b1804606 usr.bin/make/unit-tests/cond-op-and-lint.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/cond-op-and-lint.mk       Sun Nov 08 23:54:28 2020 +0000
@@ -0,0 +1,13 @@
+# $NetBSD: cond-op-and-lint.mk,v 1.1 2020/11/08 23:54:28 rillig Exp $
+#
+# Tests for the && operator in .if conditions, in lint mode.
+
+.MAKEFLAGS: -dL
+
+# The '&' operator is not allowed in lint mode.
+# It is not used in practice anyway.
+.if 0 & 0
+.  error
+.else
+.  error
+.endif
diff -r 943c3cf948d5 -r 8840b1804606 usr.bin/make/unit-tests/cond-op-or-lint.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/cond-op-or-lint.exp       Sun Nov 08 23:54:28 2020 +0000
@@ -0,0 +1,4 @@
+make: "cond-op-or-lint.mk" line 9: Unknown operator '|'
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff -r 943c3cf948d5 -r 8840b1804606 usr.bin/make/unit-tests/cond-op-or-lint.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/cond-op-or-lint.mk        Sun Nov 08 23:54:28 2020 +0000
@@ -0,0 +1,13 @@
+# $NetBSD: cond-op-or-lint.mk,v 1.1 2020/11/08 23:54:28 rillig Exp $
+#
+# Tests for the || operator in .if conditions, in lint mode.
+
+.MAKEFLAGS: -dL
+
+# The '|' operator is not allowed in lint mode.
+# It is not used in practice anyway.
+.if 0 | 0
+.  error
+.else
+.  error
+.endif



Home | Main Index | Thread Index | Old Index