From 311e2b2911cd4cf2fbe52f48563dbf76abe95f55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlado=20Paji=C4=87?= Date: Tue, 11 Mar 2025 20:32:52 +0100 Subject: [PATCH] chore(coverage): cosmetics --- pkg/testcoverage/coverage/cover.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/testcoverage/coverage/cover.go b/pkg/testcoverage/coverage/cover.go index 3710ba6..2a0cfbe 100644 --- a/pkg/testcoverage/coverage/cover.go +++ b/pkg/testcoverage/coverage/cover.go @@ -148,23 +148,21 @@ func findFileCreator(rootDir string) func(file string) (string, string, bool) { rootDir = defaultRootDir(rootDir) prefix := findModuleDirective(rootDir) files := listAllFiles(rootDir) - findWalk := func(file, prefix string) (string, string, bool) { + findFsSearch := func(file string) (string, string, bool) { noPrefixName := stripPrefix(file, prefix) - f, found := hasFile(files, noPrefixName) + fPath := hasFile(files, noPrefixName) - return path.NormalizeForOS(f), noPrefixName, found + return path.NormalizeForOS(fPath), noPrefixName, fPath != "" } return func(fileName string) (string, string, bool) { - if path, name, found := findWalk(fileName, prefix); found { + if path, name, found := findFsSearch(fileName); found { return path, name, found } - if path, name, found := findBuildImport(fileName); found { - return path, name, found - } - - return "", "", false + // when file is not find searching file system, search will fallback to + // searching using build.Import, which can be slower on some systems (windows) + return findBuildImport(fileName) } } @@ -207,20 +205,22 @@ func listAllFiles(rootDir string) []fileInfo { return files } -func hasFile(files []fileInfo, search string) (string, bool) { +func hasFile(files []fileInfo, search string) string { var result string for _, f := range files { if strings.HasSuffix(f.name, search) { if result != "" { - return "", false + // when multiple files are found with same suffix + // assume file is not found (fallback mechanism will be used) + return "" } result = f.path } } - return result, result != "" + return result } func findAnnotations(source []byte) ([]extent, error) {