Module Name:    src
Committed By:   rillig
Date:           Sun Jan 23 21:48:59 UTC 2022

Modified Files:
        src/usr.bin/make/unit-tests: deptgt-main.exp deptgt-main.mk
            directive-dinclude.exp directive-dinclude.mk
            directive-hyphen-include.exp directive-hyphen-include.mk
            directive-if.exp directive-if.mk directive-ifdef.exp
            directive-ifdef.mk directive-sinclude.mk varmod-to-separator.mk
            varname-dot-make-pid.mk varname-dot-make-ppid.mk

Log Message:
tests/make: add a few more tests


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/deptgt-main.exp \
    src/usr.bin/make/unit-tests/directive-dinclude.exp \
    src/usr.bin/make/unit-tests/directive-dinclude.mk \
    src/usr.bin/make/unit-tests/directive-hyphen-include.exp \
    src/usr.bin/make/unit-tests/directive-hyphen-include.mk
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/deptgt-main.mk \
    src/usr.bin/make/unit-tests/directive-ifdef.exp \
    src/usr.bin/make/unit-tests/directive-sinclude.mk
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/directive-if.exp \
    src/usr.bin/make/unit-tests/varmod-to-separator.mk
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/make/unit-tests/directive-if.mk
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/directive-ifdef.mk
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/varname-dot-make-pid.mk \
    src/usr.bin/make/unit-tests/varname-dot-make-ppid.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/deptgt-main.exp
diff -u src/usr.bin/make/unit-tests/deptgt-main.exp:1.1 src/usr.bin/make/unit-tests/deptgt-main.exp:1.2
--- src/usr.bin/make/unit-tests/deptgt-main.exp:1.1	Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/deptgt-main.exp	Sun Jan 23 21:48:59 2022
@@ -1 +1,2 @@
+This target real-main is the one that is made.
 exit status 0
Index: src/usr.bin/make/unit-tests/directive-dinclude.exp
diff -u src/usr.bin/make/unit-tests/directive-dinclude.exp:1.1 src/usr.bin/make/unit-tests/directive-dinclude.exp:1.2
--- src/usr.bin/make/unit-tests/directive-dinclude.exp:1.1	Sun Sep 13 09:20:23 2020
+++ src/usr.bin/make/unit-tests/directive-dinclude.exp	Sun Jan 23 21:48:59 2022
@@ -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
Index: src/usr.bin/make/unit-tests/directive-dinclude.mk
diff -u src/usr.bin/make/unit-tests/directive-dinclude.mk:1.1 src/usr.bin/make/unit-tests/directive-dinclude.mk:1.2
--- src/usr.bin/make/unit-tests/directive-dinclude.mk:1.1	Sun Sep 13 09:20:23 2020
+++ src/usr.bin/make/unit-tests/directive-dinclude.mk	Sun Jan 23 21:48:59 2022
@@ -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
Index: src/usr.bin/make/unit-tests/directive-hyphen-include.exp
diff -u src/usr.bin/make/unit-tests/directive-hyphen-include.exp:1.1 src/usr.bin/make/unit-tests/directive-hyphen-include.exp:1.2
--- src/usr.bin/make/unit-tests/directive-hyphen-include.exp:1.1	Sun Sep 13 09:20:23 2020
+++ src/usr.bin/make/unit-tests/directive-hyphen-include.exp	Sun Jan 23 21:48:59 2022
@@ -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
Index: src/usr.bin/make/unit-tests/directive-hyphen-include.mk
diff -u src/usr.bin/make/unit-tests/directive-hyphen-include.mk:1.1 src/usr.bin/make/unit-tests/directive-hyphen-include.mk:1.2
--- src/usr.bin/make/unit-tests/directive-hyphen-include.mk:1.1	Sun Sep 13 09:20:23 2020
+++ src/usr.bin/make/unit-tests/directive-hyphen-include.mk	Sun Jan 23 21:48:59 2022
@@ -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

