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 Include_src *bool Compiler_options string } 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 } if(child.Compiler_options == "") { child.Compiler_options = parent.Compiler_options } if(child.Include_src == nil) { child.Include_src = parent.Include_src} } 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; } if c.Include_src == nil { c.Include_src = new(bool) *c.Include_src = true } } 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 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 }