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



details:   https://anonhg.NetBSD.org/src/rev/497103ec81ca
branches:  trunk
changeset: 359807:497103ec81ca
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jan 23 21:48:59 2022 +0000

description:
tests/make: add a few more tests

diffstat:

 usr.bin/make/unit-tests/deptgt-main.exp              |   1 +
 usr.bin/make/unit-tests/deptgt-main.mk               |  27 ++++++++-
 usr.bin/make/unit-tests/directive-dinclude.exp       |   5 +-
 usr.bin/make/unit-tests/directive-dinclude.mk        |  25 +++++++-
 usr.bin/make/unit-tests/directive-hyphen-include.exp |   5 +-
 usr.bin/make/unit-tests/directive-hyphen-include.mk  |  22 ++++++-
 usr.bin/make/unit-tests/directive-if.exp             |  24 ++++----
 usr.bin/make/unit-tests/directive-if.mk              |   8 ++-
 usr.bin/make/unit-tests/directive-ifdef.exp          |   3 -
 usr.bin/make/unit-tests/directive-ifdef.mk           |  56 +++++++++++++------
 usr.bin/make/unit-tests/directive-sinclude.mk        |   4 +-
 usr.bin/make/unit-tests/varmod-to-separator.mk       |   6 +-
 usr.bin/make/unit-tests/varname-dot-make-pid.mk      |  18 ++++-
 usr.bin/make/unit-tests/varname-dot-make-ppid.mk     |  25 +++++++-
 14 files changed, 164 insertions(+), 65 deletions(-)

diffs (truncated from 369 to 300 lines):

diff -r ae666362427a -r 497103ec81ca usr.bin/make/unit-tests/deptgt-main.exp
--- a/usr.bin/make/unit-tests/deptgt-main.exp   Sun Jan 23 21:07:28 2022 +0000
+++ b/usr.bin/make/unit-tests/deptgt-main.exp   Sun Jan 23 21:48:59 2022 +0000
@@ -1,1 +1,2 @@
+This target real-main is the one that is made.
 exit status 0
diff -r ae666362427a -r 497103ec81ca usr.bin/make/unit-tests/deptgt-main.mk
--- a/usr.bin/make/unit-tests/deptgt-main.mk    Sun Jan 23 21:07:28 2022 +0000
+++ b/usr.bin/make/unit-tests/deptgt-main.mk    Sun Jan 23 21:48:59 2022 +0000
@@ -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.'
+
+# 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.'
 
-all:
-       @:;
+# 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 -r ae666362427a -r 497103ec81ca usr.bin/make/unit-tests/directive-dinclude.exp
--- a/usr.bin/make/unit-tests/directive-dinclude.exp    Sun Jan 23 21:07:28 2022 +0000
+++ b/usr.bin/make/unit-tests/directive-dinclude.exp    Sun Jan 23 21:48:59 2022 +0000
@@ -1,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 -r ae666362427a -r 497103ec81ca usr.bin/make/unit-tests/directive-dinclude.mk
--- a/usr.bin/make/unit-tests/directive-dinclude.mk     Sun Jan 23 21:07:28 2022 +0000
+++ b/usr.bin/make/unit-tests/directive-dinclude.mk     Sun Jan 23 21:48:59 2022 +0000
@@ -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"
 
-# TODO: Implementation
+# No complaint either, even though the operating system error is ENOTDIR, not
+# ENOENT.
+.dinclude "${MAKEFILE}/subdir"
 
-all:
-       @:;
+# 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: .PHONY
diff -r ae666362427a -r 497103ec81ca usr.bin/make/unit-tests/directive-hyphen-include.exp
--- a/usr.bin/make/unit-tests/directive-hyphen-include.exp      Sun Jan 23 21:07:28 2022 +0000
+++ b/usr.bin/make/unit-tests/directive-hyphen-include.exp      Sun Jan 23 21:48:59 2022 +0000
@@ -1,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 -r ae666362427a -r 497103ec81ca usr.bin/make/unit-tests/directive-hyphen-include.mk
--- a/usr.bin/make/unit-tests/directive-hyphen-include.mk       Sun Jan 23 21:07:28 2022 +0000
+++ b/usr.bin/make/unit-tests/directive-hyphen-include.mk       Sun Jan 23 21:48:59 2022 +0000
@@ -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.
 
