From: Jake Bailey Date: Wed, 14 May 2025 05:01:43 +0000 (-0700) Subject: cmd/internal/testdir: filter out errors outside input file set X-Git-Tag: go1.25rc1~205 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2a65100e68cd82172b214a4d12cd2586c0b9ef99;p=gostls13.git 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 Reviewed-by: Keith Randall Reviewed-by: Keith Randall LUCI-TryBot-Result: Go LUCI Auto-Submit: Michael Pratt --- diff --git a/src/cmd/internal/testdir/testdir_test.go b/src/cmd/internal/testdir/testdir_test.go index 7e7867d83f..483a9ec33c 100644 --- a/src/cmd/internal/testdir/testdir_test.go +++ b/src/cmd/internal/testdir/testdir_test.go @@ -1242,6 +1242,24 @@ func (t test) errorCheck(outStr string, wantAuto bool, fullshort ...string) (err } } + if len(out) > 0 { + // If a test uses -m and instantiates an imported generic function, + // the errors will include messages for the instantiated function + // with locations in the other package. Filter those out. + localOut := make([]string, 0, len(out)) + outLoop: + for _, errLine := range out { + for j := 0; j < len(fullshort); j += 2 { + full, short := fullshort[j], fullshort[j+1] + if strings.HasPrefix(errLine, full+":") || strings.HasPrefix(errLine, short+":") { + localOut = append(localOut, errLine) + continue outLoop + } + } + } + out = localOut + } + if len(out) > 0 { errs = append(errs, fmt.Errorf("Unmatched Errors:")) for _, errLine := range out {