From 9acd5f35470b8cdc21e52619afc29ae48e8824f2 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Sun, 1 Sep 2024 15:36:58 -0400 Subject: [PATCH] xerrors: fix TestErrorf false positive when top-level dir is renamed 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 Auto-Submit: Dmitri Shuralyov LUCI-TryBot-Result: Go LUCI Reviewed-by: Dmitri Shuralyov --- fmt_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fmt_test.go b/fmt_test.go index 99d945f..1ee7e6f 100644 --- a/fmt_test.go +++ b/fmt_test.go @@ -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 }