summaryrefslogtreecommitdiff
path: root/usr.bin/make
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2022-01-23 21:48:59 +0000
committerrillig <rillig@NetBSD.org>2022-01-23 21:48:59 +0000
commitb24cb57f9c05e7f2e8ec4a166b75d3df478e87d8 (patch)
tree7805e5ce2320a30bb22ff192e511f087182d5aa4 /usr.bin/make
parent40830cb1b942a1865047886d63b63806e276eab0 (diff)
tests/make: add a few more tests
Diffstat (limited to 'usr.bin/make')
-rw-r--r--usr.bin/make/unit-tests/deptgt-main.exp1
-rw-r--r--usr.bin/make/unit-tests/deptgt-main.mk27
-rw-r--r--usr.bin/make/unit-tests/directive-dinclude.exp5
-rw-r--r--usr.bin/make/unit-tests/directive-dinclude.mk25
-rw-r--r--usr.bin/make/unit-tests/directive-hyphen-include.exp5
-rw-r--r--usr.bin/make/unit-tests/directive-hyphen-include.mk22
-rw-r--r--usr.bin/make/unit-tests/directive-if.exp24
-rw-r--r--usr.bin/make/unit-tests/directive-if.mk8
-rw-r--r--usr.bin/make/unit-tests/directive-ifdef.exp3
-rw-r--r--usr.bin/make/unit-tests/directive-ifdef.mk44
-rw-r--r--usr.bin/make/unit-tests/directive-sinclude.mk4
-rw-r--r--usr.bin/make/unit-tests/varmod-to-separator.mk6
-rw-r--r--usr.bin/make/unit-tests/varname-dot-make-pid.mk18
-rw-r--r--usr.bin/make/unit-tests/varname-dot-make-ppid.mk25
14 files changed, 158 insertions, 59 deletions
diff --git a/usr.bin/make/unit-tests/deptgt-main.exp b/usr.bin/make/unit-tests/deptgt-main.exp
index 39a9383953d..40c9a2c3cb8 100644
--- a/usr.bin/make/unit-tests/deptgt-main.exp
+++ b/usr.bin/make/unit-tests/deptgt-main.exp
@@ -1 +1,2 @@
+This target real-main is the one that is made.
exit status 0
diff --git a/usr.bin/make/unit-tests/deptgt-main.mk b/usr.bin/make/unit-tests/deptgt-main.mk
index 84d05dc25ed..184b6f3f73b 100644
--- a/usr.bin/make/unit-tests/deptgt-main.mk
+++ b/usr.bin/make/unit-tests/deptgt-main.mk
@@ -1,10 +1,29 @@
-# $NetBSD: deptgt-main.mk,v 1.3 2020/11/15 20:20:58 rillig Exp $
+# $NetBSD: deptgt-main.mk,v 1.4 2022/01/23 21:48:59 rillig Exp $
#
# Tests for the special target .MAIN in dependency declarations, which defines
# the main target. This main target is built if no target has been specified
# on the command line or via MAKEFLAGS.
-# TODO: Implementation
+# The first target becomes the main target by default. It can be overridden
+# though.
+all: .PHONY
+ @echo 'This target is not made.'
-all:
- @:;
+# This target is not the first to be defined, but it lists '.MAIN' as one of
+# its sources. The word '.MAIN' only has a special meaning when it appears as
+# a _target_ in a dependency declaration, not as a _source_. It is thus
+# ignored.
+depsrc-main: .PHONY .MAIN
+ @echo 'This target is not made either.'
+
+# This target is the first to be marked with '.MAIN', so it replaces the
+# previous main target, which was 'all'.
+.MAIN: real-main
+real-main: .PHONY
+ @echo 'This target ${.TARGET} is the one that is made.'
+
+# This target is marked with '.MAIN' but there already is a main target. The
+# attribute '.MAIN' is thus ignored.
+.MAIN: too-late
+too-late: .PHONY
+ @echo 'This target comes too late, there is already a .MAIN target.'
diff --git a/usr.bin/make/unit-tests/directive-dinclude.exp b/usr.bin/make/unit-tests/directive-dinclude.exp
index 39a9383953d..5ea0dabb3c7 100644
--- a/usr.bin/make/unit-tests/directive-dinclude.exp
+++ b/usr.bin/make/unit-tests/directive-dinclude.exp
@@ -1 +1,4 @@
-exit status 0
+make: "directive-dinclude-error.inc" line 1: Invalid line type
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff --git a/usr.bin/make/unit-tests/directive-dinclude.mk b/usr.bin/make/unit-tests/directive-dinclude.mk
index 94fa5fb4429..d968924a6a9 100644
--- a/usr.bin/make/unit-tests/directive-dinclude.mk
+++ b/usr.bin/make/unit-tests/directive-dinclude.mk
@@ -1,9 +1,24 @@
-# $NetBSD: directive-dinclude.mk,v 1.1 2020/09/13 09:20:23 rillig Exp $
+# $NetBSD: directive-dinclude.mk,v 1.2 2022/01/23 21:48:59 rillig Exp $
#
# Tests for the .dinclude directive, which includes another file,
-# typically named .depend.
+# silently skipping it if it cannot be opened. This is primarily used for
+# including '.depend' files, that's where the 'd' comes from.
+#
+# The 'silently skipping' only applies to the case where the file cannot be
+# opened. Parse errors and other errors are handled the same way as in the
+# other .include directives.
+
+# No complaint that there is no such file.
+.dinclude "${.CURDIR}/directive-dinclude-nonexistent.inc"
+
+# No complaint either, even though the operating system error is ENOTDIR, not
+# ENOENT.
+.dinclude "${MAKEFILE}/subdir"
-# TODO: Implementation
+# Errors that are not related to opening the file are still reported.
+# expect: make: "directive-dinclude-error.inc" line 1: Invalid line type
+_!= echo 'syntax error' > directive-dinclude-error.inc
+.dinclude "${.CURDIR}/directive-dinclude-error.inc"
+_!= rm directive-dinclude-error.inc
-all:
- @:;
+all: .PHONY
diff --git a/usr.bin/make/unit-tests/directive-hyphen-include.exp b/usr.bin/make/unit-tests/directive-hyphen-include.exp
index 39a9383953d..d0835fe464b 100644
--- a/usr.bin/make/unit-tests/directive-hyphen-include.exp
+++ b/usr.bin/make/unit-tests/directive-hyphen-include.exp
@@ -1 +1,4 @@
-exit status 0
+make: "directive-hyphen-include-error.inc" line 1: Invalid line type
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff --git a/usr.bin/make/unit-tests/directive-hyphen-include.mk b/usr.bin/make/unit-tests/directive-hyphen-include.mk
index 8c851be4321..fbfbeb200d4 100644
--- a/usr.bin/make/unit-tests/directive-hyphen-include.mk
+++ b/usr.bin/make/unit-tests/directive-hyphen-include.mk
@@ -1,9 +1,23 @@
-# $NetBSD: directive-hyphen-include.mk,v 1.1 2020/09/13 09:20:23 rillig Exp $
+# $NetBSD: directive-hyphen-include.mk,v 1.2 2022/01/23 21:48:59 rillig Exp $
#
# Tests for the .-include directive, which includes another file,
# silently skipping it if it cannot be opened.
+#
+# The 'silently skipping' only applies to the case where the file cannot be
+# opened. Parse errors and other errors are handled the same way as in the
+# other .include directives.
+
+# No complaint that there is no such file.
+.-include "${.CURDIR}/directive-hyphen-include-nonexistent.inc"
+
+# No complaint either, even though the operating system error is ENOTDIR, not
+# ENOENT.
+.-include "${MAKEFILE}/subdir"
-# TODO: Implementation
+# Errors that are not related to opening the file are still reported.
+# expect: make: "directive-hyphen-include-error.inc" line 1: Invalid line type
+_!= echo 'syntax error' > directive-hyphen-include-error.inc
+.-include "${.CURDIR}/directive-hyphen-include-error.inc"
+_!= rm directive-hyphen-include-error.inc
-all:
- @:;
+all: .PHONY
diff --git a/usr.bin/make/unit-tests/directive-if.exp b/usr.bin/make/unit-tests/directive-if.exp
index 47b07d0bf5c..5682df501e9 100644
--- a/usr.bin/make/unit-tests/directive-if.exp
+++ b/usr.bin/make/unit-tests/directive-if.exp
@@ -1,18 +1,18 @@
make: "directive-if.mk" line 13: 0 evaluates to false.
make: "directive-if.mk" line 17: 1 evaluates to true.
-make: "directive-if.mk" line 40: Unknown directive "ifx"
-make: "directive-if.mk" line 41: This is not conditional.
-make: "directive-if.mk" line 42: if-less else
+make: "directive-if.mk" line 41: Unknown directive "ifx"
make: "directive-if.mk" line 43: This is not conditional.
-make: "directive-if.mk" line 44: if-less endif
-make: "directive-if.mk" line 47: Malformed conditional ()
-make: "directive-if.mk" line 57: Quotes in plain words are probably a mistake.
-make: "directive-if.mk" line 66: Don't do this, always put a space after a directive.
-make: "directive-if.mk" line 70: Don't do this, always put a space after a directive.
-make: "directive-if.mk" line 76: Don't do this, always put a space around comparison operators.
-make: "directive-if.mk" line 82: Don't do this, always put a space after a directive.
-make: "directive-if.mk" line 86: Don't do this, always put a space after a directive.
-make: "directive-if.mk" line 94: Unknown directive "ifn"
+make: "directive-if.mk" line 45: if-less else
+make: "directive-if.mk" line 47: This is not conditional.
+make: "directive-if.mk" line 49: if-less endif
+make: "directive-if.mk" line 53: Malformed conditional ()
+make: "directive-if.mk" line 63: Quotes in plain words are probably a mistake.
+make: "directive-if.mk" line 72: Don't do this, always put a space after a directive.
+make: "directive-if.mk" line 76: Don't do this, always put a space after a directive.
+make: "directive-if.mk" line 82: Don't do this, always put a space around comparison operators.
+make: "directive-if.mk" line 88: Don't do this, always put a space after a directive.
+make: "directive-if.mk" line 92: Don't do this, always put a space after a directive.
+make: "directive-if.mk" line 100: Unknown directive "ifn"
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/usr.bin/make/unit-tests/directive-if.mk b/usr.bin/make/unit-tests/directive-if.mk
index e08b9a4ed2e..1acd5c95800 100644
--- a/usr.bin/make/unit-tests/directive-if.mk
+++ b/usr.bin/make/unit-tests/directive-if.mk
@@ -1,4 +1,4 @@
-# $NetBSD: directive-if.mk,v 1.10 2022/01/09 20:21:44 rillig Exp $
+# $NetBSD: directive-if.mk,v 1.11 2022/01/23 21:48:59 rillig Exp $
#
# Tests for the .if directive.
#
@@ -37,13 +37,19 @@
# longer interpreted as a variant of '.if', therefore the '.error' and '.else'
# are interpreted as ordinary directives, producing the error messages
# "if-less else" and "if-less endif".
+# expect+1: Unknown directive "ifx"
.ifx 123
+# expect+1: This is not conditional.
.info This is not conditional.
+# expect+1: if-less else
.else
+# expect+1: This is not conditional.
.info This is not conditional.
+# expect+1: if-less endif
.endif
# Missing condition.
+# expect+1: Malformed conditional ()
.if
. error
.else
diff --git a/usr.bin/make/unit-tests/directive-ifdef.exp b/usr.bin/make/unit-tests/directive-ifdef.exp
index 1a1358988f3..39a9383953d 100644
--- a/usr.bin/make/unit-tests/directive-ifdef.exp
+++ b/usr.bin/make/unit-tests/directive-ifdef.exp
@@ -1,4 +1 @@
-make: "directive-ifdef.mk" line 12: Function calls in .ifdef are possible.
-make: "directive-ifdef.mk" line 23: String literals are tested for emptiness.
-make: "directive-ifdef.mk" line 27: String literals are tested for emptiness. Whitespace is non-empty.
exit status 0
diff --git a/usr.bin/make/unit-tests/directive-ifdef.mk b/usr.bin/make/unit-tests/directive-ifdef.mk
index 12f3648e8b2..8a60fb4a266 100644
--- a/usr.bin/make/unit-tests/directive-ifdef.mk
+++ b/usr.bin/make/unit-tests/directive-ifdef.mk
@@ -1,33 +1,51 @@
-# $NetBSD: directive-ifdef.mk,v 1.4 2021/01/21 23:03:41 rillig Exp $
+# $NetBSD: directive-ifdef.mk,v 1.5 2022/01/23 21:48:59 rillig Exp $
#
-# Tests for the .ifdef directive.
-
-# TODO: Implementation
+# Tests for the .ifdef directive, which evaluates bare words by calling
+# 'defined(word)'.
DEFINED= defined
+# There is no variable named 'UNDEF', therefore the condition evaluates to
+# false.
+.ifdef UNDEF
+. error
+.endif
+
+# There is a variable named 'DEFINED', so the condition evaluates to true.
+.ifdef DEFINED
+.else
+. error
+.endif
+
+# Since a bare word is an abbreviation for 'defined(word)', these can be
+# used to construct complex conditions.
+.ifdef UNDEF && DEFINED
+. error
+.endif
+.ifdef UNDEF || DEFINED
+.else
+. error
+.endif
+
# It looks redundant to have a call to defined() in an .ifdef, but it's
-# possible. The .ifdef only affects plain symbols, not function calls.
+# possible. The '.ifdef' only affects bare words, not function calls.
.ifdef defined(DEFINED)
-. info Function calls in .ifdef are possible.
.else
. error
.endif
-# String literals are handled the same in all variants of the .if directive.
-# They evaluate to true if they are not empty. Whitespace counts as non-empty
-# as well.
+# String literals are handled the same in all variants of the '.if' directive,
+# they evaluate to true if they are not empty, therefore this particular
+# example looks confusing and is thus not found in practice.
.ifdef ""
. error
.else
-. info String literals are tested for emptiness.
.endif
+# Whitespace counts as non-empty as well.
.ifdef " "
-. info String literals are tested for emptiness. Whitespace is non-empty.
.else
. error
.endif
-all:
- @:;
+all: .PHONY
diff --git a/usr.bin/make/unit-tests/directive-sinclude.mk b/usr.bin/make/unit-tests/directive-sinclude.mk
index fb4ed840e27..a935ea2c068 100644
--- a/usr.bin/make/unit-tests/directive-sinclude.mk
+++ b/usr.bin/make/unit-tests/directive-sinclude.mk
@@ -1,4 +1,4 @@
-# $NetBSD: directive-sinclude.mk,v 1.3 2022/01/23 16:09:38 rillig Exp $
+# $NetBSD: directive-sinclude.mk,v 1.4 2022/01/23 21:48:59 rillig Exp $
#
# Tests for the .sinclude directive, which includes another file,
# silently skipping it if it cannot be opened.
@@ -20,4 +20,4 @@ _!= echo 'syntax error' > directive-include-error.inc
.sinclude "${.CURDIR}/directive-include-error.inc"
_!= rm directive-include-error.inc
-all:
+all: .PHONY
diff --git a/usr.bin/make/unit-tests/varmod-to-separator.mk b/usr.bin/make/unit-tests/varmod-to-separator.mk
index 7999b4cf4e3..e724a9a1ce8 100644
--- a/usr.bin/make/unit-tests/varmod-to-separator.mk
+++ b/usr.bin/make/unit-tests/varmod-to-separator.mk
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-to-separator.mk,v 1.9 2022/01/23 18:59:18 rillig Exp $
+# $NetBSD: varmod-to-separator.mk,v 1.10 2022/01/23 21:48:59 rillig Exp $
#
# Tests for the :ts variable modifier, which joins the words of the variable
# using an arbitrary character as word separator.
@@ -201,7 +201,7 @@ WORDS= one two three four five six
# In the :t modifier, the :t must be followed by any of A, l, s, u.
-# expect: Bad modifier ":tx" for variable "WORDS"
+# expect: make: Bad modifier ":tx" for variable "WORDS"
.if ${WORDS:tx}
. error
.else
@@ -209,7 +209,7 @@ WORDS= one two three four five six
.endif
# The word separator must be can only be a single character.
-# expect: Bad modifier ":ts\X" for variable "WORDS"
+# expect: make: Bad modifier ":ts\X" for variable "WORDS"
.if ${WORDS:ts\X}
. error
.else
diff --git a/usr.bin/make/unit-tests/varname-dot-make-pid.mk b/usr.bin/make/unit-tests/varname-dot-make-pid.mk
index bea114d3354..d7ef5bfd5c4 100644
--- a/usr.bin/make/unit-tests/varname-dot-make-pid.mk
+++ b/usr.bin/make/unit-tests/varname-dot-make-pid.mk
@@ -1,8 +1,16 @@
-# $NetBSD: varname-dot-make-pid.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varname-dot-make-pid.mk,v 1.3 2022/01/23 21:48:59 rillig Exp $
#
-# Tests for the special .MAKE.PID variable.
+# Tests for the special .MAKE.PID variable, which contains the process ID of
+# the make process itself.
-# TODO: Implementation
+# The process ID must be a positive integer.
+.if ${.MAKE.PID:C,[0-9],,g} != ""
+. error
+.elif !(${.MAKE.PID} > 0)
+. error
+.endif
-all:
- @:;
+# Ensure that the process exists.
+_!= kill -0 ${.MAKE.PID}
+
+all: .PHONY
diff --git a/usr.bin/make/unit-tests/varname-dot-make-ppid.mk b/usr.bin/make/unit-tests/varname-dot-make-ppid.mk
index c9471542ca3..91f13fd2fee 100644
--- a/usr.bin/make/unit-tests/varname-dot-make-ppid.mk
+++ b/usr.bin/make/unit-tests/varname-dot-make-ppid.mk
@@ -1,8 +1,23 @@
-# $NetBSD: varname-dot-make-ppid.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varname-dot-make-ppid.mk,v 1.3 2022/01/23 21:48:59 rillig Exp $
#
-# Tests for the special .MAKE.PPID variable.
+# Tests for the special .MAKE.PPID variable, which contains the process ID of
+# make's parent process.
-# TODO: Implementation
+# The parent process ID must be a positive integer.
+.if ${.MAKE.PPID:C,[0-9],,g} != ""
+. error
+.elif !(${.MAKE.PPID} > 0)
+. error
+.endif
-all:
- @:;
+# Ensure that the process exists.
+_!= kill -0 ${.MAKE.PPID}
+
+# The parent process ID must be different from the process ID. If they were
+# the same, make would run as process 1, which is not a good idea because make
+# is not prepared to clean up after other processes.
+.if ${.MAKE.PPID} == ${.MAKE.PID}
+. error
+.endif
+
+all: .PHONY