1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
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
}
|