summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlu0r1ne <flur01ne@flu0r1ne.net>2021-09-03 21:14:28 -0500
committerFlu0r1ne <flur01ne@flu0r1ne.net>2021-09-03 21:14:28 -0500
commit2d197f1ce3eac8cecb5a655fcb5343cbe562ab1a (patch)
tree3b24b0cdd0ddf6456b8bac5fafcf6a1503aaa6aa
parent8fa0c34eac027c69a0fce8b5a8251e394cd4d888 (diff)
downloaddeb-planr-2d197f1ce3eac8cecb5a655fcb5343cbe562ab1a.tar.xz
deb-planr-2d197f1ce3eac8cecb5a655fcb5343cbe562ab1a.zip
Add new test runner API
-rw-r--r--adapters/gtest/adapter.go7
-rw-r--r--cmd/planr/main.go21
-rw-r--r--runner.go20
-rw-r--r--runner_builder.go42
4 files changed, 57 insertions, 33 deletions
diff --git a/adapters/gtest/adapter.go b/adapters/gtest/adapter.go
index 415d823..0a955ef 100644
--- a/adapters/gtest/adapter.go
+++ b/adapters/gtest/adapter.go
@@ -188,8 +188,7 @@ func (adapter *GtestAdapter) Evaluate(tcs []*planr.TestCase) {
// compilation failure
if !ok {
- fmt.Printf("CAN'T FIND %s: status %d\n", tc.Cname, tc.Result.Status)
-
+
if tc.Result.Status == planr.PASSING {
cfg := tc.AdapterConfig().(*GtestConfig)
@@ -214,3 +213,7 @@ func (adapter *GtestAdapter) Evaluate(tcs []*planr.TestCase) {
tc.Result.TestOutput = result.testOutput
}
}
+
+func New() *GtestAdapter {
+ return new(GtestAdapter)
+}
diff --git a/cmd/planr/main.go b/cmd/planr/main.go
index 277ffc8..b2a0975 100644
--- a/cmd/planr/main.go
+++ b/cmd/planr/main.go
@@ -27,15 +27,14 @@ func dieUsage() {
os.Exit(1)
}
-func NewRunner() planr.Runner {
- r := planr.Runner {}
-
- r.RegisterAdapter(&gtest.GtestAdapter{})
+func getConfiguredRunner() planr.Runner {
+ r := planr.ConfigureRunner()
+ r = planr.RegisterAdapter(r, gtest.New())
if wd, err := os.Getwd(); err == nil {
- r.SetConfigDirFromTree(wd)
+ r = planr.SetConfigDirFromTree(r, wd)
}
-
+
src := flag.String("srcdir", "", "source directory")
config := flag.String("configdir", "", "config directory")
build := flag.String("builddir", "", "build directory")
@@ -43,18 +42,18 @@ func NewRunner() planr.Runner {
flag.Parse()
if src != nil && *src != "" {
- r.SetSrcDir(*src)
+ r = planr.SetSrcDir(r, *src)
}
if config != nil && *config != "" {
- r.SetConfigDir(*config)
+ r = planr.SetConfigDir(r, *config)
}
if build != nil && *build != "" {
- r.SetBuildDir(*build)
+ r = planr.SetBuildDir(r, *build)
}
- return r
+ return r.New()
}
func main() {
@@ -66,7 +65,7 @@ func main() {
dieUsage()
}
- runner := NewRunner()
+ runner := getConfiguredRunner()
subcommand := flag.Arg(0)
subargs := flag.Args()[1:]
diff --git a/runner.go b/runner.go
index c0c926a..1cc509e 100644
--- a/runner.go
+++ b/runner.go
@@ -11,10 +11,6 @@ type Runner struct {
dirs DirConfig
}
-func (r *Runner) RegisterAdapter(a Adapter) {
- r.adapters = append(r.adapters, a)
-}
-
func (r Runner) adapterCfgs() []AdapterConfig {
cgs := make([]AdapterConfig, len(r.adapters))
@@ -122,22 +118,6 @@ func (r Runner) Clean() {
r.dirs.CleanBuild()
}
-func (r * Runner) SetConfigDirFromTree(childPath string) {
- r.dirs.SetConfigFromTree(childPath)
-}
-
-func (r * Runner) SetBuildDir(dir string) {
- r.dirs.SetBuild(dir)
-}
-
-func (r * Runner) SetConfigDir(dir string) {
- r.dirs.SetConfig(dir)
-}
-
-func (r * Runner) SetSrcDir(dir string) {
- r.dirs.SetSrc(dir)
-}
-
func (r Runner) BuildDir() string {
return r.dirs.Build();
}
diff --git a/runner_builder.go b/runner_builder.go
new file mode 100644
index 0000000..848d09b
--- /dev/null
+++ b/runner_builder.go
@@ -0,0 +1,42 @@
+package planr
+
+type RunnerBuilder struct {
+ adapters [] Adapter
+ dirs DirConfig
+}
+
+func ConfigureRunner() RunnerBuilder {
+ return RunnerBuilder {}
+}
+
+func RegisterAdapter(b RunnerBuilder, a Adapter) RunnerBuilder {
+ b.adapters = append(b.adapters, a)
+ return b
+}
+
+func SetConfigDirFromTree(b RunnerBuilder, childPath string) RunnerBuilder {
+ b.dirs.SetConfigFromTree(childPath)
+ return b
+}
+
+func SetConfigDir(b RunnerBuilder, dir string) RunnerBuilder {
+ b.dirs.SetConfig(dir)
+ return b
+}
+
+func SetBuildDir(b RunnerBuilder, dir string) RunnerBuilder {
+ b.dirs.SetBuild(dir)
+ return b
+}
+
+func SetSrcDir(b RunnerBuilder, dir string) RunnerBuilder {
+ b.dirs.SetSrc(dir)
+ return b
+}
+
+func (b RunnerBuilder) New() Runner {
+ return Runner {
+ dirs: b.dirs,
+ adapters: b.adapters,
+ }
+}