aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile8
-rw-r--r--adapters/gtest/adapter.go4
-rw-r--r--adapters/gtest/config.go4
-rw-r--r--cmd/planr/main.go4
-rw-r--r--cmd/planr/sub/build.go2
-rw-r--r--cmd/planr/sub/clean.go5
-rw-r--r--runner.go32
-rw-r--r--stddirs.go41
8 files changed, 62 insertions, 38 deletions
diff --git a/Makefile b/Makefile
index 424c67d..dd6031f 100644
--- a/Makefile
+++ b/Makefile
@@ -8,8 +8,14 @@ endif
CMD := planr
+ifdef DEBUG
+ FLAGS=-ldflags=-w
+endif
+
+MAIN_PKG := ./cmd/planr/main.go
+
$(CMD):
- go build -o $(CMD) ./cmd/planr/main.go
+ go build $(FLAGS) -o $(CMD) $(MAIN_PKG)
install:
mkdir -p $(DESTDIR)$(PREFIX)$(BINDIR)/
diff --git a/adapters/gtest/adapter.go b/adapters/gtest/adapter.go
index 9331cf7..415d823 100644
--- a/adapters/gtest/adapter.go
+++ b/adapters/gtest/adapter.go
@@ -19,8 +19,8 @@ const GTEST_CMAKE = "CMakeLists.txt"
func makeUnit(tc *planr.TestCase, dirs planr.DirConfig) cmakeUnit {
cfg := tc.AdapterConfig().(*GtestConfig)
- testpath := path.Join(dirs.TestsDir(), *cfg.Testfile)
- srclist := cfg.srcList(dirs.SrcDir())
+ testpath := path.Join(dirs.Tests(), *cfg.Testfile)
+ srclist := cfg.srcList(dirs.Src())
return cmakeUnit {
tc.Cname,
diff --git a/adapters/gtest/config.go b/adapters/gtest/config.go
index 4f8735f..4105932 100644
--- a/adapters/gtest/config.go
+++ b/adapters/gtest/config.go
@@ -12,9 +12,7 @@ type GtestDefaults struct {
Name *string
Suite *string
Testfile *string
- Test_root *string
Srcs *[]string
- Srcs_root *string
}
func (child *GtestDefaults) Inherit(p interface{}) {
@@ -23,9 +21,7 @@ func (child *GtestDefaults) Inherit(p interface{}) {
if(child.Name == nil) { child.Name = parent.Name }
if(child.Suite == nil) { child.Suite = parent.Suite }
if(child.Testfile == nil) { child.Testfile = parent.Testfile }
- if(child.Test_root == nil) { child.Test_root = parent.Test_root }
if(child.Srcs == nil) { child.Srcs = parent.Srcs }
- if(child.Srcs_root == nil) { child.Srcs_root = parent.Srcs_root }
}
diff --git a/cmd/planr/main.go b/cmd/planr/main.go
index e2a85ed..4b69a36 100644
--- a/cmd/planr/main.go
+++ b/cmd/planr/main.go
@@ -19,6 +19,8 @@ func printUsage(w io.Writer) {
fmt.Fprintln(w, " version ")
fmt.Fprintln(w, " build ")
fmt.Fprintln(w, " evaluate ")
+ fmt.Fprintln(w, " clean ")
+
}
func dieUsage() {
@@ -45,6 +47,8 @@ func main() {
sub.Build(subargs)
case "evaluate","eval":
sub.Evaluate(subargs)
+ case "clean":
+ sub.Clean(subargs)
case "help", "-h", "-help", "--help":
printUsage(os.Stdout)
default:
diff --git a/cmd/planr/sub/build.go b/cmd/planr/sub/build.go
index a8b19ec..142ef1c 100644
--- a/cmd/planr/sub/build.go
+++ b/cmd/planr/sub/build.go
@@ -11,7 +11,7 @@ func Runner() planr.Runner {
r.RegisterAdapter(&gtest.GtestAdapter{})
- if wd, err := os.Getwd(); err != nil {
+ if wd, err := os.Getwd(); err == nil {
r.SetConfigDirFromTree(wd)
}
diff --git a/cmd/planr/sub/clean.go b/cmd/planr/sub/clean.go
new file mode 100644
index 0000000..d40e967
--- /dev/null
+++ b/cmd/planr/sub/clean.go
@@ -0,0 +1,5 @@
+package sub
+
+func Clean(params []string) {
+ Runner().Clean()
+}
diff --git a/runner.go b/runner.go
index f2eb8e9..0a6243c 100644
--- a/runner.go
+++ b/runner.go
@@ -8,7 +8,7 @@ import (
type Runner struct {
adapters []Adapter
- DirConfig
+ dirs DirConfig
}
func (r *Runner) RegisterAdapter(a Adapter) {
@@ -47,7 +47,7 @@ func (r Runner) checkConfig(tcs []TestCase) {
func (r Runner) setupEnv(adapter Adapter) {
nm := adapter.Config().Name
- wd := path.Join(r.BuildDir(), nm)
+ wd := path.Join(r.dirs.Build(), nm)
if !directoryExists(wd) {
if err := os.Mkdir(wd, 0755); err != nil {
@@ -70,18 +70,26 @@ func (r Runner) build(tcs []TestCase) {
adapter.Build(tcTab[nm])
}
- safeCd(r.ConfigDir())
+ safeCd(r.dirs.Config())
+}
+
+func (r Runner) init_adapters() {
+ for _, adapter := range r.adapters {
+ adapter.Init(r.dirs)
+ }
}
func (r Runner) units() []TestCase {
- return collectUnits(r.RubricDir(), r.adapterCfgs())
+ return collectUnits(r.dirs.Rubric(), r.adapterCfgs())
}
func (r Runner) Build() {
- units := r.units()
+ r.init_adapters()
- if !directoryExists(r.BuildDir()) {
- r.MkBuildDir()
+ units := r.units()
+
+ if !directoryExists(r.dirs.Build()) {
+ r.dirs.MkBuild()
}
r.build(units)
@@ -97,10 +105,12 @@ func (r Runner) evaluate(tcs []TestCase) {
adapter.Evaluate(tcTab[nm])
}
- safeCd(r.ConfigDir())
+ safeCd(r.dirs.Config())
}
func (r Runner) Evaluate() []TestCase {
+ r.init_adapters()
+
units := r.units()
r.evaluate(units)
@@ -109,5 +119,9 @@ func (r Runner) Evaluate() []TestCase {
}
func (r Runner) Clean() {
- r.CleanBuildDir()
+ r.dirs.CleanBuild()
+}
+
+func (r * Runner) SetConfigDirFromTree(childPath string) {
+ r.dirs.SetConfigFromTree(childPath)
}
diff --git a/stddirs.go b/stddirs.go
index 14776d8..2385529 100644
--- a/stddirs.go
+++ b/stddirs.go
@@ -66,22 +66,22 @@ func dirFromEnv(name, env string) *string {
return nil
}
-func (c *DirConfig) SetSrcDir(srcDir string) {
+func (c *DirConfig) SetSrc(srcDir string) {
dieDirAbsent("src", srcDir)
c.src = srcDir
}
-func (c *DirConfig) SetConfigDir(configDir string) {
+func (c *DirConfig) SetConfig(configDir string) {
dieDirAbsent("planr (config)", configDir)
c.config = configDir
}
-func (c *DirConfig) SetBuildDir(buildDir string) {
+func (c *DirConfig) SetBuild(buildDir string) {
dieDirAbsent("build", buildDir)
c.build = buildDir
}
-func (c *DirConfig) SetConfigDirFromTree(cdir string) {
+func (c *DirConfig) SetConfigFromTree(cdir string) {
var configDir string
found := traverseUp(cdir, func (path string) bool {
@@ -103,12 +103,11 @@ func (c *DirConfig) SetConfigDirFromTree(cdir string) {
}
}
-func (c DirConfig) ConfigDir() string {
+func (c DirConfig) Config() string {
if c.config != "" {
return c.config
}
-
if dir := dirFromEnv("config", ENV_CONFIG_DIR); dir != nil {
c.config = *dir
return c.config
@@ -122,7 +121,7 @@ func (c DirConfig) ConfigDir() string {
return c.config
}
-func (c DirConfig) SrcDir() string {
+func (c DirConfig) Src() string {
if c.src != "" {
return c.src
}
@@ -133,11 +132,11 @@ func (c DirConfig) SrcDir() string {
}
// set path relative to config
- dir := c.ConfigDir()
+ dir := c.Config()
return path.Join(dir, DEFAULT_PATH_SRC)
}
-func (c DirConfig) BuildDir() string {
+func (c DirConfig) Build() string {
if c.src != "" {
return c.src
}
@@ -147,38 +146,38 @@ func (c DirConfig) BuildDir() string {
return c.build
}
- dir := c.ConfigDir()
+ dir := c.Config()
return path.Join(dir, DEFAULT_PATH_BUILD)
}
-func (c DirConfig) CleanBuildDir() {
- build := c.BuildDir()
+func (c DirConfig) CleanBuild() {
+ build := c.Build()
if err := os.RemoveAll(build); err != nil {
log.Fatalf("Cannot build directory %v\n", err)
}
- if err := os.Remove(build); err != nil {
- log.Fatalf("Could not remove build directory %v\n", err)
- }
+ // if err := os.Remove(build); err != nil {
+ // log.Fatalf("Could not remove build directory %v\n", err)
+ // }
}
-func (c DirConfig) MkBuildDir() {
- build := c.BuildDir()
+func (c DirConfig) MkBuild() {
+ build := c.Build()
if err := os.Mkdir(build, 0755); err != nil {
log.Fatalf("Could not create build directory %v\n", err)
}
}
-func (c DirConfig) RubricDir() string {
- rubric := path.Join(c.ConfigDir(), "rubric")
+func (c DirConfig) Rubric() string {
+ rubric := path.Join(c.Config(), "rubric")
dieDirAbsent("rubric", rubric)
return rubric
}
-func (c DirConfig) TestsDir() string {
- tests := path.Join(c.ConfigDir(), "tests")
+func (c DirConfig) Tests() string {
+ tests := path.Join(c.Config(), "tests")
dieDirAbsent("tests", tests)
return tests
}