diff --git a/formatters/source_file.go b/formatters/source_file.go index e95f0562..edbd68eb 100644 --- a/formatters/source_file.go +++ b/formatters/source_file.go @@ -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{}, @@ -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 } diff --git a/formatters/source_file_test.go b/formatters/source_file_test.go index c4ee54f8..37d3eb10 100644 --- a/formatters/source_file_test.go +++ b/formatters/source_file_test.go @@ -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") }) }