diff --git a/internal/coverage/coverage.go b/internal/coverage/coverage.go index d7be532..f000486 100644 --- a/internal/coverage/coverage.go +++ b/internal/coverage/coverage.go @@ -203,5 +203,5 @@ func (c *Coverage) removeModuleFromPath(p *cover.Profile) string { path := strings.ReplaceAll(p.FileName, c.mod.Name+"/", "") path, _ = filepath.Rel(c.mod.CallingDir, path) - return path + return filepath.ToSlash(path) // normalize to slashes } diff --git a/internal/coverage/profile_test.go b/internal/coverage/profile_test.go index 880a64d..5863f4c 100644 --- a/internal/coverage/profile_test.go +++ b/internal/coverage/profile_test.go @@ -189,7 +189,7 @@ func TestIsCovered(t *testing.T) { for _, tc := range testCases { tCase := tc t.Run(tCase.name, func(t *testing.T) { - profile := coverage.Profile{ + profile := coverage.Profile { tCase.proFilename: { { StartLine: tCase.proStartL, @@ -215,3 +215,21 @@ func TestIsCovered(t *testing.T) { }) } } + +func TestIsCovered_PathsWithSlashes(t *testing.T) { + profile := coverage.Profile{ + "internal/coverage/file.go": []coverage.Block{ + {StartLine: 10, StartCol: 1, EndLine: 20, EndCol: 1}, + }, + } + + pos := token.Position{ + Filename: "internal/coverage/file.go", + Line: 15, + Column: 5, + } + + if !profile.IsCovered(pos) { + t.Error("expected position to be covered") + } +} diff --git a/internal/engine/stubs_test.go b/internal/engine/stubs_test.go index efa93f5..d7bc001 100644 --- a/internal/engine/stubs_test.go +++ b/internal/engine/stubs_test.go @@ -18,6 +18,7 @@ package engine_test import ( "errors" + "fmt" "go/token" "io" "os" @@ -56,8 +57,15 @@ func viperReset() { func loadFixture(fixture, fromPackage string) (fstest.MapFS, gomodule.GoModule, func()) { //nolint:gosec // test code reading test fixtures - f, _ := os.Open(fixture) - src, _ := io.ReadAll(f) + f, err := os.Open(fixture) + if err != nil { + panic(fmt.Sprintf("failed to open test fixture %s: %v", fixture, err)) + } + src, err := io.ReadAll(f) + if err != nil { + _ = f.Close() + panic(fmt.Sprintf("failed to read test fixture %s: %v", fixture, err)) + } filename := filenameFromFixture(fixture) mapFS := fstest.MapFS{ filename: {Data: src},