package sub import ( "encoding/json" "fmt" "log" "flag" "golang.flu0r1ne.net/planr" ) type gradingResults struct { TestResults []planr.TestResult Score planr.Scoring } func prettyPrint(results gradingResults, summarize bool) { for _, tr := range results.TestResults { tcPprint(tr) } if summarize { printScoring(results.Score) } } func jsonPrint(results gradingResults) { res, err := json.Marshal(results) if err != nil { log.Fatalf("Error printing JSON: %v\n", err) } fmt.Println(string(res)) } func Evaluate(runner planr.Runner, params []string, cfg *planr.Config) { f := flag.NewFlagSet("evaluate", flag.ExitOnError) jsonOutput := f.Bool("json", false, "print json output") dieIncompatibleVersion(cfg) f.Parse(params) tcs := runner.CollectCases() // Filter those tests which patch IDs in params filteredTcs := make([]planr.TestCase, 0) summarizeScore := false if f.NArg() > 0 { ids := f.Args() membershipFun := make(map[string] bool, 0) for _, id := range ids { membershipFun[id] = true } for i := range tcs { if membershipFun[tcs[i].Cname] { filteredTcs = append(filteredTcs, tcs[i]) } } } else { summarizeScore = true filteredTcs = tcs } trs := runner.Evaluate(filteredTcs) results := gradingResults { TestResults: trs, Score: planr.Score(trs), } if *jsonOutput { jsonPrint(results) } else { prettyPrint(results, summarizeScore) } }