From 80e52c88af1111c6f7163354eb8bd613d97c1b4f Mon Sep 17 00:00:00 2001 From: gustaflundstrom Date: Tue, 27 Dec 2022 10:40:15 +0100 Subject: [PATCH 1/2] Log when adding prefix. --- formatters/source_file.go | 1 + 1 file changed, 1 insertion(+) diff --git a/formatters/source_file.go b/formatters/source_file.go index e95f0562..dd8c94c4 100644 --- a/formatters/source_file.go +++ b/formatters/source_file.go @@ -105,6 +105,7 @@ 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)) { sf.Name = addPrefix + sf.Name } else { From d2f3605329fcab02e69fb3a1227b3fd0807833a3 Mon Sep 17 00:00:00 2001 From: gustaflundstrom Date: Tue, 27 Dec 2022 11:08:12 +0100 Subject: [PATCH 2/2] Add prefix before loading file. --- formatters/source_file.go | 22 +++++++++++----------- formatters/source_file_test.go | 13 ++++++------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/formatters/source_file.go b/formatters/source_file.go index dd8c94c4..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,17 +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 != "" { - logrus.Printf("adding prefix %s", 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") }) }