Skip to content

Commit

Permalink
Merge pull request #388 from k1LoW/wildcard-paths
Browse files Browse the repository at this point in the history
Support wildcard paths in `coverage.paths:`
  • Loading branch information
k1LoW authored Jul 2, 2024
2 parents e727b8c + 84e2b36 commit 04f371b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 18 deletions.
16 changes: 12 additions & 4 deletions report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"strings"
"time"

"github.com/bmatcuk/doublestar/v4"
"github.com/goccy/go-json"
"github.com/hashicorp/go-multierror"
"github.com/k1LoW/octocov/config"
Expand Down Expand Up @@ -298,11 +299,18 @@ func (r *Report) Load(path string) error {
return nil
}

func (r *Report) MeasureCoverage(paths, exclude []string) error {
if len(paths) == 0 {
return fmt.Errorf("coverage report not found: %s", paths)
func (r *Report) MeasureCoverage(patterns, exclude []string) error {
if len(patterns) == 0 {
return fmt.Errorf("coverage report not found: %s", patterns)
}
var paths []string
for _, pattern := range patterns {
p, err := doublestar.FilepathGlob(pattern)
if err != nil {
return err
}
paths = append(paths, p...)
}

var cerr *multierror.Error
for _, path := range paths {
cov, rp, err := challengeParseReport(path)
Expand Down
52 changes: 38 additions & 14 deletions report/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@ func TestMeasureCoverage(t *testing.T) {
2,
false,
},
{
[]string{
filepath.Join(coverageTestdataDir(t), "**", "*.out"),
},
1,
false,
},
{
[]string{
filepath.Join(coverageTestdataDir(t), "**", "*.info"),
filepath.Join(coverageTestdataDir(t), "**", "*.out"),
},
2,
false,
},
{
[]string{
filepath.Join(coverageTestdataDir(t), "..", "**", "*.info"),
},
1,
false,
},
{
[]string{
filepath.Join(testdataDir(t), "reports", "k1LoW", "tbls", "report.json"),
Expand All @@ -107,21 +129,23 @@ func TestMeasureCoverage(t *testing.T) {
true,
},
}
for _, tt := range tests {
r := &Report{}
if err := r.MeasureCoverage(tt.paths, nil); err != nil {
if !tt.wantErr {
t.Error(err)
for i, tt := range tests {
t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
r := &Report{}
if err := r.MeasureCoverage(tt.paths, nil); err != nil {
if !tt.wantErr {
t.Error(err)
}
return
}
continue
}
if tt.wantErr {
t.Error("want error")
}
got := len(r.covPaths)
if got != tt.want {
t.Errorf("got %v\nwant %v", got, tt.want)
}
if tt.wantErr {
t.Error("want error")
}
got := len(r.covPaths)
if got != tt.want {
t.Errorf("got %v\nwant %v", got, tt.want)
}
})
}
}

Expand Down

0 comments on commit 04f371b

Please sign in to comment.