Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/coverage/coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
20 changes: 19 additions & 1 deletion internal/coverage/profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
}
}
12 changes: 10 additions & 2 deletions internal/engine/stubs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package engine_test

import (
"errors"
"fmt"
"go/token"
"io"
"os"
Expand Down Expand Up @@ -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},
Expand Down