From d078f6dc10eb265a5d88cd96adf86173d6d3ba2e Mon Sep 17 00:00:00 2001 From: Flu0r1ne Date: Thu, 2 Sep 2021 03:14:47 -0500 Subject: Make adapters and internals complient with new directory structure --- cmd/planr/sub/build.go | 12 ++++++++---- cmd/planr/sub/evaluate.go | 4 +--- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'cmd/planr/sub') diff --git a/cmd/planr/sub/build.go b/cmd/planr/sub/build.go index 58c3a38..a8b19ec 100644 --- a/cmd/planr/sub/build.go +++ b/cmd/planr/sub/build.go @@ -3,17 +3,21 @@ package sub import ( "golang.flu0r1ne.net/planr" "golang.flu0r1ne.net/planr/adapters/gtest" + "os" ) func Runner() planr.Runner { r := planr.Runner {} + r.RegisterAdapter(>est.GtestAdapter{}) + + if wd, err := os.Getwd(); err != nil { + r.SetConfigDirFromTree(wd) + } + return r } func Build(params []string) { - - rd := planr.RubricDir() - - Runner().Build(rd) + Runner().Build() } diff --git a/cmd/planr/sub/evaluate.go b/cmd/planr/sub/evaluate.go index 8ce4d81..d183b86 100644 --- a/cmd/planr/sub/evaluate.go +++ b/cmd/planr/sub/evaluate.go @@ -5,9 +5,7 @@ import ( ) func Evaluate(params []string) { - rd := planr.RubricDir() - - tcs := Runner().Evaluate(rd) + tcs := Runner().Evaluate() earned := 0.0 total := 0.0 -- cgit v1.2.3 From 287d029975b7718109f81b480079f375f7d8700a Mon Sep 17 00:00:00 2001 From: Flu0r1ne Date: Fri, 3 Sep 2021 00:02:31 -0500 Subject: Add clean option and fix issue with dir propegation --- cmd/planr/sub/build.go | 2 +- cmd/planr/sub/clean.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 cmd/planr/sub/clean.go (limited to 'cmd/planr/sub') diff --git a/cmd/planr/sub/build.go b/cmd/planr/sub/build.go index a8b19ec..142ef1c 100644 --- a/cmd/planr/sub/build.go +++ b/cmd/planr/sub/build.go @@ -11,7 +11,7 @@ func Runner() planr.Runner { r.RegisterAdapter(>est.GtestAdapter{}) - if wd, err := os.Getwd(); err != nil { + if wd, err := os.Getwd(); err == nil { r.SetConfigDirFromTree(wd) } diff --git a/cmd/planr/sub/clean.go b/cmd/planr/sub/clean.go new file mode 100644 index 0000000..d40e967 --- /dev/null +++ b/cmd/planr/sub/clean.go @@ -0,0 +1,5 @@ +package sub + +func Clean(params []string) { + Runner().Clean() +} -- cgit v1.2.3 From 38912d85394604fe9cc238ef6eb9f6e75ceb38f9 Mon Sep 17 00:00:00 2001 From: Flu0r1ne Date: Fri, 3 Sep 2021 18:13:49 -0500 Subject: Add config command to retrieve configuration values and clean command to clean build files --- cmd/planr/sub/build.go | 17 ++--------------- cmd/planr/sub/clean.go | 6 ++++-- cmd/planr/sub/config.go | 28 ++++++++++++++++++++++++++++ cmd/planr/sub/evaluate.go | 4 ++-- 4 files changed, 36 insertions(+), 19 deletions(-) create mode 100644 cmd/planr/sub/config.go (limited to 'cmd/planr/sub') diff --git a/cmd/planr/sub/build.go b/cmd/planr/sub/build.go index 142ef1c..4a1cda9 100644 --- a/cmd/planr/sub/build.go +++ b/cmd/planr/sub/build.go @@ -2,22 +2,9 @@ package sub import ( "golang.flu0r1ne.net/planr" - "golang.flu0r1ne.net/planr/adapters/gtest" - "os" ) -func Runner() planr.Runner { - r := planr.Runner {} - r.RegisterAdapter(>est.GtestAdapter{}) - - if wd, err := os.Getwd(); err == nil { - r.SetConfigDirFromTree(wd) - } - - return r -} - -func Build(params []string) { - Runner().Build() +func Build(runner planr.Runner, params []string) { + runner.Build() } diff --git a/cmd/planr/sub/clean.go b/cmd/planr/sub/clean.go index d40e967..d658c10 100644 --- a/cmd/planr/sub/clean.go +++ b/cmd/planr/sub/clean.go @@ -1,5 +1,7 @@ package sub -func Clean(params []string) { - Runner().Clean() +import "golang.flu0r1ne.net/planr" + +func Clean(runner planr.Runner, params []string) { + runner.Clean() } diff --git a/cmd/planr/sub/config.go b/cmd/planr/sub/config.go new file mode 100644 index 0000000..ee372c8 --- /dev/null +++ b/cmd/planr/sub/config.go @@ -0,0 +1,28 @@ +package sub + +import ( + "golang.flu0r1ne.net/planr" + "fmt" + "os" +) + + +func Config(runner planr.Runner, params []string) { + if len(params) != 1 { + fmt.Fprintf(os.Stderr, "Usage: planr config \n") + os.Exit(1) + } + + key := params[0] + + switch key { + case "builddir": + fmt.Printf("%s\n", runner.BuildDir()) + case "configdir": + fmt.Printf("%s\n", runner.ConfigDir()) + case "srcdir": + fmt.Printf("%s\n", runner.SrcDir()) + default: + fmt.Fprintf(os.Stderr, "\"%s\" not found in configuration\n", key) + } +} diff --git a/cmd/planr/sub/evaluate.go b/cmd/planr/sub/evaluate.go index d183b86..79d377e 100644 --- a/cmd/planr/sub/evaluate.go +++ b/cmd/planr/sub/evaluate.go @@ -4,8 +4,8 @@ import ( "golang.flu0r1ne.net/planr" ) -func Evaluate(params []string) { - tcs := Runner().Evaluate() +func Evaluate(runner planr.Runner, params []string) { + tcs := runner.Evaluate() earned := 0.0 total := 0.0 -- cgit v1.2.3 From 8c803d453201c8b85172d984fc1aee9eb5af2173 Mon Sep 17 00:00:00 2001 From: Flu0r1ne Date: Fri, 3 Sep 2021 21:45:03 -0500 Subject: Forgo scoring zero point assignment --- cmd/planr/sub/cli.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'cmd/planr/sub') diff --git a/cmd/planr/sub/cli.go b/cmd/planr/sub/cli.go index 0e6a942..d667b88 100644 --- a/cmd/planr/sub/cli.go +++ b/cmd/planr/sub/cli.go @@ -116,7 +116,9 @@ func printResults(passed, tc_total int, earned, points_total float64) { percent := earned / points_total * 100 - pprintLabeled("score", fmt.Sprintf( - "%.2f/%.2f ~= %.1f%%", earned, points_total, percent, - )); + if points_total != 0 { + pprintLabeled("score", fmt.Sprintf( + "%.2f/%.2f ~= %.1f%%", earned, points_total, percent, + )); + } } -- cgit v1.2.3 From cc7ba659adbc5ad55e1ce67f76952f2b8392c9c9 Mon Sep 17 00:00:00 2001 From: Flu0r1ne Date: Sat, 4 Sep 2021 15:38:30 -0500 Subject: Refactor build/eval pipeline to use clearer IO model and adapter segmentation methods --- cmd/planr/sub/build.go | 3 ++- cmd/planr/sub/evaluate.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'cmd/planr/sub') diff --git a/cmd/planr/sub/build.go b/cmd/planr/sub/build.go index 4a1cda9..d24bb02 100644 --- a/cmd/planr/sub/build.go +++ b/cmd/planr/sub/build.go @@ -6,5 +6,6 @@ import ( func Build(runner planr.Runner, params []string) { - runner.Build() + tcs := runner.CollectCases() + runner.Build(tcs) } diff --git a/cmd/planr/sub/evaluate.go b/cmd/planr/sub/evaluate.go index 79d377e..0366d44 100644 --- a/cmd/planr/sub/evaluate.go +++ b/cmd/planr/sub/evaluate.go @@ -5,7 +5,8 @@ import ( ) func Evaluate(runner planr.Runner, params []string) { - tcs := runner.Evaluate() + tcs := runner.CollectCases() + tcs = runner.Evaluate(tcs) earned := 0.0 total := 0.0 -- cgit v1.2.3 From 151d516e68f5d43aa2d0c5ff462752d640b6a614 Mon Sep 17 00:00:00 2001 From: Flu0r1ne Date: Sun, 5 Sep 2021 00:37:23 -0500 Subject: Refactor gtest adapter to fit new pipeline --- cmd/planr/sub/cli.go | 46 ++++++++++++++++++++++------------------------ cmd/planr/sub/evaluate.go | 10 +++++----- 2 files changed, 27 insertions(+), 29 deletions(-) (limited to 'cmd/planr/sub') diff --git a/cmd/planr/sub/cli.go b/cmd/planr/sub/cli.go index d667b88..3c58f4e 100644 --- a/cmd/planr/sub/cli.go +++ b/cmd/planr/sub/cli.go @@ -14,25 +14,23 @@ var ( col_label = color.New(color.FgCyan) ); -func tcTitle(tc planr.TestCase) string { - title := tc.Cname +func tcTitle(tr planr.TestResult) string { + title := tr.Tc.Cname - if tc.Config.Title != nil { - title = *tc.Config.Title + if tr.Tc.Config.Title != nil { + title = *tr.Tc.Config.Title } return title } -func tcStatus(tc planr.TestCase) string { +func tcStatus(tc planr.TestResult) string { status := "SILENT" - if tc.Result != nil { - if tc.Result.Status == planr.PASSING { - status = "PASS" - } else { - status = "FAIL" - } + if tc.Status == planr.PASSING { + status = "PASS" + } else { + status = "FAIL" } return status @@ -59,9 +57,9 @@ func pprintFenced(title, value string) { fmt.Println(fence) } -func tcStatusLine(tc planr.TestCase) { - title := tcTitle(tc) - status := tcStatus(tc) +func tcStatusLine(tr planr.TestResult) { + title := tcTitle(tr) + status := tcStatus(tr) if status == "PASS" { col_pass.Printf("[%s] ", status); @@ -72,8 +70,10 @@ func tcStatusLine(tc planr.TestCase) { col_title.Println(title); } -func tcPprint(tc planr.TestCase) { - tcStatusLine(tc) +func tcPprint(tr planr.TestResult) { + tcStatusLine(tr) + + tc := tr.Tc pprintLabeled("id", tc.Cname) @@ -86,22 +86,20 @@ func tcPprint(tc planr.TestCase) { pprintLabeled("description", *tc.Config.Description) } - res := tc.Result - - if res.Status == planr.COMPILATION_FAILURE { + if tr.Status == planr.COMPILATION_FAILURE { - if res.DebugOutput != "" { + if tr.DebugOutput != "" { fmt.Println() - pprintFenced("compilation output", tc.Result.DebugOutput); + pprintFenced("compilation output", tr.DebugOutput); } else { fmt.Println("WARN: No debug output provided") } - } else if res.Status == planr.RUNTIME_FAILURE { + } else if tr.Status == planr.RUNTIME_FAILURE { - if tc.Result.TestOutput != "" { + if tr.TestOutput != "" { fmt.Println() - pprintFenced("test output", tc.Result.TestOutput); + pprintFenced("test output", tr.TestOutput); } } diff --git a/cmd/planr/sub/evaluate.go b/cmd/planr/sub/evaluate.go index 0366d44..18cccb1 100644 --- a/cmd/planr/sub/evaluate.go +++ b/cmd/planr/sub/evaluate.go @@ -6,26 +6,26 @@ import ( func Evaluate(runner planr.Runner, params []string) { tcs := runner.CollectCases() - tcs = runner.Evaluate(tcs) + trs := runner.Evaluate(tcs) earned := 0.0 total := 0.0 passed := 0 - for _, tc := range tcs { - cfg := tc.Config + for _, tr := range trs { + cfg := tr.Tc.Config if cfg.Points != nil { points := float64(*cfg.Points) total += points - if tc.Result.Status == planr.PASSING { + if tr.Status == planr.PASSING { earned += points passed++ } } - tcPprint(tc) + tcPprint(tr) } printResults( -- cgit v1.2.3 From a6f45bfa932b9e8e2393b5643e2bc38e44ba76df Mon Sep 17 00:00:00 2001 From: Flu0r1ne Date: Sun, 5 Sep 2021 02:41:21 -0500 Subject: Add config w/ version information --- cmd/planr/sub/build.go | 4 ++-- cmd/planr/sub/common.go | 15 +++++++++++++++ cmd/planr/sub/evaluate.go | 4 +++- 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 cmd/planr/sub/common.go (limited to 'cmd/planr/sub') diff --git a/cmd/planr/sub/build.go b/cmd/planr/sub/build.go index d24bb02..48edd9c 100644 --- a/cmd/planr/sub/build.go +++ b/cmd/planr/sub/build.go @@ -4,8 +4,8 @@ import ( "golang.flu0r1ne.net/planr" ) - -func Build(runner planr.Runner, params []string) { +func Build(runner planr.Runner, params []string, cfg planr.Config) { + dieIncompatibleVersion(cfg) tcs := runner.CollectCases() runner.Build(tcs) } diff --git a/cmd/planr/sub/common.go b/cmd/planr/sub/common.go new file mode 100644 index 0000000..67d07f8 --- /dev/null +++ b/cmd/planr/sub/common.go @@ -0,0 +1,15 @@ +package sub + +import ( + "golang.flu0r1ne.net/planr" + "os" + "fmt" +) + +func dieIncompatibleVersion(cfg planr.Config) { + if cfg.IncompatibleWithVersion() { + fmt.Fprintf(os.Stderr, "This version of PlanR (%v) is incompatible with config version %s\n", planr.VERSION, cfg.Version) + fmt.Fprintf(os.Stderr, "Please upgrade to version %s or greater\n", cfg.Version) + os.Exit(1) + } +} diff --git a/cmd/planr/sub/evaluate.go b/cmd/planr/sub/evaluate.go index 18cccb1..c2549be 100644 --- a/cmd/planr/sub/evaluate.go +++ b/cmd/planr/sub/evaluate.go @@ -4,7 +4,9 @@ import ( "golang.flu0r1ne.net/planr" ) -func Evaluate(runner planr.Runner, params []string) { +func Evaluate(runner planr.Runner, params []string, cfg planr.Config) { + dieIncompatibleVersion(cfg) + tcs := runner.CollectCases() trs := runner.Evaluate(tcs) -- cgit v1.2.3 From 54276b73eacfab6a5d6b899bd638f6cfe9499b80 Mon Sep 17 00:00:00 2001 From: Flu0r1ne Date: Sun, 5 Sep 2021 13:39:34 -0500 Subject: Refactor with scoring object --- cmd/planr/sub/cli.go | 10 +++++----- cmd/planr/sub/evaluate.go | 26 ++++---------------------- 2 files changed, 9 insertions(+), 27 deletions(-) (limited to 'cmd/planr/sub') diff --git a/cmd/planr/sub/cli.go b/cmd/planr/sub/cli.go index 3c58f4e..e6f2256 100644 --- a/cmd/planr/sub/cli.go +++ b/cmd/planr/sub/cli.go @@ -107,16 +107,16 @@ func tcPprint(tr planr.TestResult) { fmt.Println() } -func printResults(passed, tc_total int, earned, points_total float64) { +func printScoring(score planr.Scoring) { col_title.Println("Final Results:") - pprintLabeled("passed", fmt.Sprintf("%d/%d", passed, tc_total)); + pprintLabeled("passed", fmt.Sprintf("%d/%d", score.Passed, score.Total)); - percent := earned / points_total * 100 + percent := score.EarnedPoints / score.TotalPoints * 100 - if points_total != 0 { + if score.TotalPoints != 0 { pprintLabeled("score", fmt.Sprintf( - "%.2f/%.2f ~= %.1f%%", earned, points_total, percent, + "%.2f/%.2f ~= %.1f%%", score.EarnedPoints, score.TotalPoints, percent, )); } } diff --git a/cmd/planr/sub/evaluate.go b/cmd/planr/sub/evaluate.go index c2549be..81c9989 100644 --- a/cmd/planr/sub/evaluate.go +++ b/cmd/planr/sub/evaluate.go @@ -4,36 +4,18 @@ import ( "golang.flu0r1ne.net/planr" ) + func Evaluate(runner planr.Runner, params []string, cfg planr.Config) { dieIncompatibleVersion(cfg) tcs := runner.CollectCases() trs := runner.Evaluate(tcs) - earned := 0.0 - total := 0.0 - passed := 0 - for _, tr := range trs { - cfg := tr.Tc.Config - - if cfg.Points != nil { - points := float64(*cfg.Points) - - total += points - - if tr.Status == planr.PASSING { - earned += points - passed++ - } - } + score := planr.Score(trs) + for _, tr := range trs { tcPprint(tr) } - printResults( - passed, - len(tcs), - earned, - total, - ); + printScoring(score) } -- cgit v1.2.3 From 6876ea1e5cc3319b0d23d829a14f83b9a55663d2 Mon Sep 17 00:00:00 2001 From: Flu0r1ne Date: Sun, 5 Sep 2021 13:52:39 -0500 Subject: Add flag for JSON eval output --- cmd/planr/sub/evaluate.go | 52 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 8 deletions(-) (limited to 'cmd/planr/sub') diff --git a/cmd/planr/sub/evaluate.go b/cmd/planr/sub/evaluate.go index 81c9989..95f88d0 100644 --- a/cmd/planr/sub/evaluate.go +++ b/cmd/planr/sub/evaluate.go @@ -1,21 +1,57 @@ package sub import ( - "golang.flu0r1ne.net/planr" + "encoding/json" + "fmt" + "log" + "flag" + + "golang.flu0r1ne.net/planr" ) +type gradingResults struct { + TestResults []planr.TestResult + Score planr.Scoring +} + +func prettyPrint(results gradingResults) { + for _, tr := range results.TestResults { + tcPprint(tr) + } + + 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") + + f.Parse(params) + dieIncompatibleVersion(cfg) tcs := runner.CollectCases() trs := runner.Evaluate(tcs) - - score := planr.Score(trs) - - for _, tr := range trs { - tcPprint(tr) + + results := gradingResults { + TestResults: trs, + Score: planr.Score(trs), + } + + if *jsonOutput { + jsonPrint(results) + } else { + prettyPrint(results) } - - printScoring(score) } -- cgit v1.2.3 From b9b8d706efd0d9c1848d50e7f8afa1a74ce90037 Mon Sep 17 00:00:00 2001 From: Flu0r1ne Date: Sun, 5 Sep 2021 14:18:31 -0500 Subject: Add mechanism to conditionally run some tests - FS approch should be taken upon revision --- cmd/planr/sub/evaluate.go | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'cmd/planr/sub') diff --git a/cmd/planr/sub/evaluate.go b/cmd/planr/sub/evaluate.go index 95f88d0..21481a1 100644 --- a/cmd/planr/sub/evaluate.go +++ b/cmd/planr/sub/evaluate.go @@ -14,12 +14,14 @@ type gradingResults struct { Score planr.Scoring } -func prettyPrint(results gradingResults) { +func prettyPrint(results gradingResults, summarize bool) { for _, tr := range results.TestResults { tcPprint(tr) } - printScoring(results.Score) + if summarize { + printScoring(results.Score) + } } func jsonPrint(results gradingResults) { @@ -37,12 +39,34 @@ func Evaluate(runner planr.Runner, params []string, cfg planr.Config) { jsonOutput := f.Bool("json", false, "print json output") - f.Parse(params) - dieIncompatibleVersion(cfg) + f.Parse(params) + tcs := runner.CollectCases() - trs := runner.Evaluate(tcs) + + // 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, @@ -52,6 +76,6 @@ func Evaluate(runner planr.Runner, params []string, cfg planr.Config) { if *jsonOutput { jsonPrint(results) } else { - prettyPrint(results) + prettyPrint(results, summarizeScore) } } -- cgit v1.2.3 From 91666d1f2e766bc7c3073ed4cd731637c6885e36 Mon Sep 17 00:00:00 2001 From: Flu0r1ne Date: Sun, 5 Sep 2021 18:57:59 -0500 Subject: Do not throw fatal error when missing config, this behavior will be enabled in future releases --- cmd/planr/sub/build.go | 2 +- cmd/planr/sub/common.go | 4 ++-- cmd/planr/sub/evaluate.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'cmd/planr/sub') diff --git a/cmd/planr/sub/build.go b/cmd/planr/sub/build.go index 48edd9c..e93e0cb 100644 --- a/cmd/planr/sub/build.go +++ b/cmd/planr/sub/build.go @@ -4,7 +4,7 @@ import ( "golang.flu0r1ne.net/planr" ) -func Build(runner planr.Runner, params []string, cfg planr.Config) { +func Build(runner planr.Runner, params []string, cfg * planr.Config) { dieIncompatibleVersion(cfg) tcs := runner.CollectCases() runner.Build(tcs) diff --git a/cmd/planr/sub/common.go b/cmd/planr/sub/common.go index 67d07f8..9126f3c 100644 --- a/cmd/planr/sub/common.go +++ b/cmd/planr/sub/common.go @@ -6,8 +6,8 @@ import ( "fmt" ) -func dieIncompatibleVersion(cfg planr.Config) { - if cfg.IncompatibleWithVersion() { +func dieIncompatibleVersion(cfg *planr.Config) { + if cfg != nil && cfg.IncompatibleWithVersion() { fmt.Fprintf(os.Stderr, "This version of PlanR (%v) is incompatible with config version %s\n", planr.VERSION, cfg.Version) fmt.Fprintf(os.Stderr, "Please upgrade to version %s or greater\n", cfg.Version) os.Exit(1) diff --git a/cmd/planr/sub/evaluate.go b/cmd/planr/sub/evaluate.go index 21481a1..30d30d2 100644 --- a/cmd/planr/sub/evaluate.go +++ b/cmd/planr/sub/evaluate.go @@ -34,7 +34,7 @@ func jsonPrint(results gradingResults) { fmt.Println(string(res)) } -func Evaluate(runner planr.Runner, params []string, cfg planr.Config) { +func Evaluate(runner planr.Runner, params []string, cfg *planr.Config) { f := flag.NewFlagSet("evaluate", flag.ExitOnError) jsonOutput := f.Bool("json", false, "print json output") -- cgit v1.2.3