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 tests/make: add a few more tests, ma...



details:   https://anonhg.NetBSD.org/src/rev/4ee88bab31c3
branches:  trunk
changeset: 359792:4ee88bab31c3
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jan 22 21:50:41 2022 +0000

description:
tests/make: add a few more tests, mainly for special targets

diffstat:

 usr.bin/make/unit-tests/cond-op-parentheses.exp |   7 ++--
 usr.bin/make/unit-tests/cond-op-parentheses.mk  |  36 ++++++++++++++++++++----
 usr.bin/make/unit-tests/deptgt-error.exp        |  10 ++++++-
 usr.bin/make/unit-tests/deptgt-error.mk         |  22 +++++++++++---
 usr.bin/make/unit-tests/deptgt-ignore.exp       |  12 +++++++-
 usr.bin/make/unit-tests/deptgt-ignore.mk        |  30 ++++++++++++++++++--
 usr.bin/make/unit-tests/deptgt-interrupt.exp    |   3 +-
 usr.bin/make/unit-tests/deptgt-interrupt.mk     |   9 +++--
 usr.bin/make/unit-tests/directive-elifndef.mk   |  23 +++++++++++++--
 9 files changed, 123 insertions(+), 29 deletions(-)

diffs (229 lines):

diff -r 1cd375b90ed9 -r 4ee88bab31c3 usr.bin/make/unit-tests/cond-op-parentheses.exp
--- a/usr.bin/make/unit-tests/cond-op-parentheses.exp   Sat Jan 22 19:09:21 2022 +0000
+++ b/usr.bin/make/unit-tests/cond-op-parentheses.exp   Sat Jan 22 21:50:41 2022 +0000
@@ -1,6 +1,7 @@
-make: "cond-op-parentheses.mk" line 13: Parentheses can be nested at least to depth 112.
-make: "cond-op-parentheses.mk" line 19: Malformed conditional (()
-make: "cond-op-parentheses.mk" line 29: Malformed conditional ())
+make: "cond-op-parentheses.mk" line 19: String comparison operator must be either == or !=
+make: "cond-op-parentheses.mk" line 22: Malformed conditional ((3) > 2)
+make: "cond-op-parentheses.mk" line 40: Malformed conditional (()
+make: "cond-op-parentheses.mk" line 53: Malformed conditional ())
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1
diff -r 1cd375b90ed9 -r 4ee88bab31c3 usr.bin/make/unit-tests/cond-op-parentheses.mk
--- a/usr.bin/make/unit-tests/cond-op-parentheses.mk    Sat Jan 22 19:09:21 2022 +0000
+++ b/usr.bin/make/unit-tests/cond-op-parentheses.mk    Sat Jan 22 21:50:41 2022 +0000
@@ -1,8 +1,26 @@
-# $NetBSD: cond-op-parentheses.mk,v 1.4 2021/01/19 17:49:13 rillig Exp $
+# $NetBSD: cond-op-parentheses.mk,v 1.5 2022/01/22 21:50:41 rillig Exp $
 #
-# Tests for parentheses in .if conditions.
+# Tests for parentheses in .if conditions, which group expressions to override
+# the precedence of the operators '!', '&&' and '||'.  Parentheses cannot be
+# used to form arithmetic expressions such as '(3+4)' though.
 
-# TODO: Implementation
+# Contrary to the C family of programming languages, the outermost condition
+# does not have to be enclosed in parentheses.
+.if defined(VAR)
+.  error
+.elif !1
+.  error
+.endif
+
+# Parentheses cannot enclose numbers as there is no need for it.  Make does
+# not implement any arithmetic functions in its condition parser.  If
+# absolutely necessary, use expr(1).
+# expect+1: String comparison operator must be either == or !=
+.if 3 > (2)
+.endif
+# expect+1: Malformed conditional ((3) > 2)
+.if (3) > 2
+.endif
 
 # Test for deeply nested conditions.
 .if    ((((((((((((((((((((((((((((((((((((((((((((((((((((((((        \
@@ -10,7 +28,10 @@
        1                                                               \
        ))))))))))))))))))))))))))))))))))))))))))))))))))))))))        \
        ))))))))))))))))))))))))))))))))))))))))))))))))))))))))
