diff options
author | Flu0r1ne <flur01ne@flu0r1ne.net> | 2021-09-04 15:38:30 -0500 |
---|---|---|
committer | Flu0r1ne <flur01ne@flu0r1ne.net> | 2021-09-04 15:38:30 -0500 |
commit | cc7ba659adbc5ad55e1ce67f76952f2b8392c9c9 (patch) | |
tree | 2df3f62bd4dcda45732b0955f2797596f0ae5743 /runner.go | |
parent | b3252d2bd488b5b58cf0e46151ff9db0721c5fc6 (diff) | |
download | planr-cc7ba659adbc5ad55e1ce67f76952f2b8392c9c9.tar.xz planr-cc7ba659adbc5ad55e1ce67f76952f2b8392c9c9.zip |
Refactor build/eval pipeline to use clearer IO model and adapter segmentation methods
Diffstat (limited to 'runner.go')
-rw-r--r-- | runner.go | 100 |
1 files changed, 61 insertions, 39 deletions
@@ -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 { |