Skip to content

Commit f2d7b5b

Browse files
committed
fix test
1 parent 96bb59b commit f2d7b5b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

pkg/testcoverage/coverage/cover_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"golang.org/x/tools/cover"
99

1010
. "github.com/vladopajic/go-test-coverage/v2/pkg/testcoverage/coverage"
11+
"github.com/vladopajic/go-test-coverage/v2/pkg/testcoverage/path"
1112
"github.com/vladopajic/go-test-coverage/v2/pkg/testcoverage/testdata"
1213
)
1314

@@ -97,12 +98,12 @@ func Test_findFile(t *testing.T) {
9798
file, noPrefixName, err := FindFile(prefix+"/"+filename, "")
9899
assert.NoError(t, err)
99100
assert.Equal(t, filename, noPrefixName)
100-
assert.True(t, strings.HasSuffix(file, filename))
101+
assert.True(t, strings.HasSuffix(file, path.NormalizeForOS(filename)))
101102

102103
file, noPrefixName, err = FindFile(prefix+"/"+filename, prefix)
103104
assert.NoError(t, err)
104105
assert.Equal(t, filename, noPrefixName)
105-
assert.True(t, strings.HasSuffix(file, filename))
106+
assert.True(t, strings.HasSuffix(file, path.NormalizeForOS(filename)))
106107

107108
_, _, err = FindFile(prefix+"/main1.go", "")
108109
assert.Error(t, err)

pkg/testcoverage/path/path.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ import (
88

99
const separatorToReplace = string(filepath.Separator)
1010

11+
func NormalizeForOS(path string) string {
12+
if runtime.GOOS != "windows" {
13+
return path
14+
}
15+
16+
return strings.ReplaceAll(path, "/", separatorToReplace)
17+
}
18+
1119
func NormalizeForTool(path string) string {
1220
if runtime.GOOS != "windows" {
1321
return path

0 commit comments

Comments
 (0)