-.  info Parentheses can be nested at least to depth 112.
+# Parentheses can be nested at least to depth 112.  There is nothing special
+# about this number though, much higher numbers work as well, at least on
+# NetBSD.  The actual limit depends on the allowed call stack depth for C code
+# of the platform.  Anyway, 112 should be enough for all practical purposes.
 .else
 .  error
 .endif
@@ -24,8 +45,11 @@
 
 # An unbalanced closing parenthesis is a parse error.
 #
-# As of 2021-01-19, CondParser_Term returned TOK_RPAREN even though this
-# function promised to only ever return TOK_TRUE, TOK_FALSE or TOK_ERROR.
+# Before cond.c 1.237 from 2021-01-19, CondParser_Term returned TOK_RPAREN
+# even though the documentation of that function promised to only ever return
+# TOK_TRUE, TOK_FALSE or TOK_ERROR.  In cond.c 1.241, the return type of that
+# function was changed to a properly restricted enum type, to prevent this bug
+# from occurring again.
 .if )
 .  error
 .else
diff -r 1cd375b90ed9 -r 4ee88bab31c3 usr.bin/make/unit-tests/deptgt-error.exp
--- a/usr.bin/make/unit-tests/deptgt-error.exp  Sat Jan 22 19:09:21 2022 +0000
+++ b/usr.bin/make/unit-tests/deptgt-error.exp  Sat Jan 22 21:50:41 2022 +0000
@@ -1,1 +1,9 @@
-exit status 0
+false fails
+*** Error code 1 (continuing)
+
+Stop.
+make: stopped in unit-tests
+ERROR_INFO='This information is printed on 'errors'.'
+Making sub-error as prerequisite.
+Making .ERROR out of nothing.
+exit status 1
diff -r 1cd375b90ed9 -r 4ee88bab31c3 usr.bin/make/unit-tests/deptgt-error.mk
--- a/usr.bin/make/unit-tests/deptgt-error.mk   Sat Jan 22 19:09:21 2022 +0000
+++ b/usr.bin/make/unit-tests/deptgt-error.mk   Sat Jan 22 21:50:41 2022 +0000
@@ -1,9 +1,21 @@
-# $NetBSD: deptgt-error.mk,v 1.3 2020/11/15 20:20:58 rillig Exp $
+# $NetBSD: deptgt-error.mk,v 1.4 2022/01/22 21:50:41 rillig Exp $
 #
 # Tests for the special target .ERROR in dependency declarations, which
-# collects commands that are run when another target fails.
+# is made when another target fails.
+
+all: .PHONY
+       false fails
+
+.ERROR:
+       @echo 'Making ${.TARGET} out of nothing.'
 
-# TODO: Implementation
+.ERROR: sub-error
+sub-error: .PHONY
+       @echo 'Making ${.TARGET} as prerequisite.'
 
