summaryrefslogtreecommitdiff
path: root/adapters/gtest/config.go
diff options
context:
space:
mode:
authorflu0r1ne <flu0r1ne@flu0r1ne.net>2021-09-05 20:37:19 -0500
committerflu0r1ne <flu0r1ne@flu0r1ne.net>2021-09-05 20:37:19 -0500
commitf5b60238e05b124eb40f805eb4a0bbfc0b043da5 (patch)
treef461bff108f5ddafc4078aa7394d7bf2a6309cc9 /adapters/gtest/config.go
parent8f22bd4f5b4eb6996c524bcb6948d36cef0ac822 (diff)
parentfd66fb134967067ed7e1c3182325f646b73c730b (diff)
downloaddeb-planr-f5b60238e05b124eb40f805eb4a0bbfc0b043da5.tar.xz
deb-planr-f5b60238e05b124eb40f805eb4a0bbfc0b043da5.zip
Merge branch 'upstream' into ppa
Merge v0.1.0
Diffstat (limited to 'adapters/gtest/config.go')
-rw-r--r--adapters/gtest/config.go97
1 files changed, 53 insertions, 44 deletions
diff --git a/adapters/gtest/config.go b/adapters/gtest/config.go
index cff45fa..533f266 100644
--- a/adapters/gtest/config.go
+++ b/adapters/gtest/config.go
@@ -2,79 +2,88 @@ package gtest
import (
"log"
- "golang.flu0r1ne.net/planr"
"strings"
+ "path"
+ "golang.flu0r1ne.net/planr"
"github.com/BurntSushi/toml"
)
-type GtestDefaults struct {
- Name *string
- Suite *string
- Testfile *string
- Test_root *string
- Srcs *[]string
- Srcs_root *string
+const (
+ DEFAULT_TIMEOUT = 1000
+)
+
+type Defaults struct {
+ Name string
+ Suite string
+ Testfile string
+ Srcs []string
+ Timeout uint
}
-func (child *GtestDefaults) Inherit(p interface{}) {
- parent := p.(*GtestDefaults)
+func (child *Defaults) Inherit(p interface{}) {
+ parent := p.(*Defaults)
- 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 }
+ if(child.Name == "") { child.Name = parent.Name }
+ if(child.Suite == "") { child.Suite = parent.Suite }
+ if(child.Testfile == "") { child.Testfile = parent.Testfile }
+ if(len(child.Srcs) == 0) { child.Srcs = parent.Srcs }
+ if(child.Timeout == 0) { child.Timeout = parent.Timeout }
}
-type GtestConfig struct {
- GtestDefaults
+type Config struct {
+ Defaults
}
-func (g GtestConfig) ensureSatisfied(path string) {
- if g.Name == nil {
+func (c * Config) finalize(path string) {
+ if c.Name == "" {
log.Fatalf("\"name\" is not defined for unit: %s\n", path)
- } else if g.Suite == nil {
+ } else if c.Suite == "" {
log.Fatalf("\"suite\" is not defined for unit: %s\n", path)
- } else if g.Testfile == nil {
+ } else if c.Testfile == "" {
log.Fatalf("\"testfile\" is not defined for unit: %s\n", path)
}
+
+ if c.Timeout == 0 {
+ c.Timeout = DEFAULT_TIMEOUT;
+ }
}
-func (cfg GtestConfig) joinTests(path_ string) string {
- if cfg.Test_root == nil {
- return planr.JoinConfigDir("tests", path_)
+func srcList(srcdir string, srcs []string) string {
+ builder := strings.Builder {}
+
+ for _, src := range srcs {
+ builder.WriteString("\"")
+ builder.WriteString(path.Join(srcdir, src))
+ builder.WriteString("\"\n ")
}
-
- return planr.JoinConfigDir(*cfg.Test_root, path_)
+
+ return builder.String()
}
-func (cfg GtestConfig) joinSrcs(path_ string) string {
- if cfg.Srcs_root == nil {
- return planr.JoinConfigDir("../src", path_)
+func cmakeUnits(e []executable, dirs planr.DirConfig) []cmakeUnit {
+
+ units := make([]cmakeUnit, len(e))
+ for i, exe := range e {
+ testpath := path.Join(dirs.Tests(), exe.testpath)
+ srclist := srcList(dirs.Src(), exe.srcs)
+
+ units[i] = cmakeUnit { exe.exeNm, testpath, srclist }
}
- return planr.JoinConfigDir(*cfg.Srcs_root, path_)
+ return units
}
-func (cfg GtestConfig) srcList() string {
- var srcList string
+func finalizeConfigs(tcs []planr.TestCase) {
+ for i := range tcs {
+ cfg := tcs[i].AdapterConfig().(*Config)
- if cfg.Srcs != nil {
- srcs := make([]string, len(*cfg.Srcs))
- for i, src := range *cfg.Srcs {
- srcs[i] = "\"" + cfg.joinSrcs(src) + "\""
- }
-
- srcList = strings.Join(srcs, "\n ")
+ cfg.finalize(tcs[i].Path)
}
-
- return srcList
}
func ParseConfig(prim toml.Primitive) (planr.InheritableConfig, error) {
- config := GtestConfig{}
+ config := Config{}
if err := toml.PrimitiveDecode(prim, &config); err != nil {
return nil, err
@@ -84,7 +93,7 @@ func ParseConfig(prim toml.Primitive) (planr.InheritableConfig, error) {
}
func ParseDefaultConfig(prim toml.Primitive) (planr.InheritableConfig, error) {
- config := GtestDefaults{}
+ config := Defaults{}
if err := toml.PrimitiveDecode(prim, &config); err != nil {
return nil, err