summaryrefslogtreecommitdiff
path: root/adapters/gtest
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/gtest')
-rw-r--r--adapters/gtest/adapter.go64
-rw-r--r--adapters/gtest/results.go17
2 files changed, 65 insertions, 16 deletions
diff --git a/adapters/gtest/adapter.go b/adapters/gtest/adapter.go
index 09e6ac1..600c956 100644
--- a/adapters/gtest/adapter.go
+++ b/adapters/gtest/adapter.go
@@ -16,7 +16,7 @@ import (
const GTEST_CMAKE = "CMakeLists.txt"
func mkUnit(tc *planr.TestCase) cmakeUnit {
- cfg := tc.AdapterConfig("gtest").(*GtestConfig)
+ cfg := tc.AdapterConfig().(*GtestConfig)
return cmakeUnit {
tc.Cname,
@@ -49,7 +49,7 @@ func (adapter *GtestAdapter) Build(tcs []*planr.TestCase) {
for _, tc := range tcs {
fmt.Printf("[R] Building %s (%s)\n", tc.Cname, tc.Path)
- cfg := tc.AdapterConfig("gtest").(*GtestConfig)
+ cfg := tc.AdapterConfig().(*GtestConfig)
cfg.ensureSatisfied(tc.Path)
units = append(units, mkUnit(tc))
@@ -61,15 +61,16 @@ func (adapter *GtestAdapter) Build(tcs []*planr.TestCase) {
planr.RunCmd("cmake", "-S", ".", "-B", ".")
}
-func (adapter *GtestAdapter) Evaluate(tcs []*planr.TestCase) {
- planr.RunCmd("make", "-k")
+type ResultFromId map[string] planr.TestResult
+
+func (adapter *GtestAdapter) execTests(cnames []string) ResultFromId {
buildDir := adapter.Config().Dir()
- results := make([]planr.TestResult, 0)
- for _, tc := range tcs {
- fmt.Printf("[R] Evaluating %s (%s)\n", tc.Cname, tc.Path)
+ lut := make(ResultFromId, 0)
+ for _, exe := range cnames {
+ fmt.Printf("[R] Evaluating %s\n", exe)
- exe := path.Join(buildDir, tc.Cname)
+ exePath := path.Join(buildDir, exe)
f, err := ioutil.TempFile(buildDir, "gtest_adapter_*.json")
@@ -78,7 +79,7 @@ func (adapter *GtestAdapter) Evaluate(tcs []*planr.TestCase) {
}
ctx, cancel := context.WithTimeout(context.Background(), 9999*time.Millisecond)
- cmd := exec.CommandContext(ctx, exe, "--gtest_output=json:" + f.Name())
+ cmd := exec.CommandContext(ctx, exePath, "--gtest_output=json:" + f.Name())
defer cancel()
defer os.Remove(f.Name())
@@ -96,11 +97,50 @@ func (adapter *GtestAdapter) Evaluate(tcs []*planr.TestCase) {
}
if exitFail {
- fmt.Printf("Failure detected")
+ fmt.Printf("")
}
- results = append(results, decodeResults(f)...)
+ for _, r := range decodeResults(f) {
+ lut[exe + "." + r.id] = r.result
+ }
}
- fmt.Println(results)
+ return lut
+}
+
+func exes(tcs []*planr.TestCase) []string {
+ set := make(map[string] bool, 0)
+
+ for _, tc := range tcs {
+ if(!set[tc.Cname]) {
+ set[tc.Cname] = true
+ }
+ }
+
+ exes := make([]string, 0)
+ for k := range set {
+ exes = append(exes, k)
+ }
+
+ return exes
+}
+
+func id(tc *planr.TestCase) string {
+ cfg := tc.AdapterConfig().(*GtestConfig)
+ return tc.Cname + "." + *cfg.Suite + "." + *cfg.Name
+}
+
+func (adapter *GtestAdapter) Evaluate(tcs []*planr.TestCase) {
+ buildDir := adapter.Config().Dir()
+ chdir(buildDir)
+
+ planr.RunCmd("make", "-k")
+
+ files := exes(tcs)
+ resultById := adapter.execTests(files)
+
+ for _, tc := range tcs {
+ result := resultById[id(tc)]
+ tc.Result = &result
+ }
}
diff --git a/adapters/gtest/results.go b/adapters/gtest/results.go
index e5280e3..88e4069 100644
--- a/adapters/gtest/results.go
+++ b/adapters/gtest/results.go
@@ -47,7 +47,12 @@ type gResults struct {
Testsuites []gTestsuites `json:"testsuites"`
}
-func decodeResults(r io.Reader) []planr.TestResult {
+type Result struct {
+ id string
+ result planr.TestResult
+}
+
+func decodeResults(r io.Reader) []Result {
var results gResults
buf := bytes.Buffer{}
@@ -59,14 +64,18 @@ func decodeResults(r io.Reader) []planr.TestResult {
log.Fatal(err)
}
- decoded := make([]planr.TestResult, 0)
+ decoded := make([]Result, 0)
for _, suite := range results.Testsuites {
for _, test := range suite.Testsuite {
n := len(test.Failures)
- decoded = append(decoded, planr.TestResult {
- Pass: n == 0,
+ decoded = append(decoded, Result{
+ id: suite.Name + "." + test.Name,
+ result: planr.TestResult {
+ Pass: n == 0,
+ },
})
+
}
}