Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/add prefix #506

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
21 changes: 11 additions & 10 deletions formatters/source_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ func NewSourceFile(name string, commit *object.Commit) (SourceFile, error) {
}
}

if addPrefix, err := envy.MustGet("ADD_PREFIX"); err == nil {
if addPrefix != "" {
logrus.Printf("adding prefix %s", addPrefix)
if strings.HasSuffix(addPrefix, string(os.PathSeparator)) {
name = addPrefix + name
} else {
name = addPrefix + string(os.PathSeparator) + name
}
}
}

sf := SourceFile{
Name: name,
Coverage: Coverage{},
Expand All @@ -103,16 +114,6 @@ func NewSourceFile(name string, commit *object.Commit) (SourceFile, error) {
return sf, errors.WithStack(err)
}

if addPrefix, err := envy.MustGet("ADD_PREFIX"); err == nil {
if addPrefix != "" {
if strings.HasSuffix(addPrefix, string(os.PathSeparator)) {
sf.Name = addPrefix + sf.Name
} else {
sf.Name = addPrefix + string(os.PathSeparator) + sf.Name
}
}
}

return sf, nil
}

Expand Down
13 changes: 6 additions & 7 deletions formatters/source_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,22 @@ func Test_SourceFile_Merge_With_Mismatch_Blob_Id(t *testing.T) {

func Test_SourceFile_AddPrefix(t *testing.T) {
envy.Temp(func() {
envy.Set("ADD_PREFIX", "test-prefix")
envy.Set("PREFIX", ".")
envy.Set("ADD_PREFIX", "lcov")
r := require.New(t)
sf, err := NewSourceFile("./coverage.go", nil)
sf, err := NewSourceFile("example.info", nil)
r.NoError(err)
r.Equal(sf.Name, "test-prefix/coverage.go")
r.Equal(sf.Name, "lcov/example.info")
})
}

func Test_SourceFile_AddPrefixWithPathSeparator(t *testing.T) {
envy.Temp(func() {
envy.Set("ADD_PREFIX", "test-prefix/")
envy.Set("ADD_PREFIX", "lcov/")
envy.Set("PREFIX", ".")
r := require.New(t)
sf, err := NewSourceFile("./coverage.go", nil)
sf, err := NewSourceFile("./example.info", nil)
r.NoError(err)
r.Equal(sf.Name, "test-prefix/coverage.go")
r.Equal(sf.Name, "lcov/example.info")
})
}

Expand Down