Module Name: src Committed By: rillig Date: Sat Jan 22 21:50:42 UTC 2022
Modified Files: src/usr.bin/make/unit-tests: cond-op-parentheses.exp cond-op-parentheses.mk deptgt-error.exp deptgt-error.mk deptgt-ignore.exp deptgt-ignore.mk deptgt-interrupt.exp deptgt-interrupt.mk directive-elifndef.mk Log Message: tests/make: add a few more tests, mainly for special targets To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/cond-op-parentheses.exp \ src/usr.bin/make/unit-tests/deptgt-error.mk \ src/usr.bin/make/unit-tests/deptgt-ignore.mk \ src/usr.bin/make/unit-tests/deptgt-interrupt.mk cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/cond-op-parentheses.mk cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/deptgt-error.exp \ src/usr.bin/make/unit-tests/deptgt-ignore.exp \ src/usr.bin/make/unit-tests/deptgt-interrupt.exp cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/directive-elifndef.mk Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/unit-tests/cond-op-parentheses.exp diff -u src/usr.bin/make/unit-tests/cond-op-parentheses.exp:1.3 src/usr.bin/make/unit-tests/cond-op-parentheses.exp:1.4 --- src/usr.bin/make/unit-tests/cond-op-parentheses.exp:1.3 Tue Jan 19 17:49:13 2021 +++ src/usr.bin/make/unit-tests/cond-op-parentheses.exp Sat Jan 22 21:50:41 2022 @@ -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 Index: src/usr.bin/make/unit-tests/deptgt-error.mk diff -u src/usr.bin/make/unit-tests/deptgt-error.mk:1.3 src/usr.bin/make/unit-tests/deptgt-error.mk:1.4 --- src/usr.bin/make/unit-tests/deptgt-error.mk:1.3 Sun Nov 15 20:20:58 2020 +++ src/usr.bin/make/unit-tests/deptgt-error.mk Sat Jan 22 21:50:41 2022 @@ -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. -# TODO: Implementation +all: .PHONY + false fails -all: - @:; +.ERROR: + @echo 'Making ${.TARGET} out of nothing.' + +.ERROR: sub-error +sub-error: .PHONY + @echo 'Making ${.TARGET} as prerequisite.' + +# 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'. Index: src/usr.bin/make/unit-tests/deptgt-ignore.mk diff -u src/usr.bin/make/unit-tests/deptgt-ignore.mk:1.3 src/usr.bin/make/unit-tests/deptgt-ignore.mk:1.4 --- src/usr.bin/make/unit-tests/deptgt-ignore.mk:1.3 Sun Nov 15 20:20:58 2020 +++ src/usr.bin/make/unit-tests/deptgt-ignore.mk Sat Jan 22 21:50:41 2022 @@ -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. + +.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 + +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}.' -# TODO: Implementation +# 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 -all: - @:; +#.MAKEFLAGS: -dg2 Index: src/usr.bin/make/unit-tests/deptgt-interrupt.mk diff -u src/usr.bin/make/unit-tests/deptgt-interrupt.mk:1.3 src/usr.bin/make/unit-tests/deptgt-interrupt.mk:1.4 --- src/usr.bin/make/unit-tests/deptgt-interrupt.mk:1.3 Sun Nov 15 20:20:58 2020 +++ src/usr.bin/make/unit-tests/deptgt-interrupt.mk Sat Jan 22 21:50:41 2022 @@ -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} + +.INTERRUPT: + @echo 'Ctrl-C' Index: src/usr.bin/make/unit-tests/cond-op-parentheses.mk diff -u src/usr.bin/make/unit-tests/cond-op-parentheses.mk:1.4 src/usr.bin/make/unit-tests/cond-op-parentheses.mk:1.5 --- src/usr.bin/make/unit-tests/cond-op-parentheses.mk:1.4 Tue Jan 19 17:49:13 2021 +++ src/usr.bin/make/unit-tests/cond-op-parentheses.mk Sat Jan 22 21:50:41 2022 @@ -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 Index: src/usr.bin/make/unit-tests/deptgt-error.exp diff -u src/usr.bin/make/unit-tests/deptgt-error.exp:1.1 src/usr.bin/make/unit-tests/deptgt-error.exp:1.2 --- src/usr.bin/make/unit-tests/deptgt-error.exp:1.1 Sun Aug 16 12:07:51 2020 +++ src/usr.bin/make/unit-tests/deptgt-error.exp Sat Jan 22 21:50:41 2022 @@ -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 Index: src/usr.bin/make/unit-tests/deptgt-ignore.exp diff -u src/usr.bin/make/unit-tests/deptgt-ignore.exp:1.1 src/usr.bin/make/unit-tests/deptgt-ignore.exp:1.2 --- src/usr.bin/make/unit-tests/deptgt-ignore.exp:1.1 Sun Aug 16 12:07:51 2020 +++ src/usr.bin/make/unit-tests/deptgt-ignore.exp Sat Jan 22 21:50:41 2022 @@ -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 Index: src/usr.bin/make/unit-tests/deptgt-interrupt.exp diff -u src/usr.bin/make/unit-tests/deptgt-interrupt.exp:1.1 src/usr.bin/make/unit-tests/deptgt-interrupt.exp:1.2 --- src/usr.bin/make/unit-tests/deptgt-interrupt.exp:1.1 Sun Aug 16 12:07:51 2020 +++ src/usr.bin/make/unit-tests/deptgt-interrupt.exp Sat Jan 22 21:50:41 2022 @@ -1 +1,2 @@ -exit status 0 +Ctrl-C +exit status 130 Index: src/usr.bin/make/unit-tests/directive-elifndef.mk diff -u src/usr.bin/make/unit-tests/directive-elifndef.mk:1.2 src/usr.bin/make/unit-tests/directive-elifndef.mk:1.3 --- src/usr.bin/make/unit-tests/directive-elifndef.mk:1.2 Sun Aug 16 14:25:16 2020 +++ src/usr.bin/make/unit-tests/directive-elifndef.mk Sat Jan 22 21:50:41 2022 @@ -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: - @:;