Skip to content

Commit 10926ad

Browse files
committed
fix
1 parent 855ee3e commit 10926ad

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

pkg/testcoverage/coverage/cover_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package coverage_test
22

33
import (
4+
"runtime"
45
"strings"
56
"testing"
67

@@ -21,11 +22,16 @@ const (
2122
profileNOK = testdataDir + testdata.ProfileNOK
2223
profileNOKInvalidLength = testdataDir + testdata.ProfileNOKInvalidLength
2324
profileNOKInvalidData = testdataDir + testdata.ProfileNOKInvalidData
24-
25-
prefix = "github.com/vladopajic/go-test-coverage/v2"
26-
coverFilename = "pkg/testcoverage/coverage/cover.go"
2725
)
2826

27+
var prefix = func() string { //nolint:gochecknoglobals // relax
28+
if runtime.GOOS == "windows" {
29+
return "go-test-coverage/go-test-coverage"
30+
}
31+
32+
return "github.com/vladopajic/go-test-coverage/v2"
33+
}()
34+
2935
func Test_GenerateCoverageStats(t *testing.T) {
3036
t.Parallel()
3137

pkg/testcoverage/coverage/export_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var (
66
FindFuncsAndBlocks = findFuncsAndBlocks
77
ParseProfiles = parseProfiles
88
CoverageForFile = coverageForFile
9+
StripPrefix = stripPrefix
910
)
1011

1112
type Extent = extent

pkg/testcoverage/coverage/types_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,39 @@ func TestCoveredPercentage(t *testing.T) {
2828
assert.Equal(t, tc.percentage, CoveredPercentage(tc.total, tc.covered))
2929
}
3030
}
31+
32+
func TestStripPrefix(t *testing.T) {
33+
t.Parallel()
34+
35+
tests := []struct {
36+
file string
37+
prefix string
38+
noPrefix string
39+
}{
40+
{
41+
file: "github.com/example/foo/bar.go",
42+
prefix: "github.com/example",
43+
noPrefix: "foo/bar.go",
44+
},
45+
{
46+
file: "github.com/example/foo/bar.go",
47+
prefix: "github.com/example/",
48+
noPrefix: "foo/bar.go",
49+
},
50+
{
51+
file: "github.com/example/foo/bar.go",
52+
prefix: "example/foo",
53+
noPrefix: "bar.go",
54+
},
55+
{
56+
file: "github.com/example/foo/bar.go",
57+
prefix: "github.com/example1/",
58+
noPrefix: "github.com/example/foo/bar.go",
59+
},
60+
}
61+
62+
for _, tc := range tests {
63+
name := StripPrefix(tc.file, tc.prefix)
64+
assert.Equal(t, tc.noPrefix, name)
65+
}
66+
}

0 commit comments

Comments
 (0)