diff options
-rw-r--r-- | cmd/planr/sub/cli.go | 28 | ||||
-rw-r--r-- | cmd/planr/sub/evaluate.go | 13 | ||||
-rw-r--r-- | rubric_config.go | 15 | ||||
-rw-r--r-- | runner.go | 2 | ||||
-rw-r--r-- | testcase.go | 7 |
5 files changed, 45 insertions, 20 deletions
diff --git a/cmd/planr/sub/cli.go b/cmd/planr/sub/cli.go index e6f2256..4d29144 100644 --- a/cmd/planr/sub/cli.go +++ b/cmd/planr/sub/cli.go @@ -17,8 +17,8 @@ var ( func tcTitle(tr planr.TestResult) string { title := tr.Tc.Cname - if tr.Tc.Config.Title != nil { - title = *tr.Tc.Config.Title + if tr.Tc.Config.Title != "" { + title = tr.Tc.Config.Title } return title @@ -70,20 +70,34 @@ func tcStatusLine(tr planr.TestResult) { col_title.Println(title); } -func tcPprint(tr planr.TestResult) { +type PrintOpts int + +const ( + PRINT_CONCISE PrintOpts = 1 << iota + PRINT_DESCRIPTION + PRINT_POINTS +) + +func (opt PrintOpts) HasFlag(flag PrintOpts) bool { + return (opt & flag) == flag +} + +func tcPprint(tr planr.TestResult, opt PrintOpts) { tcStatusLine(tr) tc := tr.Tc pprintLabeled("id", tc.Cname) - if tc.Config.Points != nil { + if tc.Config.Points != nil && opt.HasFlag(PRINT_POINTS) { points := fmt.Sprintf("%.1f", *tc.Config.Points) - pprintLabeled("points", points) + pprintLabeled("points1", points) } - if tc.Config.Description != nil { - pprintLabeled("description", *tc.Config.Description) + if tc.Config.Description != "" && opt.HasFlag(PRINT_DESCRIPTION) { + tabbed := strings.ReplaceAll(tc.Config.Description, "\n", "\n ") + + pprintLabeled("description", tabbed) } if tr.Status == planr.COMPILATION_FAILURE { diff --git a/cmd/planr/sub/evaluate.go b/cmd/planr/sub/evaluate.go index 30d30d2..4f5e4e1 100644 --- a/cmd/planr/sub/evaluate.go +++ b/cmd/planr/sub/evaluate.go @@ -14,9 +14,15 @@ type gradingResults struct { Score planr.Scoring } -func prettyPrint(results gradingResults, summarize bool) { +func prettyPrint(results gradingResults, verbose, summarize bool) { for _, tr := range results.TestResults { - tcPprint(tr) + opts := PRINT_CONCISE + + if verbose { + opts = opts | PRINT_DESCRIPTION | PRINT_POINTS + } + + tcPprint(tr, opts) } if summarize { @@ -38,6 +44,7 @@ func Evaluate(runner planr.Runner, params []string, cfg *planr.Config) { f := flag.NewFlagSet("evaluate", flag.ExitOnError) jsonOutput := f.Bool("json", false, "print json output") + extra := f.Bool("extra", false, "print extra grading information") dieIncompatibleVersion(cfg) @@ -76,6 +83,6 @@ func Evaluate(runner planr.Runner, params []string, cfg *planr.Config) { if *jsonOutput { jsonPrint(results) } else { - prettyPrint(results, summarizeScore) + prettyPrint(results, *extra, summarizeScore) } } diff --git a/rubric_config.go b/rubric_config.go index d533a7b..00cd76c 100644 --- a/rubric_config.go +++ b/rubric_config.go @@ -39,8 +39,9 @@ type InheritableConfig interface { // Program-wide configuration which is recognized // in defaults.toml type Defaults struct { + Description string Points *float32 - Adapter *string + Adapter string /* The TOML library only parses exported fields. @@ -73,18 +74,22 @@ func (child *Defaults) Inherit(p interface{}) { // Inherit properties which haven't been configured if child.Points == nil { - child.Points = parent.Points; + child.Points = parent.Points } - if child.Adapter == nil { - child.Adapter = parent.Adapter; + if child.Adapter == "" { + child.Adapter = parent.Adapter } + if child.Description == "" { + child.Description = parent.Description + } + // Call the inherit method as defined by the adapters // If an adapter is undefined, inherit the parent configuration // // _configs represents all adapters (registered to a runner) - for _, adapter := range *child.configs_ { + for _, adapter := range *parent.configs_ { parent_adapter, parent_exists := parent.adapters_[adapter.Name] child_adapter, child_exists := child.adapters_[adapter.Name] @@ -56,7 +56,7 @@ func (r Runner) groupByAdapter(tcs []TestCase) []adapterTestSet { for _, tc := range tcs { // TODO: Make non-pointer - adptNm := *tc.Config.Adapter + adptNm := tc.Config.Adapter // See if adapter if contained in map adapter, contained := r.adapters[adptNm] diff --git a/testcase.go b/testcase.go index d1db292..4273c88 100644 --- a/testcase.go +++ b/testcase.go @@ -24,12 +24,11 @@ type TestResult struct { // Program-wide testcase config type TestCaseConfig struct { Defaults - Title *string - Description *string + Title string } func (c TestCaseConfig) ensureSatisfied(name string) { - if (c.Adapter == nil) { + if (c.Adapter == "") { log.Fatalf("Adapter must be provided for testcase %s", name) } } @@ -51,7 +50,7 @@ type TestCase struct { } func (tc TestCase) AdapterConfig() InheritableConfig { - return tc.Config.adapters_[*tc.Config.Adapter] + return tc.Config.adapters_[tc.Config.Adapter] } type ByReadIdx []TestResult |