aboutsummaryrefslogtreecommitdiff
path: root/adapters/gtest/adapter.go
diff options
context:
space:
mode:
authorFlu0r1ne <flur01ne@flu0r1ne.net>2021-08-05 18:41:53 -0500
committerFlu0r1ne <flur01ne@flu0r1ne.net>2021-08-05 18:41:53 -0500
commitcbc5fbdf941cd40dc6a9546fb924689f5d6978c7 (patch)
tree734bfa515ddeab208c35c50624cfd9f1124ce6cf /adapters/gtest/adapter.go
parent05ce22f9d2308bca51b48fb60558d17f2e381227 (diff)
downloadplanr-cbc5fbdf941cd40dc6a9546fb924689f5d6978c7.tar.xz
planr-cbc5fbdf941cd40dc6a9546fb924689f5d6978c7.zip
Improvised a basic text report, finished evaluation mappings
Diffstat (limited to 'adapters/gtest/adapter.go')
-rw-r--r--adapters/gtest/adapter.go64
1 files changed, 52 insertions, 12 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
+ }
}