diff options
Diffstat (limited to 'adapters/gtest/config.go')
-rw-r--r-- | adapters/gtest/config.go | 97 |
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 |