-all:
-       @:;
+# Before making the '.ERROR' target, these variable values are printed.
+MAKE_PRINT_VAR_ON_ERROR=       ERROR_INFO
+
+# Use single quotes to demonstrate that the output is only informational, it
+# does not use any established escaping mechanism.
+ERROR_INFO=    This information is ${:Uprinted} on 'errors'.
diff -r 1cd375b90ed9 -r 4ee88bab31c3 usr.bin/make/unit-tests/deptgt-ignore.exp
--- a/usr.bin/make/unit-tests/deptgt-ignore.exp Sat Jan 22 19:09:21 2022 +0000
+++ b/usr.bin/make/unit-tests/deptgt-ignore.exp Sat Jan 22 21:50:41 2022 +0000
@@ -1,1 +1,11 @@
-exit status 0
+error-failed before
+*** Error code 1 (continuing)
+error-ignored before
+*** Error code 1 (ignored)
+error-ignored after
+Making depends-on-ignored from error-ignored.
+`all' not remade because of errors.
+
+Stop.
+make: stopped in unit-tests
+exit status 1
diff -r 1cd375b90ed9 -r 4ee88bab31c3 usr.bin/make/unit-tests/deptgt-ignore.mk
--- a/usr.bin/make/unit-tests/deptgt-ignore.mk  Sat Jan 22 19:09:21 2022 +0000
+++ b/usr.bin/make/unit-tests/deptgt-ignore.mk  Sat Jan 22 21:50:41 2022 +0000
@@ -1,9 +1,31 @@
-# $NetBSD: deptgt-ignore.mk,v 1.3 2020/11/15 20:20:58 rillig Exp $
+# $NetBSD: deptgt-ignore.mk,v 1.4 2022/01/22 21:50:41 rillig Exp $
 #
 # Tests for the special target .IGNORE in dependency declarations, which
 # does not stop if a command from this target exits with a non-zero status.
+#
+# This test only applies to compatibility mode.  In jobs mode such as with
+# '-j1', all commands for a single target are bundled into a single shell
+# program, which is a different implementation technique, the .IGNORE applies
+# there as well.
 
-# TODO: Implementation
+.MAKEFLAGS: -d0                        # force stdout to be unbuffered
+
+all: depends-on-failed depends-on-ignored
+.PHONY: all depends-on-failed depends-on-ignored error-failed error-ignored
 
-all:
-       @:;
+error-failed error-ignored:
+       @echo '${.TARGET} before'
+       @false
+       @echo '${.TARGET} after'
+
+depends-on-failed: error-failed
+       @echo 'Making ${.TARGET} from ${.ALLSRC}.'
+depends-on-ignored: error-ignored
+       @echo 'Making ${.TARGET} from ${.ALLSRC}.'
+
+# Even though the command 'false' in the middle fails, the remaining commands
+# are still run.  After that, the target is marked made, so targets depending
+# on the target with the ignored commands are made.
+.IGNORE: error-ignored
+
+#.MAKEFLAGS: -dg2
diff -r 1cd375b90ed9 -r 4ee88bab31c3 usr.bin/make/unit-tests/deptgt-interrupt.exp
--- a/usr.bin/make/unit-tests/deptgt-interrupt.exp      Sat Jan 22 19:09:21 2022 +0000
+++ b/usr.bin/make/unit-tests/deptgt-interrupt.exp      Sat Jan 22 21:50:41 2022 +0000
@@ -1,1 +1,2 @@
-exit status 0
+Ctrl-C
+exit status 130
diff -r 1cd375b90ed9 -r 4ee88bab31c3 usr.bin/make/unit-tests/deptgt-interrupt.mk
--- a/usr.bin/make/unit-tests/deptgt-interrupt.mk       Sat Jan 22 19:09:21 2022 +0000
+++ b/usr.bin/make/unit-tests/deptgt-interrupt.mk       Sat Jan 22 21:50:41 2022 +0000
@@ -1,10 +1,11 @@
-# $NetBSD: deptgt-interrupt.mk,v 1.3 2020/11/15 20:20:58 rillig Exp $
+# $NetBSD: deptgt-interrupt.mk,v 1.4 2022/01/22 21:50:41 rillig Exp $
 #
 # Tests for the special target .INTERRUPT in dependency declarations, which
 # collects commands to be run when make is interrupted while building another
 # target.
 
-# TODO: Implementation
+all:
+       @kill -INT ${.MAKE.PID}
 
-all:
-       @:;
+.INTERRUPT:
+       @echo 'Ctrl-C'
diff -r 1cd375b90ed9 -r 4ee88bab31c3 usr.bin/make/unit-tests/directive-elifndef.mk
--- a/usr.bin/make/unit-tests/directive-elifndef.mk     Sat Jan 22 19:09:21 2022 +0000
+++ b/usr.bin/make/unit-tests/directive-elifndef.mk     Sat Jan 22 21:50:41 2022 +0000
@@ -1,8 +1,23 @@
-# $NetBSD: directive-elifndef.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: directive-elifndef.mk,v 1.3 2022/01/22 21:50:41 rillig Exp $
 #
-# Tests for the .elifndef directive.
+# Tests for the .elifndef directive, which is an obscure form of writing the
+# more usual '.elif !defined(VAR)'.
 
-# TODO: Implementation
+# At this point, VAR is not yet defined, and due to the 'n' in 'elifndef' the
+# condition evaluates to true.
+.if 0
+.elifndef VAR && VAR || VAR
+.else
+.  error
+.endif
+
+VAR=   # defined
+
+# At this point, VAR is defined, and due to the 'n' in 'elifndef' the
+# condition evaluates to false.
+.if 0
+.elifndef VAR && VAR || VAR
+.  error
+.endif
 
 all:
-       @:;



Home | Main Index | Thread Index | Old Index