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
|
package gtest
import (
"log"
"os"
"path"
"os/exec"
"golang.flu0r1ne.net/planr"
)
const GTEST_CMAKE = "CMakeLists.txt"
func safeWd() string{
wd, err := os.Getwd()
if err != nil {
log.Fatalf("Could not get GtestBuildDir %s %v\n", wd, err)
}
return wd
}
type Adapter struct {
dirs planr.DirConfig
buildDir string
}
func (a *Adapter) Config() planr.AdapterConfig {
return planr.AdapterConfig {
Name: "gtest",
ParseConfig: ParseConfig,
ParseDefaultConfig: ParseDefaultConfig,
}
}
func (a *Adapter) Init(ctx planr.PipelineContext) {
a.dirs = ctx.Dirs
a.buildDir = ctx.AdapterDir
}
func (adapter Adapter) Build(tcs []planr.TestCase) {
finalizeConfigs(tcs)
exes := createExecutables(tcs)
cmakeFile := path.Join(adapter.buildDir, GTEST_CMAKE)
cmakeUnits := cmakeUnits(exes, adapter.dirs)
generateCmakeScript(cmakeFile, cmakeUnits)
cmd := exec.Command("cmake", "-S", ".", "-B", ".")
cmd.Dir = adapter.buildDir
planr.Exec(cmd)
cmd = exec.Command("make", "gtest", "gmock")
cmd.Dir = adapter.buildDir
planr.Exec(cmd)
}
func (adapter *Adapter) Evaluate(tcs []planr.TestCase) [] planr.TestResult {
finalizeConfigs(tcs)
results := make([]planr.TestResult, 0)
exes := createExecutables(tcs)
c := make(chan []planr.TestResult, len(exes))
for i := range exes {
go func(exe *executable) {
succeed, buildFailures := exe.compile(adapter.buildDir)
if ! succeed {
c <- buildFailures
return
}
runtimeResults := exe.execute(adapter.buildDir)
c <- runtimeResults
}(&exes[i])
}
for range exes {
results = append(results, (<-c)...)
}
return results
}
func NewAdapter() *Adapter {
return new(Adapter)
}
|