summaryrefslogtreecommitdiff
path: root/runner.go
diff options
context:
space:
mode:
Diffstat (limited to 'runner.go')
-rw-r--r--runner.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/runner.go b/runner.go
new file mode 100644
index 0000000..5c66573
--- /dev/null
+++ b/runner.go
@@ -0,0 +1,63 @@
+package planr
+
+type Runner struct {
+ adapters []Adapter
+}
+
+func (r *Runner) RegisterAdapter(a Adapter) {
+ r.adapters = append(r.adapters, a)
+}
+
+func (r Runner) adapterCfgs() []AdapterConfig {
+ cgs := make([]AdapterConfig, len(r.adapters))
+
+ for _, adapter := range r.adapters {
+ cgs = append(cgs, adapter.Config())
+ }
+
+ return cgs
+}
+
+func (r Runner) collectUnits(root string) []TestCase {
+ tcs := make([]TestCase, 10)
+
+ collectUnits(root, nil, r.adapterCfgs(), &tcs)
+
+ return tcs
+}
+
+func (r Runner) cycle(tcs []TestCase) []TestResult {
+ results := make([]TestResult, 0)
+
+ for _, adapter := range r.adapters {
+ aname := adapter.Config().Name
+
+ adapter.InitializeBuild()
+
+ for _, tc := range tcs {
+ if tc.ContainsAdapter(aname) {
+ adapter.Build(tc)
+ }
+ }
+
+ adapter.FinalizeBuild()
+
+ for _, tc := range tcs {
+ if tc.ContainsAdapter(aname) {
+ results = append(results, adapter.Evaluate(tc))
+ }
+ }
+
+ adapter.Cleanup()
+ }
+
+ return results
+}
+
+func (r Runner) Run(root string) [] TestResult {
+ tcs := r.collectUnits(root)
+
+ trs := r.cycle(tcs)
+
+ return trs
+}