Module Name: src Committed By: rillig Date: Sun May 8 06:51:27 UTC 2022
Modified Files: src/distrib/sets/lists/tests: mi src/usr.bin/make/unit-tests: Makefile comment.mk compat-error.mk cond-cmp-string.mk cond-func-defined.mk cond-token-string.exp cond-token-string.mk directive-for-lines.mk directive-for-null.mk directive-info.mk opt-jobs-no-action.mk varmod-ifelse.mk varmod-match.mk Removed Files: src/usr.bin/make/unit-tests: cond1.exp cond1.mk Log Message: tests/make: migrate cond1 test to other, more specific tests The tests in cond1 were a mixture of "everything related to conditions", and the test cases were heavily dependent on each other, which made them hard to understand. Move each test case to its corresponding special-purpose test. To generate a diff of this commit: cvs rdiff -u -r1.1201 -r1.1202 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.313 -r1.314 src/usr.bin/make/unit-tests/Makefile cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/comment.mk \ src/usr.bin/make/unit-tests/compat-error.mk \ src/usr.bin/make/unit-tests/cond-token-string.mk cvs rdiff -u -r1.15 -r1.16 src/usr.bin/make/unit-tests/cond-cmp-string.mk cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/cond-func-defined.mk \ src/usr.bin/make/unit-tests/varmod-match.mk cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/cond-token-string.exp cvs rdiff -u -r1.5 -r0 src/usr.bin/make/unit-tests/cond1.exp cvs rdiff -u -r1.3 -r0 src/usr.bin/make/unit-tests/cond1.mk cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/directive-for-lines.mk cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/directive-for-null.mk cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/directive-info.mk \ src/usr.bin/make/unit-tests/opt-jobs-no-action.mk cvs rdiff -u -r1.18 -r1.19 src/usr.bin/make/unit-tests/varmod-ifelse.mk Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.1201 src/distrib/sets/lists/tests/mi:1.1202 --- src/distrib/sets/lists/tests/mi:1.1201 Fri Apr 29 22:17:50 2022 +++ src/distrib/sets/lists/tests/mi Sun May 8 06:51:27 2022 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1201 2022/04/29 22:17:50 pgoyette Exp $ +# $NetBSD: mi,v 1.1202 2022/05/08 06:51:27 rillig Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -5459,8 +5459,8 @@ ./usr/tests/usr.bin/make/unit-tests/cond-token-var.mk tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/cond-undef-lint.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/cond-undef-lint.mk tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/make/unit-tests/cond1.exp tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/make/unit-tests/cond1.mk tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/make/unit-tests/cond1.exp tests-obsolete obsolete,atf +./usr/tests/usr.bin/make/unit-tests/cond1.mk tests-obsolete obsolete,atf ./usr/tests/usr.bin/make/unit-tests/cond2.exp obsolete-tests obsolete ./usr/tests/usr.bin/make/unit-tests/cond2.mk obsolete-tests obsolete ./usr/tests/usr.bin/make/unit-tests/counter-append.exp tests-usr.bin-tests compattestfile,atf Index: src/usr.bin/make/unit-tests/Makefile diff -u src/usr.bin/make/unit-tests/Makefile:1.313 src/usr.bin/make/unit-tests/Makefile:1.314 --- src/usr.bin/make/unit-tests/Makefile:1.313 Sat May 7 17:49:47 2022 +++ src/usr.bin/make/unit-tests/Makefile Sun May 8 06:51:27 2022 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.313 2022/05/07 17:49:47 rillig Exp $ +# $NetBSD: Makefile,v 1.314 2022/05/08 06:51:27 rillig Exp $ # # Unit tests for make(1) # @@ -84,7 +84,6 @@ TESTS+= cond-token-plain TESTS+= cond-token-string TESTS+= cond-token-var TESTS+= cond-undef-lint -TESTS+= cond1 TESTS+= counter TESTS+= counter-append TESTS+= dep Index: src/usr.bin/make/unit-tests/comment.mk diff -u src/usr.bin/make/unit-tests/comment.mk:1.4 src/usr.bin/make/unit-tests/comment.mk:1.5 --- src/usr.bin/make/unit-tests/comment.mk:1.4 Sun Jan 23 18:00:53 2022 +++ src/usr.bin/make/unit-tests/comment.mk Sun May 8 06:51:27 2022 @@ -1,4 +1,4 @@ -# $NetBSD: comment.mk,v 1.4 2022/01/23 18:00:53 rillig Exp $ +# $NetBSD: comment.mk,v 1.5 2022/05/08 06:51:27 rillig Exp $ # # Demonstrate how comments are written in makefiles. @@ -23,7 +23,7 @@ on and on. .endif # And after the closing directive. VAR= # This comment makes the variable value empty. - # ParseGetLine removes any whitespace before the + # ParseRawLine removes any whitespace before the # comment. .if ${VAR} != "" . error Index: src/usr.bin/make/unit-tests/compat-error.mk diff -u src/usr.bin/make/unit-tests/compat-error.mk:1.4 src/usr.bin/make/unit-tests/compat-error.mk:1.5 --- src/usr.bin/make/unit-tests/compat-error.mk:1.4 Sat May 7 08:01:20 2022 +++ src/usr.bin/make/unit-tests/compat-error.mk Sun May 8 06:51:27 2022 @@ -1,14 +1,21 @@ -# $NetBSD: compat-error.mk,v 1.4 2022/05/07 08:01:20 rillig Exp $ +# $NetBSD: compat-error.mk,v 1.5 2022/05/08 06:51:27 rillig Exp $ # # Test detailed error handling in compat mode. # -# Until 2020-12-13, .ERROR_TARGET was success3, which was wrong. -# Since compat.c 1.215 from 2020-12-13, it is 'fail1', which is the first -# failed top-level target. XXX: Even better would be if .ERROR_TARGET were -# the smallest target that caused the build to fail, even if it were a -# sub-sub-sub-dependency of a top-level target. +# Make several targets that alternately succeed and fail. # -# XXX: As of 2020-12-13, .ERROR_CMD is empty, which is wrong. +# The first failing top-level target is recorded in '.ERROR_TARGET'. While +# this information may give a hint as to which target failed, it would be more +# useful at that point to know the actual target that failed, or the complete +# chain from root cause to top-level target. +# +# Historic bugs +# Before compat.c 1.215 from 2020-12-13, '.ERROR_TARGET' was 'success3', +# which was obviously wrong. +# +# Bugs +# As of 2020-12-13, '.ERROR_CMD' is empty, which does not provide any +# insight into the command that actually failed. # # See also: # Compat_MakeAll @@ -20,10 +27,10 @@ # 2020: LstNode_SetNull(cmdNode); # # The commit that skipped NULL commands for .ERROR_CMD: -# CVS: 2016.08.11.19.53.?? +# CVS: 2016.08.11.19.53.17 # Git: 58b23478b7353d46457089e726b07a49197388e4 -.MAKEFLAGS: success1 fail1 success2 fail2 success3 +.MAKEFLAGS: -k success1 fail1 success2 fail2 success3 success1 success2 success3: : Making ${.TARGET} out of nothing. Index: src/usr.bin/make/unit-tests/cond-token-string.mk diff -u src/usr.bin/make/unit-tests/cond-token-string.mk:1.4 src/usr.bin/make/unit-tests/cond-token-string.mk:1.5 --- src/usr.bin/make/unit-tests/cond-token-string.mk:1.4 Thu Jan 21 00:38:28 2021 +++ src/usr.bin/make/unit-tests/cond-token-string.mk Sun May 8 06:51:27 2022 @@ -1,4 +1,4 @@ -# $NetBSD: cond-token-string.mk,v 1.4 2021/01/21 00:38:28 rillig Exp $ +# $NetBSD: cond-token-string.mk,v 1.5 2022/05/08 06:51:27 rillig Exp $ # # Tests for quoted string literals in .if conditions. # @@ -76,7 +76,22 @@ . info An empty variable evaluates to false. .endif +# A non-empty string evaluates to true, no matter if it's a literal string or +# if it contains variable expressions. +VAR= value +.if ("${VALUE}") +.else +. error +.endif + +# In the conditions in .if directives, the left-hand side of a comparison must +# be enclosed in quotes. The right-hand side does not need to be enclosed in +# quotes. +.if "quoted" == quoted +.else +. error +.endif + .MAKEFLAGS: -d0 -all: - @:; +all: .PHONY Index: src/usr.bin/make/unit-tests/cond-cmp-string.mk diff -u src/usr.bin/make/unit-tests/cond-cmp-string.mk:1.15 src/usr.bin/make/unit-tests/cond-cmp-string.mk:1.16 --- src/usr.bin/make/unit-tests/cond-cmp-string.mk:1.15 Sat Dec 11 09:53:53 2021 +++ src/usr.bin/make/unit-tests/cond-cmp-string.mk Sun May 8 06:51:27 2022 @@ -1,4 +1,4 @@ -# $NetBSD: cond-cmp-string.mk,v 1.15 2021/12/11 09:53:53 rillig Exp $ +# $NetBSD: cond-cmp-string.mk,v 1.16 2022/05/08 06:51:27 rillig Exp $ # # Tests for string comparisons in .if conditions. @@ -136,3 +136,11 @@ .else . error .endif + +# Two variables with different values compare unequal. +VAR1= value1 +VAR2= value2 +.if ${VAR1} != ${VAR2} +.else +. error +.endif Index: src/usr.bin/make/unit-tests/cond-func-defined.mk diff -u src/usr.bin/make/unit-tests/cond-func-defined.mk:1.8 src/usr.bin/make/unit-tests/cond-func-defined.mk:1.9 --- src/usr.bin/make/unit-tests/cond-func-defined.mk:1.8 Sun Dec 12 08:55:28 2021 +++ src/usr.bin/make/unit-tests/cond-func-defined.mk Sun May 8 06:51:27 2022 @@ -1,4 +1,4 @@ -# $NetBSD: cond-func-defined.mk,v 1.8 2021/12/12 08:55:28 rillig Exp $ +# $NetBSD: cond-func-defined.mk,v 1.9 2022/05/08 06:51:27 rillig Exp $ # # Tests for the defined() function in .if conditions. @@ -48,5 +48,10 @@ ${:UA B}= variable name with spaces . endif .endfor -all: - @:; +# Neither of the conditions is true. Before July 2020, the right-hand +# condition was evaluated even though it was irrelevant. +.if defined(UNDEF) && ${UNDEF:Mx} != "" +. error +.endif + +all: .PHONY Index: src/usr.bin/make/unit-tests/varmod-match.mk diff -u src/usr.bin/make/unit-tests/varmod-match.mk:1.8 src/usr.bin/make/unit-tests/varmod-match.mk:1.9 --- src/usr.bin/make/unit-tests/varmod-match.mk:1.8 Sun Mar 27 18:39:01 2022 +++ src/usr.bin/make/unit-tests/varmod-match.mk Sun May 8 06:51:27 2022 @@ -1,4 +1,4 @@ -# $NetBSD: varmod-match.mk,v 1.8 2022/03/27 18:39:01 rillig Exp $ +# $NetBSD: varmod-match.mk,v 1.9 2022/05/08 06:51:27 rillig Exp $ # # Tests for the :M variable modifier, which filters words that match the # given pattern. @@ -184,3 +184,19 @@ ${:U*}= asterisk .if ${ plain string :L:M*} != "plain string" . error .endif + + +# The pattern can come from a variable expression. For single-letter +# variables, either the short form or the long form can be used, just as +# everywhere else. +PRIMES= 2 3 5 7 11 +n= 2 +.if ${PRIMES:M$n} != "2" +. error +.endif +.if ${PRIMES:M${n}} != "2" +. error +.endif +.if ${PRIMES:M${:U2}} != "2" +. error +.endif Index: src/usr.bin/make/unit-tests/cond-token-string.exp diff -u src/usr.bin/make/unit-tests/cond-token-string.exp:1.7 src/usr.bin/make/unit-tests/cond-token-string.exp:1.8 --- src/usr.bin/make/unit-tests/cond-token-string.exp:1.7 Sat Jan 8 20:21:34 2022 +++ src/usr.bin/make/unit-tests/cond-token-string.exp Sun May 8 06:51:27 2022 @@ -13,6 +13,10 @@ CondParser_Eval: "${:Uvalue}" make: "cond-token-string.mk" line 68: A nonempty variable expression evaluates to true. CondParser_Eval: "${:U}" make: "cond-token-string.mk" line 76: An empty variable evaluates to false. +CondParser_Eval: ("${VALUE}") +make: "cond-token-string.mk" line 84: Missing argument for ".error" +CondParser_Eval: "quoted" == quoted +Comparing "quoted" == "quoted" make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 Index: src/usr.bin/make/unit-tests/directive-for-lines.mk diff -u src/usr.bin/make/unit-tests/directive-for-lines.mk:1.3 src/usr.bin/make/unit-tests/directive-for-lines.mk:1.4 --- src/usr.bin/make/unit-tests/directive-for-lines.mk:1.3 Sat Dec 19 12:40:00 2020 +++ src/usr.bin/make/unit-tests/directive-for-lines.mk Sun May 8 06:51:27 2022 @@ -1,9 +1,9 @@ -# $NetBSD: directive-for-lines.mk,v 1.3 2020/12/19 12:40:00 rillig Exp $ +# $NetBSD: directive-for-lines.mk,v 1.4 2022/05/08 06:51:27 rillig Exp $ # # Tests for the line numbers that are reported in .for loops. # -# Between 2007-01-01 (git 4d3c468f96e1080e, parse.c 1.127) and 2020-12-19 -# (parse.c 1.494), the line numbers for the .info directives and error +# Since parse.c 1.127 from 2007-01-01 and before parse.c 1.494 from +# 2020-12-19, the line numbers for the .info directives and error # messages inside .for loops had been wrong since ParseGetLine skipped empty # lines, even when collecting the lines for the .for loop body. Index: src/usr.bin/make/unit-tests/directive-for-null.mk diff -u src/usr.bin/make/unit-tests/directive-for-null.mk:1.1 src/usr.bin/make/unit-tests/directive-for-null.mk:1.2 --- src/usr.bin/make/unit-tests/directive-for-null.mk:1.1 Sat Dec 19 16:00:17 2020 +++ src/usr.bin/make/unit-tests/directive-for-null.mk Sun May 8 06:51:27 2022 @@ -1,4 +1,4 @@ -# $NetBSD: directive-for-null.mk,v 1.1 2020/12/19 16:00:17 rillig Exp $ +# $NetBSD: directive-for-null.mk,v 1.2 2022/05/08 06:51:27 rillig Exp $ # # Test for parsing a .for loop that accidentally contains a null byte. # @@ -9,7 +9,7 @@ # make: "(stdin)" line 3: Zero byte read from file # # The one about "end of file" might be misleading but is due to the -# implementation. On both errors and EOF, ParseGetLine returns NULL. +# implementation. On both errors and EOF, ParseRawLine returns NULL. # # The one about the "zero byte" in line 3 is surprising since the only # line that contains a null byte is line 2. Index: src/usr.bin/make/unit-tests/directive-info.mk diff -u src/usr.bin/make/unit-tests/directive-info.mk:1.9 src/usr.bin/make/unit-tests/directive-info.mk:1.10 --- src/usr.bin/make/unit-tests/directive-info.mk:1.9 Sat Jan 8 20:21:34 2022 +++ src/usr.bin/make/unit-tests/directive-info.mk Sun May 8 06:51:27 2022 @@ -1,4 +1,4 @@ -# $NetBSD: directive-info.mk,v 1.9 2022/01/08 20:21:34 rillig Exp $ +# $NetBSD: directive-info.mk,v 1.10 2022/05/08 06:51:27 rillig Exp $ # # Tests for the .info directive. # @@ -18,7 +18,7 @@ .info.man: # not a message, but possibly a suffix rule # Even if lines would have trailing whitespace, this would be trimmed by -# ParseGetLine. +# ParseRawLine. .info .info # comment Index: src/usr.bin/make/unit-tests/opt-jobs-no-action.mk diff -u src/usr.bin/make/unit-tests/opt-jobs-no-action.mk:1.9 src/usr.bin/make/unit-tests/opt-jobs-no-action.mk:1.10 --- src/usr.bin/make/unit-tests/opt-jobs-no-action.mk:1.9 Sun Apr 4 09:58:51 2021 +++ src/usr.bin/make/unit-tests/opt-jobs-no-action.mk Sun May 8 06:51:27 2022 @@ -1,4 +1,4 @@ -# $NetBSD: opt-jobs-no-action.mk,v 1.9 2021/04/04 09:58:51 rillig Exp $ +# $NetBSD: opt-jobs-no-action.mk,v 1.10 2022/05/08 06:51:27 rillig Exp $ # # Tests for the combination of the options -j and -n, which prints the # commands instead of actually running them. @@ -21,7 +21,7 @@ # The shell attributes are handled by Job_ParseShell. # The shell attributes 'quiet' and 'echo' don't need a trailing newline, # this is handled by the [0] != '\0' checks in Job_ParseShell. -# The '\#' is handled by ParseGetLine. +# The '\#' is handled by ParseRawLine. # The '\n' is handled by Str_Words in Job_ParseShell. # The '$$' is handled by Var_Subst in ParseDependencyLine. .SHELL: \ Index: src/usr.bin/make/unit-tests/varmod-ifelse.mk diff -u src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.18 src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.19 --- src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.18 Sat Jan 15 20:16:55 2022 +++ src/usr.bin/make/unit-tests/varmod-ifelse.mk Sun May 8 06:51:27 2022 @@ -1,4 +1,4 @@ -# $NetBSD: varmod-ifelse.mk,v 1.18 2022/01/15 20:16:55 rillig Exp $ +# $NetBSD: varmod-ifelse.mk,v 1.19 2022/05/08 06:51:27 rillig Exp $ # # Tests for the ${cond:?then:else} variable modifier, which evaluates either # the then-expression or the else-expression, depending on the condition. @@ -133,7 +133,7 @@ VAR= value # When parsing such an expression, the parser used to be strict. It first # evaluated the left-hand side of the operator '&&' and then started parsing # the right-hand side 'no >= 10'. The word 'no' is obviously a string -# literal, not enclosed in quotes, which is ok, even on the left-hand side of +# literal, not enclosed in quotes, which is OK, even on the left-hand side of # the comparison operator, but only because this is a condition in the # modifier ':?'. In an ordinary directive '.if', this would be a parse error. # For strings, only the comparison operators '==' and '!=' are defined, @@ -169,3 +169,16 @@ EMPTY= # empty .info ${${ASTERISK} :?true:false} # syntax error since the condition is completely blank. .info ${${EMPTY} :?true:false} + + +# Since the condition of the '?:' modifier is expanded before being parsed and +# evaluated, it is common practice to enclose expressions in quotes, to avoid +# producing syntactically invalid conditions such as ' == value'. This only +# works if the expanded values neither contain quotes nor backslashes. For +# strings containing quotes or backslashes, the '?:' modifier should not be +# used. +PRIMES= 2 3 5 7 11 +.if ${1 2 3 4 5:L:@n@$n:${ ("${PRIMES:M$n}" != "") :?prime:not_prime}@} != \ + "1:not_prime 2:prime 3:prime 4:not_prime 5:prime" +. error +.endif