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 remarks to the tests ab...



details:   https://anonhg.NetBSD.org/src/rev/eef6483f2bbb
branches:  trunk
changeset: 946084:eef6483f2bbb
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Nov 15 14:58:14 2020 +0000

description:
make(1): add remarks to the tests about conditions

diffstat:

 usr.bin/make/unit-tests/cond-op-not.exp         |  10 ++++----
 usr.bin/make/unit-tests/cond-op-not.mk          |   6 +++-
 usr.bin/make/unit-tests/cond-op-parentheses.exp |   1 +
 usr.bin/make/unit-tests/cond-op-parentheses.mk  |  13 +++++++++++-
 usr.bin/make/unit-tests/cond-op.exp             |  26 ++++++++++++------------
 usr.bin/make/unit-tests/cond-op.mk              |  19 +++++++++++------
 usr.bin/make/unit-tests/cond-short.mk           |  21 ++++++++++++++++++-
 usr.bin/make/unit-tests/cond-token-number.exp   |  10 ++++----
 usr.bin/make/unit-tests/cond-token-number.mk    |  12 ++++++++++-
 usr.bin/make/unit-tests/cond-token-plain.mk     |  10 ++++----
 usr.bin/make/unit-tests/cond-token-var.exp      |   8 +++---
 usr.bin/make/unit-tests/cond-token-var.mk       |  22 +++++++++++++++++---
 usr.bin/make/unit-tests/cond-undef-lint.exp     |   2 +-
 usr.bin/make/unit-tests/cond-undef-lint.mk      |   6 ++++-
 usr.bin/make/unit-tests/cond1.exp               |   4 +-
 usr.bin/make/unit-tests/cond1.mk                |   7 +++++-
 16 files changed, 123 insertions(+), 54 deletions(-)

diffs (truncated from 430 to 300 lines):

diff -r 2552c63ab713 -r eef6483f2bbb usr.bin/make/unit-tests/cond-op-not.exp
--- a/usr.bin/make/unit-tests/cond-op-not.exp   Sun Nov 15 14:14:24 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-op-not.exp   Sun Nov 15 14:58:14 2020 +0000
@@ -1,6 +1,6 @@
-make: "cond-op-not.mk" line 27: Not empty evaluates to true.
-make: "cond-op-not.mk" line 35: Not space evaluates to false.
-make: "cond-op-not.mk" line 39: Not 0 evaluates to true.
-make: "cond-op-not.mk" line 47: Not 1 evaluates to false.
-make: "cond-op-not.mk" line 53: Not word evaluates to false.
+make: "cond-op-not.mk" line 29: Not empty evaluates to true.
+make: "cond-op-not.mk" line 37: Not space evaluates to false.
+make: "cond-op-not.mk" line 41: Not 0 evaluates to true.
+make: "cond-op-not.mk" line 49: Not 1 evaluates to false.
+make: "cond-op-not.mk" line 55: Not word evaluates to false.
 exit status 0
diff -r 2552c63ab713 -r eef6483f2bbb usr.bin/make/unit-tests/cond-op-not.mk
--- a/usr.bin/make/unit-tests/cond-op-not.mk    Sun Nov 15 14:14:24 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-op-not.mk    Sun Nov 15 14:58:14 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: cond-op-not.mk,v 1.5 2020/11/15 14:14:24 rillig Exp $
+# $NetBSD: cond-op-not.mk,v 1.6 2020/11/15 14:58:14 rillig Exp $
 #
 # Tests for the ! operator in .if conditions, which negates its argument.
 
@@ -18,7 +18,9 @@
 .  error
 .endif
 
-# The '==' binds more tightly than '!'.
+# The operator '==' binds more tightly than '!'.
+# This is unusual since most other programming languages define the precedence
+# to be the other way round.
 .if !${:Uexpression} == "expression"
 .  error
 .endif
diff -r 2552c63ab713 -r eef6483f2bbb usr.bin/make/unit-tests/cond-op-parentheses.exp
--- a/usr.bin/make/unit-tests/cond-op-parentheses.exp   Sun Nov 15 14:14:24 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-op-parentheses.exp   Sun Nov 15 14:58:14 2020 +0000
@@ -1,1 +1,2 @@
+make: "cond-op-parentheses.mk" line 13: Parentheses can be nested at least to depth 112.
 exit status 0
