package gtest import ( "log" "strings" "path" "golang.flu0r1ne.net/planr" "github.com/BurntSushi/toml" ) const ( DEFAULT_TIMEOUT = 1000 ) type Defaults struct { Name string Suite string Testfile string Srcs []string Timeout uint } func (child *Defaults) Inherit(p interface{}) { parent := p.(*Defaults) 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 Config struct { Defaults } func (c * Config) finalize(path string) { if c.Name == "" { log.Fatalf("\"name\" is not defined for unit: %s\n", path) } else if c.Suite == "" { log.Fatalf("\"suite\" is not defined for unit: %s\n", path) } else if c.Testfile == "" { log.Fatalf("\"testfile\" is not defined for unit: %s\n", path) } if c.Timeout == 0 { c.Timeout = DEFAULT_TIMEOUT; } } 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 builder.String() } 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 units } func finalizeConfigs(tcs []planr.TestCase) { for i := range tcs { cfg := tcs[i].AdapterConfig().(*Config) cfg.finalize(tcs[i].Path) } } func ParseConfig(prim toml.Primitive) (planr.InheritableConfig, error) { config := Config{} if err := toml.PrimitiveDecode(prim, &config); err != nil { return nil, err } return &config, nil } func ParseDefaultConfig(prim toml.Primitive) (planr.InheritableConfig, error) { config := Defaults{} if err := toml.PrimitiveDecode(prim, &config); err != nil { return nil, err } return &config, nil }