Skip to content

Commit

Permalink
Log the coverage objects, so this information is available and not lost
Browse files Browse the repository at this point in the history
Part of #204
  • Loading branch information
ruiAzevedo19 committed Jun 27, 2024
1 parent 10fc840 commit d74a936
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
8 changes: 6 additions & 2 deletions cmd/eval-dev-quality/cmd/evaluate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,12 @@ func TestEvaluateExecute(t *testing.T) {
filepath.Join("result-directory", "README.md"): func(t *testing.T, filePath, data string) {
validateReportLinks(t, data, []string{"symflower_symbolic-execution"})
},
filepath.Join("result-directory", string(evaluatetask.IdentifierWriteTests), "symflower_symbolic-execution", "golang", "golang", "plain.log"): nil,
filepath.Join("result-directory", string(evaluatetask.IdentifierWriteTests), "symflower_symbolic-execution", "java", "java", "plain.log"): nil,
filepath.Join("result-directory", string(evaluatetask.IdentifierWriteTests), "symflower_symbolic-execution", "golang", "golang", "plain.log"): func(t *testing.T, filePath, data string) {
assert.Contains(t, data, "coverage objects: [{")
},
filepath.Join("result-directory", string(evaluatetask.IdentifierWriteTests), "symflower_symbolic-execution", "java", "java", "plain.log"): func(t *testing.T, filePath, data string) {
assert.Contains(t, data, "coverage objects: [{")
},
},
})
})
Expand Down
7 changes: 6 additions & 1 deletion language/coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"regexp"

pkgerrors "github.com/pkg/errors"
"github.com/symflower/eval-dev-quality/log"
)

// CoverageBlockUnfolded is an unfolded representation of a coverage data block.
Expand All @@ -23,11 +24,15 @@ type CoverageBlockUnfolded struct {
var FileRangeMatch = regexp.MustCompile(`^(.+):(\d+):(\d+)-(.+):(\d+):(\d+)$`)

// CoverageObjectCountOfFile parses the given coverage file and returns its coverage object count.
func CoverageObjectCountOfFile(coverageFilePath string) (coverageObjectCount uint64, err error) {
func CoverageObjectCountOfFile(logger *log.Logger, coverageFilePath string) (coverageObjectCount uint64, err error) {
coverageFile, err := os.ReadFile(coverageFilePath)
if err != nil {
return 0, pkgerrors.WithMessage(pkgerrors.WithStack(err), coverageFilePath)
}

// Log coverage objects.
logger.Printf("coverage objects: %s", string(coverageFile))

var coverageData []CoverageBlockUnfolded
if err := json.Unmarshal(coverageFile, &coverageData); err != nil {
return 0, pkgerrors.WithMessage(pkgerrors.WithStack(err), string(coverageFile))
Expand Down
2 changes: 1 addition & 1 deletion language/golang/language.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (l *Language) Execute(logger *log.Logger, repositoryPath string) (coverage
}
}

coverage, err = language.CoverageObjectCountOfFile(coverageFilePath)
coverage, err = language.CoverageObjectCountOfFile(logger, coverageFilePath)
if err != nil {
return 0, problems, pkgerrors.WithMessage(pkgerrors.WithStack(err), commandOutput)
}
Expand Down
2 changes: 1 addition & 1 deletion language/java/language.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (l *Language) Execute(logger *log.Logger, repositoryPath string) (coverage
return 0, nil, pkgerrors.WithMessage(pkgerrors.WithStack(err), commandOutput)
}

coverage, err = language.CoverageObjectCountOfFile(coverageFilePath)
coverage, err = language.CoverageObjectCountOfFile(logger, coverageFilePath)
if err != nil {
return 0, nil, pkgerrors.WithMessage(pkgerrors.WithStack(err), commandOutput)
}
Expand Down

0 comments on commit d74a936

Please sign in to comment.