summaryrefslogtreecommitdiff
path: root/cmd/planr/sub
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/planr/sub')
-rw-r--r--cmd/planr/sub/build.go16
-rw-r--r--cmd/planr/sub/clean.go7
-rw-r--r--cmd/planr/sub/cli.go60
-rw-r--r--cmd/planr/sub/common.go15
-rw-r--r--cmd/planr/sub/config.go28
-rw-r--r--cmd/planr/sub/evaluate.go89
6 files changed, 150 insertions, 65 deletions
diff --git a/cmd/planr/sub/build.go b/cmd/planr/sub/build.go
index 58c3a38..e93e0cb 100644
--- a/cmd/planr/sub/build.go
+++ b/cmd/planr/sub/build.go
@@ -2,18 +2,10 @@ package sub
import (
"golang.flu0r1ne.net/planr"
- "golang.flu0r1ne.net/planr/adapters/gtest"
)
-func Runner() planr.Runner {
- r := planr.Runner {}
- r.RegisterAdapter(&gtest.GtestAdapter{})
- return r
-}
-
-func Build(params []string) {
-
- rd := planr.RubricDir()
-
- Runner().Build(rd)
+func Build(runner planr.Runner, params []string, cfg * planr.Config) {
+ dieIncompatibleVersion(cfg)
+ tcs := runner.CollectCases()
+ runner.Build(tcs)
}
diff --git a/cmd/planr/sub/clean.go b/cmd/planr/sub/clean.go
new file mode 100644
index 0000000..d658c10
--- /dev/null
+++ b/cmd/planr/sub/clean.go
@@ -0,0 +1,7 @@
+package sub
+
+import "golang.flu0r1ne.net/planr"
+
+func Clean(runner planr.Runner, params []string) {
+ runner.Clean()
+}
diff --git a/cmd/planr/sub/cli.go b/cmd/planr/sub/cli.go
index 0e6a942..e6f2256 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);
}
}
@@ -109,14 +107,16 @@ func tcPprint(tc planr.TestCase) {
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
- pprintLabeled("score", fmt.Sprintf(
- "%.2f/%.2f ~= %.1f%%", earned, points_total, percent,
- ));
+ if score.TotalPoints != 0 {
+ pprintLabeled("score", fmt.Sprintf(
+ "%.2f/%.2f ~= %.1f%%", score.EarnedPoints, score.TotalPoints, percent,
+ ));
+ }
}
diff --git a/cmd/planr/sub/common.go b/cmd/planr/sub/common.go
new file mode 100644
index 0000000..9126f3c
--- /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 != 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/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 <parameter>\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 8ce4d81..30d30d2 100644
--- a/cmd/planr/sub/evaluate.go
+++ b/cmd/planr/sub/evaluate.go
@@ -1,38 +1,81 @@
package sub
import (
- "golang.flu0r1ne.net/planr"
+ "encoding/json"
+ "fmt"
+ "log"
+ "flag"
+
+ "golang.flu0r1ne.net/planr"
)
-func Evaluate(params []string) {
- rd := planr.RubricDir()
+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)
+ }
+}
- tcs := Runner().Evaluate(rd)
+func jsonPrint(results gradingResults) {
+ res, err := json.Marshal(results)
- earned := 0.0
- total := 0.0
- passed := 0
- for _, tc := range tcs {
- cfg := tc.Config
+ if err != nil {
+ log.Fatalf("Error printing JSON: %v\n", err)
+ }
- if cfg.Points != nil {
- points := float64(*cfg.Points)
+ fmt.Println(string(res))
+}
- total += points
+func Evaluate(runner planr.Runner, params []string, cfg *planr.Config) {
+ f := flag.NewFlagSet("evaluate", flag.ExitOnError)
- if tc.Result.Status == planr.PASSING {
- earned += points
- passed++
- }
+ 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
}
- tcPprint(tc)
+ for i := range tcs {
+ if membershipFun[tcs[i].Cname] {
+ filteredTcs = append(filteredTcs, tcs[i])
+ }
+ }
+ } else {
+ summarizeScore = true
+ filteredTcs = tcs
}
- printResults(
- passed,
- len(tcs),
- earned,
- total,
- );
+ trs := runner.Evaluate(filteredTcs)
+
+ results := gradingResults {
+ TestResults: trs,
+ Score: planr.Score(trs),
+ }
+
+ if *jsonOutput {
+ jsonPrint(results)
+ } else {
+ prettyPrint(results, summarizeScore)
+ }
}