-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_tests.go
112 lines (98 loc) · 2.41 KB
/
run_tests.go
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
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"time"
)
type GtestTest struct {
Name string `json:"name"`
Status string `json:"status"`
Time string `json:"time"`
Classname string `json:"classname"`
}
type GtestTestsuite struct {
Name string `json:"name"`
Tests int32 `json:"tests"`
Failures int32 `json:"failures"`
Disabled int32 `json:"disabled"`
Errors int32 `json:"errors"`
Time string `json:"time"`
Testsuite []GtestTest `json:"testsuite"`
}
type GtestResults struct {
Name string `json:"name"`
Tests int32 `json:"tests"`
Failures int32 `json:"failures"`
Disabled int32 `json:"disabled"`
Errors int32 `json:"errors"`
Time string `json:"time"`
TimeStamp time.Time `json:"timestamp"`
}
func loadTestResults(filename string) (*GtestResults, error) {
contents, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
var results GtestResults
err = json.Unmarshal(contents, &results)
if err != nil {
return nil, err
}
return &results, nil
}
type testRun struct {
dir string
exe string
err error
state os.ProcessState
}
var verbose bool
func init() {
flag.BoolVar(&verbose, "verbose", false, "Display test output.")
}
func main() {
flag.Parse()
runs := []*testRun{}
for _, test := range flag.Args() {
fmt.Printf("Running %s\n", test)
run := &testRun{
dir: filepath.Dir(test),
exe: filepath.Base(test),
}
cmd := exec.Command("./"+run.exe, "--gtest_output=json")
cmd.Dir = run.dir
out, err := cmd.CombinedOutput()
run.err = err
run.state = *cmd.ProcessState
ioutil.WriteFile(filepath.Join(run.dir, "test_log.txt"), out, 0644)
if verbose {
fmt.Print(string(out))
}
runs = append(runs, run)
}
var totalTests int32
var totalFailures int32
var totalDisabled int32
var totalErrors int32
for _, run := range runs {
results, err := loadTestResults(filepath.Join(run.dir, "test_detail.json"))
if err != nil {
panic(err.Error())
}
totalTests += results.Tests
totalFailures += results.Failures
totalDisabled += results.Disabled
totalErrors += results.Errors
}
fmt.Printf("Failures: %d/%d\n", totalFailures, totalTests)
fmt.Printf("Errors: %d/%d\n", totalErrors, totalTests)
fmt.Printf("Disabled: %d/%d\n", totalDisabled, totalTests)
if totalFailures > 0 || totalErrors > 0 {
os.Exit(1)
}
}