Skip to content

Commit

Permalink
Ability to select repositories in CLI so one can only run certain tes…
Browse files Browse the repository at this point in the history
…t candidates
  • Loading branch information
bauersimon committed Apr 3, 2024
1 parent 1e9fdf4 commit 7672bf8
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion cmd/eval-symflower-codegen-testing/cmd/evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"log"
"os"
"path/filepath"
"sort"
"strings"
Expand All @@ -20,6 +21,8 @@ type Evaluate struct {
Languages []string `long:"language" description:"Evaluate with this language. By default all languages are used."`
// Models determines which models should be used for the evaluation, or empty if all models should be used.
Models []string `long:"model" description:"Evaluate with this model. By default all models are used."`
// Repositories determines which repository should be used for the evaluation, or empty if all repositories should be used.
Repositories []string `long:"repository" description:"Evaluate with this repository. By default all repositories are used."`
// TestdataPath determines the testdata path where all repositories reside grouped by languages.
TestdataPath string `long:"testdata" description:"Path to the testdata directory where all repositories reside grouped by languages." default:"testdata/"`
}
Expand All @@ -40,6 +43,11 @@ func (command *Evaluate) Execute(args []string) (err error) {
}
sort.Strings(command.Languages)

commandRepositories := map[string]bool{}
for _, r := range command.Repositories {
commandRepositories[r] = true
}

// Gather models.
if len(command.Models) == 0 {
command.Models = maps.Keys(model.Models)
Expand Down Expand Up @@ -70,11 +78,36 @@ func (command *Evaluate) Execute(args []string) (err error) {
model := model.Models[modelID]
language := language.Languages[languageID]

if err := evaluate.EvaluateRepository(model, language, filepath.Join(command.TestdataPath, language.ID(), "plain")); err != nil {
if err := evaluate.EvaluateRepository(model, language, filepath.Join(command.TestdataPath, languageID, "plain")); err != nil {
log.Fatalf("%+v", err)
}
}
}

// Evaluating models and languages.
log.Printf("Evaluating models and languages")
for _, languageID := range command.Languages {
for _, modelID := range command.Models {
model := model.Models[modelID]
language := language.Languages[languageID]
languagePath := filepath.Join(command.TestdataPath, language.ID())

repositories, err := os.ReadDir(languagePath)
if err != nil {
log.Fatalf("ERROR: language path %q cannot be accessed: %s", languagePath, err)
}
for _, repository := range repositories {
if !repository.IsDir() || (len(commandRepositories) > 0 && !commandRepositories[repository.Name()]) {
continue
}

if err := evaluate.EvaluateRepository(model, language, filepath.Join(languagePath, repository.Name())); err != nil {
log.Printf("%+v", err)
}
}

}
}

return nil
}

0 comments on commit 7672bf8

Please sign in to comment.