Thu Jan 20 19:16:25 2022 UTC ()
tests/make: refine test for wrong diagnostic line

To trigger the faulty code path, the file where the targets gets its
first command must be included via its relative path.  That was the case
when running 'cd usr.bin/make && make test' but not when running the
tests via ATF.


(rillig)
diff -r1.1 -r1.2 src/usr.bin/make/unit-tests/dep-duplicate.exp
diff -r1.1 -r1.2 src/usr.bin/make/unit-tests/dep-duplicate.mk

cvs diff -r1.1 -r1.2 src/usr.bin/make/unit-tests/dep-duplicate.exp (expand / switch to unified diff)

--- src/usr.bin/make/unit-tests/dep-duplicate.exp 2022/01/19 22:10:41 1.1
+++ src/usr.bin/make/unit-tests/dep-duplicate.exp 2022/01/20 19:16:25 1.2
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
1make: "dep-duplicate.inc" line 1: warning: duplicate script for target "all" ignored 1make: "dep-duplicate.inc" line 1: warning: duplicate script for target "all" ignored
2make: "dep-duplicate.inc" line 15: warning: using previous script for "all" defined here 2make: "dep-duplicate.inc" line 3: warning: using previous script for "all" defined here
3first 3main-output
4exit status 0 4exit status 0

cvs diff -r1.1 -r1.2 src/usr.bin/make/unit-tests/dep-duplicate.mk (expand / switch to unified diff)

--- src/usr.bin/make/unit-tests/dep-duplicate.mk 2022/01/19 22:10:41 1.1
+++ src/usr.bin/make/unit-tests/dep-duplicate.mk 2022/01/20 19:16:25 1.2
@@ -1,21 +1,31 @@ @@ -1,21 +1,31 @@
1# $NetBSD: dep-duplicate.mk,v 1.1 2022/01/19 22:10:41 rillig Exp $ 1# $NetBSD: dep-duplicate.mk,v 1.2 2022/01/20 19:16:25 rillig Exp $
2# 2#
3# Test for a target whose commands are defined twice. This generates a 3# Test for a target whose commands are defined twice. This generates a
4# warning, not an error, so ensure that the correct commands are kept. 4# warning, not an error, so ensure that the correct commands are kept.
5# 5#
6# Also ensure that the diagnostics mention the correct file in case of 6# Also ensure that the diagnostics mention the correct file in case of
7# included files. This particular case had been broken in parse.c 1.231 from 7# included files. Since parse.c 1.231 from 2018-12-22 and before parse.c
8# 2018-12-22. 8# 1.653 from 2022-01-20, the wrong filename had been printed if the file of
 9# the first commands section was in a file that was included by its relative
 10# path.
9 11
10# expect: make: "dep-duplicate.inc" line 15: warning: using previous script for "all" defined here 12# expect: make: "dep-duplicate.inc" line 3: warning: using previous script for "all" defined here
11# FIXME: The file "dep-duplicate.inc" has no line 15. 13# FIXME: The file "dep-duplicate.inc" has no line 3.
12 14
13# expect: first 
14all: .PHONY 15all: .PHONY
15 @echo first 16 @exec > dep-duplicate.main; \
 17 echo '# empty line 1'; \
 18 echo '# empty line 2'; \
 19 echo 'all:; @echo main-output'; \
 20 echo '.include "dep-duplicate.inc"'
16 21
17_!= echo 'all:;echo second' > dep-duplicate.inc 22 @exec > dep-duplicate.inc; \
18.include "${.CURDIR}/dep-duplicate.inc" 23 echo 'all:; @echo inc-output'
19 24
20.END: 25 # The main file must be specified using a relative path, just like the
 26 # default 'makefile' or 'Makefile', to produce the same result when
 27 # run via ATF or 'make test'.
 28 @${MAKE} -r -f dep-duplicate.main
 29
 30 @rm -f dep-duplicate.main
21 @rm -f dep-duplicate.inc 31 @rm -f dep-duplicate.inc