Skip to content

Commit

Permalink
Merge pull request #40 from symflower/test-evaluate-pacakge
Browse files Browse the repository at this point in the history
Test "evaluate" package
  • Loading branch information
bauersimon authored Apr 18, 2024
2 parents ebce489 + 644f67e commit e194515
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/eval-dev-quality/cmd/evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type Evaluate struct {
}

func (command *Evaluate) Execute(args []string) (err error) {
command.ResultPath = strings.ReplaceAll(command.ResultPath, "%datetime%", time.Now().Format(time.DateTime))
command.ResultPath = strings.ReplaceAll(command.ResultPath, "%datetime%", time.Now().Format("2006-01-02-15:04:05")) // REMARK Use a datetime format with a dash, so directories can be easily marked because they are only one group.

log, logClose, err := log.FileAndSTDOUT(filepath.Join(command.ResultPath, "evaluation.log"))
if err != nil {
Expand Down
69 changes: 69 additions & 0 deletions evaluate/repository_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package evaluate

import (
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/zimmski/osutil"

"github.com/symflower/eval-dev-quality/evaluate/metrics"
"github.com/symflower/eval-dev-quality/language"
"github.com/symflower/eval-dev-quality/model"
"github.com/symflower/eval-dev-quality/model/symflower"
)

func TestEvaluateRepository(t *testing.T) {
type testCase struct {
Name string

Model model.Model
Language language.Language
TestDataPath string
RepositoryPath string

ExpectedRepositoryAssessment metrics.Assessments
ExpectedResultFiles []string
ExpectedProblems []error
ExpectedError error
}

validate := func(t *testing.T, tc *testCase) {
t.Run(tc.Name, func(t *testing.T) {
temporaryPath := t.TempDir()

actualRepositoryAssessment, actualProblems, actualErr := EvaluateRepository(temporaryPath, tc.Model, tc.Language, tc.TestDataPath, tc.RepositoryPath)

assert.Equal(t, tc.ExpectedRepositoryAssessment, actualRepositoryAssessment)
assert.Equal(t, tc.ExpectedProblems, actualProblems)
assert.Equal(t, tc.ExpectedError, actualErr)

actualResultFiles, err := osutil.FilesRecursive(temporaryPath)
require.NoError(t, err)
for i, p := range actualResultFiles {
actualResultFiles[i], err = filepath.Rel(temporaryPath, p)
require.NoError(t, err)
}
assert.Equal(t, tc.ExpectedResultFiles, actualResultFiles)
})
}

validate(t, &testCase{
Name: "Plain",

Model: &symflower.ModelSymflower{},
Language: &language.LanguageGolang{},
TestDataPath: "../testdata",
RepositoryPath: "golang/plain",

ExpectedRepositoryAssessment: metrics.Assessments{
metrics.AssessmentKeyCoverageStatement: 1,
metrics.AssessmentKeyFilesExecuted: 1,
metrics.AssessmentKeyNoExcessResponse: 1,
},
ExpectedResultFiles: []string{
"symflower_symbolic-execution/golang/golang/plain.log",
},
})
}

0 comments on commit e194515

Please sign in to comment.