]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/testdir: filter out errors outside input file set
authorJake Bailey <jacob.b.bailey@gmail.com>
Wed, 14 May 2025 05:01:43 +0000 (22:01 -0700)
committerMichael Pratt <mpratt@google.com>
Tue, 20 May 2025 17:15:47 +0000 (10:15 -0700)
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 <mknyszek@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Pratt <mpratt@google.com>

src/cmd/internal/testdir/testdir_test.go

index 7e7867d83f9c47ad19c3d682f9c000e07e7c06ef..483a9ec33c67987725f3c7fa8aba7edb0b39c060 100644 (file)
@@ -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 {