Skip to content

Commit

Permalink
xerrors: fix TestErrorf false positive when top-level dir is renamed
Browse files Browse the repository at this point in the history
The rePath pattern will typically replace two matches with "/path.":
one with the test's import path, like " /golang.org/x/xerrors_test.",
and a file path like " /Users/gopher/golang.org/x/xerrors/fmt_test.".

The former will always end with "/xerrors_test." as long as the module
path is still "golang.org/x/xerrors" and the TestErrorf test is inside
an xerrors_test package. The latter may not match xerrors.*test if the
top-level directory isn't named "xerrors". But it will always end with
"/fmt_test." as long as the TestErrorf test is still inside the file
named "fmt_test.go".

So look for those two patterns to fix false positive failures when the
git repository is cloned to a custom path without any "xerrors" in it.

Change-Id: I4d95121734337050309c2d989afd8f82430a2f31
Reviewed-on: https://go-review.googlesource.com/c/xerrors/+/609380
Reviewed-by: Ian Lance Taylor <[email protected]>
Auto-Submit: Dmitri Shuralyov <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
  • Loading branch information
dmitshur authored and gopherbot committed Sep 3, 2024
1 parent 93cc26a commit 9acd5f3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions fmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,14 +555,14 @@ type panicValue struct{}

func (panicValue) String() string { panic("panic") }

var rePath = regexp.MustCompile(`( [^ ]*)xerrors.*test\.`)
var reLine = regexp.MustCompile(":[0-9]*\n?$")
var rePath = regexp.MustCompile(`( [^ ]+)\/(xerrors_test|fmt_test)\.`)
var reLine = regexp.MustCompile(":[0-9]+\n?$")

func cleanPath(s string) string {
s = rePath.ReplaceAllString(s, "/path.")
s = reLine.ReplaceAllString(s, ":xxx")
s = strings.Replace(s, "\n ", "", -1)
s = strings.Replace(s, " /", "/", -1)
s = strings.ReplaceAll(s, "\n ", "")
s = strings.ReplaceAll(s, " /", "/")
return s
}

Expand Down

0 comments on commit 9acd5f3

Please sign in to comment.