Index: src/usr.bin/make/unit-tests/deptgt-main.mk
diff -u src/usr.bin/make/unit-tests/deptgt-main.mk:1.3 src/usr.bin/make/unit-tests/deptgt-main.mk:1.4
--- src/usr.bin/make/unit-tests/deptgt-main.mk:1.3	Sun Nov 15 20:20:58 2020
+++ src/usr.bin/make/unit-tests/deptgt-main.mk	Sun Jan 23 21:48:59 2022
@@ -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.'
Index: src/usr.bin/make/unit-tests/directive-ifdef.exp
diff -u src/usr.bin/make/unit-tests/directive-ifdef.exp:1.3 src/usr.bin/make/unit-tests/directive-ifdef.exp:1.4
--- src/usr.bin/make/unit-tests/directive-ifdef.exp:1.3	Thu Jan 21 23:03:41 2021
+++ src/usr.bin/make/unit-tests/directive-ifdef.exp	Sun Jan 23 21:48:59 2022
@@ -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
Index: src/usr.bin/make/unit-tests/directive-sinclude.mk
diff -u src/usr.bin/make/unit-tests/directive-sinclude.mk:1.3 src/usr.bin/make/unit-tests/directive-sinclude.mk:1.4
--- src/usr.bin/make/unit-tests/directive-sinclude.mk:1.3	Sun Jan 23 16:09:38 2022
+++ src/usr.bin/make/unit-tests/directive-sinclude.mk	Sun Jan 23 21:48:59 2022
@@ -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-incl
 .sinclude "${.CURDIR}/directive-include-error.inc"
 _!=	rm directive-include-error.inc
 
-all:
+all: .PHONY

Index: src/usr.bin/make/unit-tests/directive-if.exp
diff -u src/usr.bin/make/unit-tests/directive-if.exp:1.9 src/usr.bin/make/unit-tests/directive-if.exp:1.10
--- src/usr.bin/make/unit-tests/directive-if.exp:1.9	Sun Jan  9 20:21:44 2022
+++ src/usr.bin/make/unit-tests/directive-if.exp	Sun Jan 23 21:48:59 2022
@@ -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
Index: src/usr.bin/make/unit-tests/varmod-to-separator.mk
diff -u src/usr.bin/make/unit-tests/varmod-to-separator.mk:1.9 src/usr.bin/make/unit-tests/varmod-to-separator.mk:1.10
--- src/usr.bin/make/unit-tests/varmod-to-separator.mk:1.9	Sun Jan 23 18:59:18 2022
+++ src/usr.bin/make/unit-tests/varmod-to-separator.mk	Sun Jan 23 21:48:59 2022
@@ -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

Index: src/usr.bin/make/unit-tests/directive-if.mk
diff -u src/usr.bin/make/unit-tests/directive-if.mk:1.10 src/usr.bin/make/unit-tests/directive-if.mk:1.11
--- src/usr.bin/make/unit-tests/directive-if.mk:1.10	Sun Jan  9 20:21:44 2022
+++ src/usr.bin/make/unit-tests/directive-if.mk	Sun Jan 23 21:48:59 2022
@@ -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

Index: src/usr.bin/make/unit-tests/directive-ifdef.mk
diff -u src/usr.bin/make/unit-tests/directive-ifdef.mk:1.4 src/usr.bin/make/unit-tests/directive-ifdef.mk:1.5
--- src/usr.bin/make/unit-tests/directive-ifdef.mk:1.4	Thu Jan 21 23:03:41 2021
+++ src/usr.bin/make/unit-tests/directive-ifdef.mk	Sun Jan 23 21:48:59 2022
@@ -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

Index: src/usr.bin/make/unit-tests/varname-dot-make-pid.mk
diff -u src/usr.bin/make/unit-tests/varname-dot-make-pid.mk:1.2 src/usr.bin/make/unit-tests/varname-dot-make-pid.mk:1.3
--- src/usr.bin/make/unit-tests/varname-dot-make-pid.mk:1.2	Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/varname-dot-make-pid.mk	Sun Jan 23 21:48:59 2022
@@ -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
Index: src/usr.bin/make/unit-tests/varname-dot-make-ppid.mk
diff -u src/usr.bin/make/unit-tests/varname-dot-make-ppid.mk:1.2 src/usr.bin/make/unit-tests/varname-dot-make-ppid.mk:1.3
--- src/usr.bin/make/unit-tests/varname-dot-make-ppid.mk:1.2	Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/varname-dot-make-ppid.mk	Sun Jan 23 21:48:59 2022
@@ -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

Reply via email to