diff -r 2552c63ab713 -r eef6483f2bbb usr.bin/make/unit-tests/cond-op-parentheses.mk
--- a/usr.bin/make/unit-tests/cond-op-parentheses.mk    Sun Nov 15 14:14:24 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-op-parentheses.mk    Sun Nov 15 14:58:14 2020 +0000
@@ -1,8 +1,19 @@
-# $NetBSD: cond-op-parentheses.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: cond-op-parentheses.mk,v 1.3 2020/11/15 14:58:14 rillig Exp $
 #
 # Tests for parentheses in .if conditions.
 
 # TODO: Implementation
 
+# Test for deeply nested conditions.
+.if    ((((((((((((((((((((((((((((((((((((((((((((((((((((((((        \
+       ((((((((((((((((((((((((((((((((((((((((((((((((((((((((        \
+       1                                                               \
+       ))))))))))))))))))))))))))))))))))))))))))))))))))))))))        \
+       ))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+.  info Parentheses can be nested at least to depth 112.
+.else
+.  error
+.endif
+
 all:
        @:;
diff -r 2552c63ab713 -r eef6483f2bbb usr.bin/make/unit-tests/cond-op.exp
--- a/usr.bin/make/unit-tests/cond-op.exp       Sun Nov 15 14:14:24 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-op.exp       Sun Nov 15 14:58:14 2020 +0000
@@ -1,16 +1,16 @@
-make: "cond-op.mk" line 45: Malformed conditional ("!word" == !word)
-make: "cond-op.mk" line 70: Malformed conditional (0 ${ERR::=evaluated})
-make: "cond-op.mk" line 74: warning: After detecting a parse error, the rest is evaluated.
-make: "cond-op.mk" line 78: Parsing continues until here.
-make: "cond-op.mk" line 81: A B C   =>   (A || B) && C   A || B && C   A || (B && C)
-make: "cond-op.mk" line 88: 0 0 0   =>   0               0             0
-make: "cond-op.mk" line 88: 0 0 1   =>   0               0             0
-make: "cond-op.mk" line 88: 0 1 0   =>   0               0             0
-make: "cond-op.mk" line 88: 0 1 1   =>   1               1             1
-make: "cond-op.mk" line 88: 1 0 0   =>   0               1             1
-make: "cond-op.mk" line 88: 1 0 1   =>   1               1             1
-make: "cond-op.mk" line 88: 1 1 0   =>   0               1             1
-make: "cond-op.mk" line 88: 1 1 1   =>   1               1             1
+make: "cond-op.mk" line 50: Malformed conditional ("!word" == !word)
+make: "cond-op.mk" line 75: Malformed conditional (0 ${ERR::=evaluated})
+make: "cond-op.mk" line 79: After detecting a parse error, the rest is evaluated.
+make: "cond-op.mk" line 83: Parsing continues until here.
+make: "cond-op.mk" line 86: A B C   =>   (A || B) && C   A || B && C   A || (B && C)
+make: "cond-op.mk" line 93: 0 0 0   =>   0               0             0
+make: "cond-op.mk" line 93: 0 0 1   =>   0               0             0
+make: "cond-op.mk" line 93: 0 1 0   =>   0               0             0
+make: "cond-op.mk" line 93: 0 1 1   =>   1               1             1
+make: "cond-op.mk" line 93: 1 0 0   =>   0               1             1
+make: "cond-op.mk" line 93: 1 0 1   =>   1               1             1
+make: "cond-op.mk" line 93: 1 1 0   =>   0               1             1
+make: "cond-op.mk" line 93: 1 1 1   =>   1               1             1
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1
diff -r 2552c63ab713 -r eef6483f2bbb usr.bin/make/unit-tests/cond-op.mk
--- a/usr.bin/make/unit-tests/cond-op.mk        Sun Nov 15 14:14:24 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-op.mk        Sun Nov 15 14:58:14 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: cond-op.mk,v 1.9 2020/11/15 14:04:26 rillig Exp $
+# $NetBSD: cond-op.mk,v 1.10 2020/11/15 14:58:14 rillig Exp $
 #
 # Tests for operators like &&, ||, ! in .if conditions.
 #
@@ -9,8 +9,8 @@
 #      cond-op-parentheses.mk
 
 # In make, && binds more tightly than ||, like in C.
-# If make had the same precedence for both && and ||, the result would be
-# different.
+# If make had the same precedence for both && and ||, like in the shell,
+# the result would be different.
 # If || were to bind more tightly than &&, the result would be different
 # as well.
 .if !(1 || 1 && 0)
@@ -18,13 +18,17 @@
 .endif
 
 # If make were to interpret the && and || operators like the shell, the
-# implicit binding would be this:
+# previous condition would be interpreted as:
 .if (1 || 1) && 0
 .  error
 .endif
 
 # The precedence of the ! operator is different from C though. It has a
-# lower precedence than the comparison operators.
+# lower precedence than the comparison operators.  Negating a condition
+# does not need parentheses.
+#
+# This kind of condition looks so unfamiliar that it doesn't occur in
+# practice.
 .if !"word" == "word"
 .  error
 .endif
@@ -36,7 +40,8 @@
 
 # TODO: Demonstrate that the precedence of the ! and == operators actually
 # makes a difference.  There is a simple example for sure, I just cannot
-# wrap my head around it.
+# wrap my head around it right now.  See the truth table generator below
+# for an example that doesn't require much thought.
 
 # This condition is malformed because the '!' on the right-hand side must not
 # appear unquoted.  If any, it must be enclosed in quotes.
@@ -71,7 +76,7 @@
 .  error
 .endif
 .if ${ERR:Uundefined} == evaluated
-.  warning After detecting a parse error, the rest is evaluated.
+.  info After detecting a parse error, the rest is evaluated.
 .endif
 
 # Just in case that parsing should ever stop on the first error.
diff -r 2552c63ab713 -r eef6483f2bbb usr.bin/make/unit-tests/cond-short.mk
--- a/usr.bin/make/unit-tests/cond-short.mk     Sun Nov 15 14:14:24 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-short.mk     Sun Nov 15 14:58:14 2020 +0000
@@ -1,11 +1,14 @@
-# $NetBSD: cond-short.mk,v 1.11 2020/10/24 08:50:17 rillig Exp $
+# $NetBSD: cond-short.mk,v 1.12 2020/11/15 14:58:14 rillig Exp $
 #
 # Demonstrates that in conditions, the right-hand side of an && or ||
 # is only evaluated if it can actually influence the result.
+# This is called 'short-circuit evaluation' and is the usual evaluation
+# mode in most programming languages.  A notable exception is Ada, which
+# distinguishes between the operators 'And', 'And Then', 'Or', 'Or Else'.
 #
 # Between 2015-10-11 and 2020-06-28, the right-hand side of an && or ||
 # operator was always evaluated, which was wrong.
-#
+# TODO: Had the evaluation been correct at some time before 2015-11-12?
 
 # The && operator.
 
@@ -113,6 +116,9 @@
 # make sure these do not cause complaint
 #.MAKEFLAGS: -dc
 
+# TODO: Rewrite this whole section and check all the conditions and variables.
+# Several of the assumptions are probably wrong here.
+# TODO: replace 'x=' with '.info' or '.error'.
 V42=   42
 iV1=   ${V42}
 iV2=   ${V66}
@@ -167,5 +173,16 @@
 .endif
 x!=    echo '0 || ${iV2:U2} < ${V42}: $x' >&2; echo
 
+# TODO: Has this always worked?  There may have been a time, maybe around
+# 2000, when make would complain about the "Malformed conditional" because
+# UNDEF is not defined.
+.if defined(UNDEF) && ${UNDEF} != "undefined"
+.  error
+.endif
+
+# TODO: Test each modifier to make sure it is skipped when it is irrelevant
+# for the result.  Since this test is already quite long, do that in another
+# test.
+
 all:
        @:;:
diff -r 2552c63ab713 -r eef6483f2bbb usr.bin/make/unit-tests/cond-token-number.exp
--- a/usr.bin/make/unit-tests/cond-token-number.exp     Sun Nov 15 14:14:24 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-token-number.exp     Sun Nov 15 14:58:14 2020 +0000
@@ -1,8 +1,8 @@
-make: "cond-token-number.mk" line 13: Malformed conditional (-0)
-make: "cond-token-number.mk" line 21: Malformed conditional (+0)
-make: "cond-token-number.mk" line 29: Malformed conditional (!-1)
-make: "cond-token-number.mk" line 37: Malformed conditional (!+1)
-make: "cond-token-number.mk" line 70: End of the tests.
+make: "cond-token-number.mk" line 15: Malformed conditional (-0)
+make: "cond-token-number.mk" line 25: Malformed conditional (+0)
+make: "cond-token-number.mk" line 35: Malformed conditional (!-1)
+make: "cond-token-number.mk" line 45: Malformed conditional (!+1)
+make: "cond-token-number.mk" line 80: End of the tests.
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1
diff -r 2552c63ab713 -r eef6483f2bbb usr.bin/make/unit-tests/cond-token-number.mk
--- a/usr.bin/make/unit-tests/cond-token-number.mk      Sun Nov 15 14:14:24 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-token-number.mk      Sun Nov 15 14:58:14 2020 +0000
@@ -1,6 +1,8 @@
-# $NetBSD: cond-token-number.mk,v 1.4 2020/11/08 22:28:05 rillig Exp $
+# $NetBSD: cond-token-number.mk,v 1.5 2020/11/15 14:58:14 rillig Exp $
 #
 # Tests for number tokens in .if conditions.
+#
+# TODO: Add introduction.
 
 .if 0
 .  error
@@ -12,6 +14,8 @@
 # See the ch_isdigit call in CondParser_String.
 .if -0
 .  error
+.else
+.  error
 .endif
 
 # Even though +0 is a number and would be accepted by strtod, it is not
@@ -20,6 +24,8 @@
 # See the ch_isdigit call in CondParser_String.
 .if +0
 .  error
+.else
+.  error
 .endif
 
 # Even though -1 is a number and would be accepted by strtod, it is not
@@ -28,6 +34,8 @@
 # See the ch_isdigit call in CondParser_String.
 .if !-1
 .  error
+.else
+.  error
 .endif
 
 # Even though +1 is a number and would be accepted by strtod, it is not
@@ -36,6 +44,8 @@
 # See the ch_isdigit call in CondParser_String.
 .if !+1
 .  error
+.else
+.  error
 .endif
 
 # When the number comes from a variable expression though, it may be signed.
diff -r 2552c63ab713 -r eef6483f2bbb usr.bin/make/unit-tests/cond-token-plain.mk
--- a/usr.bin/make/unit-tests/cond-token-plain.mk       Sun Nov 15 14:14:24 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-token-plain.mk       Sun Nov 15 14:58:14 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: cond-token-plain.mk,v 1.5 2020/11/09 00:07:06 rillig Exp $
+# $NetBSD: cond-token-plain.mk,v 1.6 2020/11/15 14:58:14 rillig Exp $
 #
 # Tests for plain tokens (that is, string literals without quotes)
 # in .if conditions.
@@ -14,7 +14,7 @@
 # parser gets to see it.
 #
 # XXX: The error message is missing for this malformed condition.
-# The right-hand side of the comparison is just a '"'.
+# The right-hand side of the comparison is just a '"', before unescaping.
 .if ${:U} != "#hash"
 .  error
 .endif
@@ -35,15 +35,15 @@
 # original problems.  This workaround is probably not needed anymore.
 #
 # XXX: Missing error message for the malformed condition. The right-hand
-# side is double-quotes, backslash, backslash.
-# XXX: It is unexpected that the right-hand side evaluates to a single
-# backslash.
+# side before unescaping is double-quotes, backslash, backslash.
 .if ${:U\\} != "\\#hash"
 .  error
 .endif
 



Home | Main Index | Thread Index | Old Index