-# TODO: Implementation
+# No complaint that there is no such file.
+.-include "${.CURDIR}/directive-hyphen-include-nonexistent.inc"
 
-all:
-       @:;
+# No complaint either, even though the operating system error is ENOTDIR, not
+# ENOENT.
+.-include "${MAKEFILE}/subdir"
+
+# 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: .PHONY
diff -r ae666362427a -r 497103ec81ca usr.bin/make/unit-tests/directive-if.exp
--- a/usr.bin/make/unit-tests/directive-if.exp  Sun Jan 23 21:07:28 2022 +0000
+++ b/usr.bin/make/unit-tests/directive-if.exp  Sun Jan 23 21:48:59 2022 +0000
@@ -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 -r ae666362427a -r 497103ec81ca usr.bin/make/unit-tests/directive-if.mk
--- a/usr.bin/make/unit-tests/directive-if.mk   Sun Jan 23 21:07:28 2022 +0000
+++ b/usr.bin/make/unit-tests/directive-if.mk   Sun Jan 23 21:48:59 2022 +0000
@@ -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 -r ae666362427a -r 497103ec81ca usr.bin/make/unit-tests/directive-ifdef.exp
--- a/usr.bin/make/unit-tests/directive-ifdef.exp       Sun Jan 23 21:07:28 2022 +0000
+++ b/usr.bin/make/unit-tests/directive-ifdef.exp       Sun Jan 23 21:48:59 2022 +0000
@@ -1,4 +1,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 -r ae666362427a -r 497103ec81ca usr.bin/make/unit-tests/directive-ifdef.mk
--- a/usr.bin/make/unit-tests/directive-ifdef.mk        Sun Jan 23 21:07:28 2022 +0000
+++ b/usr.bin/make/unit-tests/directive-ifdef.mk        Sun Jan 23 21:48:59 2022 +0000
@@ -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
 
-# 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.
-.ifdef defined(DEFINED)
-.  info Function calls in .ifdef are possible.
+# 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
 
-# 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.
-.ifdef ""
+# Since a bare word is an abbreviation for 'defined(word)', these can be
+# used to construct complex conditions.
+.ifdef UNDEF && DEFINED
 .  error
-.else
-.  info String literals are tested for emptiness.
 .endif
-
-.ifdef " "
-.  info String literals are tested for emptiness.  Whitespace is non-empty.
+.ifdef UNDEF || DEFINED
 .else
 .  error
 .endif
 
-all:
-       @:;
+# It looks redundant to have a call to defined() in an .ifdef, but it's
+# possible.  The '.ifdef' only affects bare words, not function calls.
+.ifdef defined(DEFINED)
+.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, therefore this particular
+# example looks confusing and is thus not found in practice.
+.ifdef ""
+.  error
+.else
+.endif
+
+# Whitespace counts as non-empty as well.
+.ifdef " "
+.else
+.  error
+.endif
+
+all: .PHONY
diff -r ae666362427a -r 497103ec81ca usr.bin/make/unit-tests/directive-sinclude.mk
--- a/usr.bin/make/unit-tests/directive-sinclude.mk     Sun Jan 23 21:07:28 2022 +0000
+++ b/usr.bin/make/unit-tests/directive-sinclude.mk     Sun Jan 23 21:48:59 2022 +0000
@@ -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 @@
 .sinclude "${.CURDIR}/directive-include-error.inc"
 _!=    rm directive-include-error.inc
 
-all:
+all: .PHONY
diff -r ae666362427a -r 497103ec81ca usr.bin/make/unit-tests/varmod-to-separator.mk
--- a/usr.bin/make/unit-tests/varmod-to-separator.mk    Sun Jan 23 21:07:28 2022 +0000
+++ b/usr.bin/make/unit-tests/varmod-to-separator.mk    Sun Jan 23 21:48:59 2022 +0000
@@ -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 @@
 
 
 # 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"



Home | Main Index | Thread Index | Old Index