package planr import "fmt" 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 } 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 } func (r Runner) checkConfig(tcs []TestCase) { for _, tc := range tcs { tc.Config.ensureSatisfied(tc.Path) } } func (r Runner) build(tcs []TestCase) { r.checkConfig(tcs) tcTab := r.buildTcLUT(tcs) for _, adapter := range r.adapters { nm := adapter.Config().Name fmt.Printf("[R] Building adapter \"%s\"\n", nm) adapter.Build(tcTab[nm]) } } func (r Runner) units(root string) []TestCase { return collectUnits(root, r.adapterCfgs()) } func (r Runner) Build(root string) { units := r.units(root) r.build(units) } func (r Runner) evaluate(tcs []TestCase) { tcTab := r.buildTcLUT(tcs) for _, adapter := range r.adapters { nm := adapter.Config().Name fmt.Printf("[R] Evaluating adapter \"%s\"\n", nm) adapter.Evaluate(tcTab[nm]) } } func (r Runner) Evaluate(root string) []TestCase { units := r.units(root) r.evaluate(units) return units }