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') 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/main.go | 4 ++++ cmd/planr/sub/build.go | 2 +- cmd/planr/sub/clean.go | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 cmd/planr/sub/clean.go (limited to 'cmd/planr') diff --git a/cmd/planr/main.go b/cmd/planr/main.go index e2a85ed..4b69a36 100644 --- a/cmd/planr/main.go +++ b/cmd/planr/main.go @@ -19,6 +19,8 @@ func printUsage(w io.Writer) { fmt.Fprintln(w, " version ") fmt.Fprintln(w, " build ") fmt.Fprintln(w, " evaluate ") + fmt.Fprintln(w, " clean ") + } func dieUsage() { @@ -45,6 +47,8 @@ func main() { sub.Build(subargs) case "evaluate","eval": sub.Evaluate(subargs) + case "clean": + sub.Clean(subargs) case "help", "-h", "-help", "--help": printUsage(os.Stdout) default: 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/main.go | 51 ++++++++++++++++++++++++++++++++++++++++------- cmd/planr/sub/build.go | 17 ++-------------- cmd/planr/sub/clean.go | 6 ++++-- cmd/planr/sub/config.go | 28 ++++++++++++++++++++++++++ cmd/planr/sub/evaluate.go | 4 ++-- 5 files changed, 80 insertions(+), 26 deletions(-) create mode 100644 cmd/planr/sub/config.go (limited to 'cmd/planr') diff --git a/cmd/planr/main.go b/cmd/planr/main.go index 4b69a36..adcb50e 100644 --- a/cmd/planr/main.go +++ b/cmd/planr/main.go @@ -5,8 +5,11 @@ import ( "io" "log" "os" + "flag" + "golang.flu0r1ne.net/planr" "golang.flu0r1ne.net/planr/cmd/planr/sub" + "golang.flu0r1ne.net/planr/adapters/gtest" ) const ( @@ -20,7 +23,7 @@ func printUsage(w io.Writer) { fmt.Fprintln(w, " build ") fmt.Fprintln(w, " evaluate ") fmt.Fprintln(w, " clean ") - + fmt.Fprintln(w, " config ") } func dieUsage() { @@ -28,6 +31,36 @@ func dieUsage() { os.Exit(1) } +func NewRunner() planr.Runner { + r := planr.Runner {} + + r.RegisterAdapter(>est.GtestAdapter{}) + + if wd, err := os.Getwd(); err == nil { + r.SetConfigDirFromTree(wd) + } + + src := flag.String("srcdir", "", "source directory") + config := flag.String("configdir", "", "config directory") + build := flag.String("builddir", "", "build directory") + + flag.Parse() + + if src != nil && *src != "" { + r.SetSrcDir(*src) + } + + if config != nil && *config != "" { + r.SetConfigDir(*config) + } + + if build != nil && *build != "" { + r.SetBuildDir(*build) + } + + return r +} + func main() { log.SetFlags(log.Llongfile | log.Lmsgprefix) @@ -37,18 +70,22 @@ func main() { dieUsage() } - subcommand := os.Args[1] - subargs := os.Args[2:] + runner := NewRunner() + + subcommand := flag.Arg(0) + subargs := flag.Args()[1:] switch subcommand { case "version": fmt.Printf("%s\n", VERSION) case "build": - sub.Build(subargs) - case "evaluate","eval": - sub.Evaluate(subargs) + sub.Build(runner, subargs) + case "evaluate", "eval": + sub.Evaluate(runner, subargs) case "clean": - sub.Clean(subargs) + sub.Clean(runner, subargs) + case "config": + sub.Config(runner, subargs) case "help", "-h", "-help", "--help": printUsage(os.Stdout) default: 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 7671f58c301ffb22bb49a1de6f87b6db6865ff13 Mon Sep 17 00:00:00 2001 From: Flu0r1ne Date: Fri, 3 Sep 2021 20:07:51 -0500 Subject: Use version code in PLANR for the CLI --- cmd/planr/main.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'cmd/planr') diff --git a/cmd/planr/main.go b/cmd/planr/main.go index adcb50e..277ffc8 100644 --- a/cmd/planr/main.go +++ b/cmd/planr/main.go @@ -12,10 +12,6 @@ import ( "golang.flu0r1ne.net/planr/adapters/gtest" ) -const ( - VERSION = "0.0.3" -) - func printUsage(w io.Writer) { fmt.Fprintf (w, "usage: %s command args ... \n", os.Args[0]) fmt.Fprintln(w, " help ") @@ -77,7 +73,7 @@ func main() { switch subcommand { case "version": - fmt.Printf("%s\n", VERSION) + fmt.Printf("%s\n", planr.VERSION) case "build": sub.Build(runner, subargs) case "evaluate", "eval": -- cgit v1.2.3 From 2d197f1ce3eac8cecb5a655fcb5343cbe562ab1a Mon Sep 17 00:00:00 2001 From: Flu0r1ne Date: Fri, 3 Sep 2021 21:14:28 -0500 Subject: Add new test runner API --- cmd/planr/main.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'cmd/planr') diff --git a/cmd/planr/main.go b/cmd/planr/main.go index 277ffc8..b2a0975 100644 --- a/cmd/planr/main.go +++ b/cmd/planr/main.go @@ -27,15 +27,14 @@ func dieUsage() { os.Exit(1) } -func NewRunner() planr.Runner { - r := planr.Runner {} - - r.RegisterAdapter(>est.GtestAdapter{}) +func getConfiguredRunner() planr.Runner { + r := planr.ConfigureRunner() + r = planr.RegisterAdapter(r, gtest.New()) if wd, err := os.Getwd(); err == nil { - r.SetConfigDirFromTree(wd) + r = planr.SetConfigDirFromTree(r, wd) } - + src := flag.String("srcdir", "", "source directory") config := flag.String("configdir", "", "config directory") build := flag.String("builddir", "", "build directory") @@ -43,18 +42,18 @@ func NewRunner() planr.Runner { flag.Parse() if src != nil && *src != "" { - r.SetSrcDir(*src) + r = planr.SetSrcDir(r, *src) } if config != nil && *config != "" { - r.SetConfigDir(*config) + r = planr.SetConfigDir(r, *config) } if build != nil && *build != "" { - r.SetBuildDir(*build) + r = planr.SetBuildDir(r, *build) } - return r + return r.New() } func main() { @@ -66,7 +65,7 @@ func main() { dieUsage() } - runner := NewRunner() + runner := getConfiguredRunner() subcommand := flag.Arg(0) subargs := flag.Args()[1:] -- 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') 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/main.go | 2 +- cmd/planr/sub/build.go | 3 ++- cmd/planr/sub/evaluate.go | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'cmd/planr') diff --git a/cmd/planr/main.go b/cmd/planr/main.go index b2a0975..4ff57eb 100644 --- a/cmd/planr/main.go +++ b/cmd/planr/main.go @@ -29,7 +29,7 @@ func dieUsage() { func getConfiguredRunner() planr.Runner { r := planr.ConfigureRunner() - r = planr.RegisterAdapter(r, gtest.New()) + r = planr.RegisterAdapter(r, gtest.NewAdapter()) if wd, err := os.Getwd(); err == nil { r = planr.SetConfigDirFromTree(r, wd) 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') 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 4a6efc74aebcc689a734d05bc8435eb9560340e1 Mon Sep 17 00:00:00 2001 From: Flu0r1ne Date: Sun, 5 Sep 2021 02:11:09 -0500 Subject: Add CPU profiling flag --- cmd/planr/main.go | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'cmd/planr') diff --git a/cmd/planr/main.go b/cmd/planr/main.go index 4ff57eb..d7f62aa 100644 --- a/cmd/planr/main.go +++ b/cmd/planr/main.go @@ -1,15 +1,16 @@ package main import ( + "flag" "fmt" "io" "log" "os" - "flag" + "runtime/pprof" "golang.flu0r1ne.net/planr" - "golang.flu0r1ne.net/planr/cmd/planr/sub" "golang.flu0r1ne.net/planr/adapters/gtest" + "golang.flu0r1ne.net/planr/cmd/planr/sub" ) func printUsage(w io.Writer) { @@ -27,6 +28,11 @@ func dieUsage() { os.Exit(1) } +var src = flag.String("srcdir", "", "source directory") +var config = flag.String("configdir", "", "config directory") +var build = flag.String("builddir", "", "build directory") +var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") + func getConfiguredRunner() planr.Runner { r := planr.ConfigureRunner() r = planr.RegisterAdapter(r, gtest.NewAdapter()) @@ -35,21 +41,15 @@ func getConfiguredRunner() planr.Runner { r = planr.SetConfigDirFromTree(r, wd) } - src := flag.String("srcdir", "", "source directory") - config := flag.String("configdir", "", "config directory") - build := flag.String("builddir", "", "build directory") - - flag.Parse() - - if src != nil && *src != "" { + if *src != "" { r = planr.SetSrcDir(r, *src) } - if config != nil && *config != "" { + if *config != "" { r = planr.SetConfigDir(r, *config) } - if build != nil && *build != "" { + if *build != "" { r = planr.SetBuildDir(r, *build) } @@ -57,6 +57,18 @@ func getConfiguredRunner() planr.Runner { } func main() { + flag.Parse() + + if *cpuprofile != "" { + f, err := os.Create(*cpuprofile) + + if err != nil { + log.Fatal(err) + } + + pprof.StartCPUProfile(f) + defer pprof.StopCPUProfile() + } log.SetFlags(log.Llongfile | log.Lmsgprefix) log.SetPrefix("planr: ") -- 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/main.go | 6 ++++-- cmd/planr/sub/build.go | 4 ++-- cmd/planr/sub/common.go | 15 +++++++++++++++ cmd/planr/sub/evaluate.go | 4 +++- 4 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 cmd/planr/sub/common.go (limited to 'cmd/planr') diff --git a/cmd/planr/main.go b/cmd/planr/main.go index d7f62aa..ce20811 100644 --- a/cmd/planr/main.go +++ b/cmd/planr/main.go @@ -79,6 +79,8 @@ func main() { runner := getConfiguredRunner() + cfg := planr.DecodeConfig(runner.ConfigDir()) + subcommand := flag.Arg(0) subargs := flag.Args()[1:] @@ -86,9 +88,9 @@ func main() { case "version": fmt.Printf("%s\n", planr.VERSION) case "build": - sub.Build(runner, subargs) + sub.Build(runner, subargs, cfg) case "evaluate", "eval": - sub.Evaluate(runner, subargs) + sub.Evaluate(runner, subargs, cfg) case "clean": sub.Clean(runner, subargs) case "config": 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 62e85f40923b3485ba60766052de7150acf039c5 Mon Sep 17 00:00:00 2001 From: Flu0r1ne Date: Sun, 5 Sep 2021 04:30:33 -0500 Subject: Add bash adapter --- cmd/planr/main.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'cmd/planr') diff --git a/cmd/planr/main.go b/cmd/planr/main.go index ce20811..d250bbd 100644 --- a/cmd/planr/main.go +++ b/cmd/planr/main.go @@ -1,7 +1,6 @@ package main -import ( - "flag" +import ( "flag" "fmt" "io" "log" @@ -10,6 +9,7 @@ import ( "golang.flu0r1ne.net/planr" "golang.flu0r1ne.net/planr/adapters/gtest" + "golang.flu0r1ne.net/planr/adapters/bash" "golang.flu0r1ne.net/planr/cmd/planr/sub" ) @@ -28,14 +28,15 @@ func dieUsage() { os.Exit(1) } -var src = flag.String("srcdir", "", "source directory") -var config = flag.String("configdir", "", "config directory") -var build = flag.String("builddir", "", "build directory") +var src = flag.String("srcdir", "", "source directory") +var config = flag.String("configdir", "", "config directory") +var build = flag.String("builddir", "", "build directory") var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") func getConfiguredRunner() planr.Runner { r := planr.ConfigureRunner() r = planr.RegisterAdapter(r, gtest.NewAdapter()) + r = planr.RegisterAdapter(r, bash.NewAdapter()) if wd, err := os.Getwd(); err == nil { r = planr.SetConfigDirFromTree(r, wd) -- 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') 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/main.go | 1 + cmd/planr/sub/evaluate.go | 52 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 8 deletions(-) (limited to 'cmd/planr') diff --git a/cmd/planr/main.go b/cmd/planr/main.go index d250bbd..b073115 100644 --- a/cmd/planr/main.go +++ b/cmd/planr/main.go @@ -19,6 +19,7 @@ func printUsage(w io.Writer) { fmt.Fprintln(w, " version ") fmt.Fprintln(w, " build ") fmt.Fprintln(w, " evaluate ") + fmt.Fprintln(w, " evaluate -json ") fmt.Fprintln(w, " clean ") fmt.Fprintln(w, " config ") } 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 0f8c8df3e9d4ed05475b0fa3f1d26253e3de719d Mon Sep 17 00:00:00 2001 From: Flu0r1ne Date: Sun, 5 Sep 2021 14:01:17 -0500 Subject: Clarify config cmd in version --- cmd/planr/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd/planr') diff --git a/cmd/planr/main.go b/cmd/planr/main.go index b073115..d179b76 100644 --- a/cmd/planr/main.go +++ b/cmd/planr/main.go @@ -21,7 +21,7 @@ func printUsage(w io.Writer) { fmt.Fprintln(w, " evaluate ") fmt.Fprintln(w, " evaluate -json ") fmt.Fprintln(w, " clean ") - fmt.Fprintln(w, " config ") + fmt.Fprintln(w, " config ") } func dieUsage() { -- 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/main.go | 1 + cmd/planr/sub/evaluate.go | 36 ++++++++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 6 deletions(-) (limited to 'cmd/planr') diff --git a/cmd/planr/main.go b/cmd/planr/main.go index d179b76..93f1cbf 100644 --- a/cmd/planr/main.go +++ b/cmd/planr/main.go @@ -19,6 +19,7 @@ func printUsage(w io.Writer) { fmt.Fprintln(w, " version ") fmt.Fprintln(w, " build ") fmt.Fprintln(w, " evaluate ") + fmt.Fprintln(w, " evaluate ... ") fmt.Fprintln(w, " evaluate -json ") fmt.Fprintln(w, " clean ") fmt.Fprintln(w, " config ") 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') 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 From fd66fb134967067ed7e1c3182325f646b73c730b Mon Sep 17 00:00:00 2001 From: Flu0r1ne Date: Sun, 5 Sep 2021 20:17:00 -0500 Subject: Fix bug where standard dirs are not set due to abs positioning --- cmd/planr/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd/planr') diff --git a/cmd/planr/main.go b/cmd/planr/main.go index 93f1cbf..2243203 100644 --- a/cmd/planr/main.go +++ b/cmd/planr/main.go @@ -76,7 +76,7 @@ func main() { log.SetFlags(log.Llongfile | log.Lmsgprefix) log.SetPrefix("planr: ") - if len(os.Args) < 2 { + if flag.NArg() < 1 { dieUsage() } -- cgit v1.2.3