Skip to content

Commit 2a65100

Browse files
jakebaileyprattmic
authored andcommitted
cmd/internal/testdir: filter out errors outside input file set
When an errorcheck test uses -m and instantiates an imported generic function, the errors will include -m messages from the imported package (since the new function has not previously been walked). These errors cannot be matched since we can't write errors in files outside the test input. To fix this (and enable the other CLs in this stack), drop any unmatched errors that occur in files outside those in the input set. Change-Id: I2fcf0dd4693125d2e5823ea4437011730d8b1b1f Reviewed-on: https://go-review.googlesource.com/c/go/+/672515 Reviewed-by: Michael Knyszek <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Michael Pratt <[email protected]>
1 parent ff9da9b commit 2a65100

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/cmd/internal/testdir/testdir_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,24 @@ func (t test) errorCheck(outStr string, wantAuto bool, fullshort ...string) (err
12421242
}
12431243
}
12441244

1245+
if len(out) > 0 {
1246+
// If a test uses -m and instantiates an imported generic function,
1247+
// the errors will include messages for the instantiated function
1248+
// with locations in the other package. Filter those out.
1249+
localOut := make([]string, 0, len(out))
1250+
outLoop:
1251+
for _, errLine := range out {
1252+
for j := 0; j < len(fullshort); j += 2 {
1253+
full, short := fullshort[j], fullshort[j+1]
1254+
if strings.HasPrefix(errLine, full+":") || strings.HasPrefix(errLine, short+":") {
1255+
localOut = append(localOut, errLine)
1256+
continue outLoop
1257+
}
1258+
}
1259+
}
1260+
out = localOut
1261+
}
1262+
12451263
if len(out) > 0 {
12461264
errs = append(errs, fmt.Errorf("Unmatched Errors:"))
12471265
for _, errLine := range out {

0 commit comments

Comments
 (0)