From 0fbf3fce65c8472b8167c4fe3b6fc0c49f9b3c19 Mon Sep 17 00:00:00 2001 From: rillig Date: Fri, 31 May 2024 07:13:12 +0000 Subject: [PATCH] tests/make: replace or document .error in tests The text 'Missing argument for ".error"' in an .exp file may be a hint for an accidentally broken test, so eliminate them as far as possible. --- .../make/unit-tests/directive-for-empty.exp | 7 +---- .../make/unit-tests/directive-for-empty.mk | 26 ++++++++++--------- usr.bin/make/unit-tests/opt-debug-hash.exp | 2 +- usr.bin/make/unit-tests/opt-debug-hash.mk | 7 ++--- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/usr.bin/make/unit-tests/directive-for-empty.exp b/usr.bin/make/unit-tests/directive-for-empty.exp index 5cc3ac846b36..f0389d329341 100644 --- a/usr.bin/make/unit-tests/directive-for-empty.exp +++ b/usr.bin/make/unit-tests/directive-for-empty.exp @@ -1,7 +1,4 @@ make: "directive-for-empty.mk" line 22: 2 -make: "directive-for-empty.mk" line 38: Missing argument for ".error" -make: "directive-for-empty.mk" line 38: Missing argument for ".error" -make: "directive-for-empty.mk" line 38: Missing argument for ".error" For: end for 1 For: loop body with i = value: # The identifier 'empty' can only be used in conditions such as .if, .ifdef or @@ -22,6 +19,4 @@ CPPFLAGS+= -Dmessage="empty(i)" # condition directives, they can also occur in the modifier ':?', see # varmod-ifelse.mk. CPPFLAGS+= -Dmacro="${empty(i):?empty:not-empty}" -make: Fatal errors encountered -- cannot continue -make: stopped in unit-tests -exit status 1 +exit status 0 diff --git a/usr.bin/make/unit-tests/directive-for-empty.mk b/usr.bin/make/unit-tests/directive-for-empty.mk index 1c4cb0f1ad27..886f7430c682 100644 --- a/usr.bin/make/unit-tests/directive-for-empty.mk +++ b/usr.bin/make/unit-tests/directive-for-empty.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-for-empty.mk,v 1.3 2023/11/19 21:47:52 rillig Exp $ +# $NetBSD: directive-for-empty.mk,v 1.4 2024/05/31 07:13:12 rillig Exp $ # # Tests for .for loops containing conditions of the form 'empty(var:...)'. # @@ -26,23 +26,23 @@ # In conditions, the function call to 'empty' does not look like an # expression, therefore it is not replaced. Since there is no global variable -# named 'i', this expression makes for a leaky abstraction. If the .for +# named 'i', this condition makes for a leaky abstraction. If the .for # variables were real variables, calling 'empty' would work on them as well. .for i in 11 12 13 # Asking for an empty iteration variable does not make sense as the .for loop # splits the iteration items into words, and such a word cannot be empty. -. if empty(i) -# expect+3: Missing argument for ".error" -# expect+2: Missing argument for ".error" -# expect+1: Missing argument for ".error" -. error # due to the leaky abstraction +. if !empty(i) +. error # not reached, due to the leaky abstraction . endif -# The typical way of using 'empty' with variables from .for loops is pattern -# matching using the modifiers ':M' or ':N'. +# The typical way of mistakenly using 'empty' with variables from .for loops +# is pattern matching using the modifiers ':M' or ':N'. . if !empty(i:M*2*) -. if ${i} != "12" -. error -. endif +. error +. endif +# Instead of the 'empty' function, the variables from .for loops can be +# queried using conditions of the form '${var:...} != ""'. +. if $i == "12" && ${i:M*2*} != "12" +. error . endif .endfor @@ -122,3 +122,5 @@ CPPFLAGS+= -Dmacro="${empty(i):?empty:not-empty}" # TODO: Add code that demonstrates the current interaction between variables # from .for loops and the modifiers mentioned above. + +all: diff --git a/usr.bin/make/unit-tests/opt-debug-hash.exp b/usr.bin/make/unit-tests/opt-debug-hash.exp index 194b08daa5f2..d8b60450e222 100644 --- a/usr.bin/make/unit-tests/opt-debug-hash.exp +++ b/usr.bin/make/unit-tests/opt-debug-hash.exp @@ -1,4 +1,4 @@ -make: "opt-debug-hash.mk" line 12: Missing argument for ".error" +make: "opt-debug-hash.mk" line 13: Missing argument for ".error" make: Fatal errors encountered -- cannot continue HashTable targets: size=16 numEntries=0 maxchain=0 HashTable Global variables: size=16 numEntries= maxchain=3 diff --git a/usr.bin/make/unit-tests/opt-debug-hash.mk b/usr.bin/make/unit-tests/opt-debug-hash.mk index a1b21e145bf0..88edbedd6fd9 100644 --- a/usr.bin/make/unit-tests/opt-debug-hash.mk +++ b/usr.bin/make/unit-tests/opt-debug-hash.mk @@ -1,4 +1,4 @@ -# $NetBSD: opt-debug-hash.mk,v 1.4 2023/06/01 20:56:35 rillig Exp $ +# $NetBSD: opt-debug-hash.mk,v 1.5 2024/05/31 07:13:12 rillig Exp $ # # Tests for the -dh command line option, which adds debug logging for # hash tables. Even more detailed logging is available by compiling @@ -6,7 +6,8 @@ .MAKEFLAGS: -dh -# Force a parse error, to demonstrate the newline character in the diagnostic -# that had been missing before parse.c 1.655 from 2022-01-22. +# Force a parse error, to demonstrate the newline character in the "cannot +# continue" diagnostic that had been missing before parse.c 1.655 from +# 2022-01-22. # expect+1: Missing argument for ".error" .error