summaryrefslogtreecommitdiff
path: root/runner.go
diff options
context:
space:
mode:
Diffstat (limited to 'runner.go')
-rw-r--r--runner.go100
1 files changed, 61 insertions, 39 deletions
diff --git a/runner.go b/runner.go
index d3d4b08..f613d44 100644
--- a/runner.go
+++ b/runner.go
@@ -7,8 +7,8 @@ import (
)
type Runner struct {
- adapters []Adapter
- dirs DirConfig
+ adapters map[string] Adapter
+ dirs DirConfig
}
func (r Runner) adapterCfgs() []AdapterConfig {
@@ -21,20 +21,7 @@ func (r Runner) adapterCfgs() []AdapterConfig {
return cgs
}
-type tcTab map[string] []*TestCase
-
-func (r Runner) buildTcLUT(tcs []TestCase) tcTab {
- m := make(tcTab, 0)
-
- for i := range tcs {
- tc := &tcs[i]
- nm := *tc.Config.Adapter
- m[nm] = append(m[nm], tc)
- }
-
- return m
-}
-
+// TODO: Move into configuration parsing
func (r Runner) checkConfig(tcs []TestCase) {
for _, tc := range tcs {
tc.Config.ensureSatisfied(tc.Path)
@@ -54,55 +41,90 @@ func (r Runner) setupEnv(adapter Adapter) {
safeCd(wd)
}
-func (r Runner) build(tcs []TestCase) {
+type adapterTestSet struct {
+ adapter Adapter
+ tcs []TestCase
+}
+
+func (r Runner) groupByAdapter(tcs []TestCase) []adapterTestSet {
r.checkConfig(tcs)
+
+ pairs := make(map[string] adapterTestSet, 0)
- tcTab := r.buildTcLUT(tcs)
+ for _, tc := range tcs {
+ // TODO: Make non-pointer
+ adptNm := *tc.Config.Adapter
+
+ // See if adapter if contained in map
+ adapter, contained := r.adapters[adptNm]
+
+ if !contained {
+ log.Fatalf("Cannot find adapter \"%s\" for testcase \"%s\"", adptNm, tc.Cname)
+ }
- for _, adapter := range r.adapters {
- nm := adapter.Config().Name
- r.setupEnv(adapter)
+ pair, exists := pairs[adptNm]
- adapter.Build(tcTab[nm])
+ if !exists {
+ pair.adapter = adapter
+ }
+
+ pair.tcs = append(pair.tcs, tc)
+
+ pairs[adptNm] = pair
}
- safeCd(r.dirs.Config())
+
+ // Convert to slice
+ set := make([]adapterTestSet, 0)
+
+ for _, pair := range pairs {
+ set = append(set, pair)
+ }
+
+ return set
}
-func (r Runner) units() []TestCase {
+func (r Runner) CollectCases() []TestCase {
return collectUnits(r.dirs.Rubric(), r.adapterCfgs())
}
-func (r Runner) Build() {
- units := r.units()
+func (r Runner) Build(tcs []TestCase) {
if !directoryExists(r.dirs.Build()) {
r.dirs.MkBuild()
}
- r.build(units)
-}
+ testSets := r.groupByAdapter(tcs)
-func (r Runner) evaluate(tcs []TestCase) {
- tcTab := r.buildTcLUT(tcs)
-
- for _, adapter := range r.adapters {
- nm := adapter.Config().Name
+ for _, pair := range testSets {
+ adapter := pair.adapter
+ cases := pair.tcs
r.setupEnv(adapter)
- adapter.Evaluate(tcTab[nm])
+
+ adapter.Build(cases)
}
safeCd(r.dirs.Config())
}
-func (r Runner) Evaluate() []TestCase {
+func (r Runner) Evaluate(tcs []TestCase) []TestCase {
+ testSets := r.groupByAdapter(tcs)
+ results := make([]TestCase, 0)
- units := r.units()
+ for _, pair := range testSets {
+ adapter := pair.adapter
+ cases := pair.tcs
+
+ r.setupEnv(adapter)
+ resultSet := adapter.Evaluate(cases)
- r.evaluate(units)
+ results = append(results, resultSet...)
+ }
+
+ safeCd(r.dirs.Config())
- return units
+ return results
}
func (r Runner) Clean() {
@@ -121,7 +143,7 @@ func (r Runner) SrcDir() string {
return r.dirs.Src()
}
-func NewRunner(adapters []Adapter, dirs DirConfig) Runner {
+func NewRunner(adapters map[string]Adapter, dirs DirConfig) Runner {
r := Runner{adapters, dirs}
for _, adapter := range r.adapters {