summaryrefslogtreecommitdiff
path: root/adapters/gtest/adapter.go
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/gtest/adapter.go')
-rw-r--r--adapters/gtest/adapter.go44
1 files changed, 24 insertions, 20 deletions
diff --git a/adapters/gtest/adapter.go b/adapters/gtest/adapter.go
index 0a955ef..7033c7f 100644
--- a/adapters/gtest/adapter.go
+++ b/adapters/gtest/adapter.go
@@ -16,8 +16,8 @@ import (
const GTEST_CMAKE = "CMakeLists.txt"
-func makeUnit(tc *planr.TestCase, dirs planr.DirConfig) cmakeUnit {
- cfg := tc.AdapterConfig().(*GtestConfig)
+func makeUnit(tc planr.TestCase, dirs planr.DirConfig) cmakeUnit {
+ cfg := tc.AdapterConfig().(*Config)
testpath := path.Join(dirs.Tests(), *cfg.Testfile)
srclist := cfg.srcList(dirs.Src())
@@ -41,7 +41,7 @@ func safeWd() string{
type ResultFromId map[string] Result
-func (adapter *GtestAdapter) execTests(cnames []string) ResultFromId {
+func (adapter *Adapter) execTests(cnames []string) ResultFromId {
buildDir := safeWd()
lut := make(ResultFromId, 0)
@@ -89,7 +89,7 @@ func (adapter *GtestAdapter) execTests(cnames []string) ResultFromId {
// An executable may contain more than one test
// Gather all executables and deduplicate them
-func exes(tcs []*planr.TestCase) []string {
+func exes(tcs []planr.TestCase) []string {
set := make(map[string] bool, 0)
for _, tc := range tcs {
@@ -112,12 +112,12 @@ func exes(tcs []*planr.TestCase) []string {
return exes
}
-func id(tc *planr.TestCase) string {
- cfg := tc.AdapterConfig().(*GtestConfig)
+func id(tc planr.TestCase) string {
+ cfg := tc.AdapterConfig().(*Config)
return tc.Cname + "." + *cfg.Suite + "." + *cfg.Name
}
-func compile(wg * sync.WaitGroup, tc *planr.TestCase) {
+func compile(wg * sync.WaitGroup, tc * planr.TestCase) {
defer wg.Done()
cmd := exec.Command("make", tc.Cname)
@@ -137,11 +137,11 @@ func compile(wg * sync.WaitGroup, tc *planr.TestCase) {
tc.Result.DebugOutput = string(out)
}
-type GtestAdapter struct {
+type Adapter struct {
dirs planr.DirConfig
}
-func (a *GtestAdapter) Config() planr.AdapterConfig {
+func (a *Adapter) Config() planr.AdapterConfig {
return planr.AdapterConfig {
Name: "gtest",
ParseConfig: ParseConfig,
@@ -149,18 +149,18 @@ func (a *GtestAdapter) Config() planr.AdapterConfig {
}
}
-func (a *GtestAdapter) Init(dirs planr.DirConfig) {
+func (a *Adapter) Init(dirs planr.DirConfig) {
a.dirs = dirs
}
-func (adapter *GtestAdapter) Build(tcs []*planr.TestCase) {
+func (adapter Adapter) Build(tcs []planr.TestCase) {
buildDir := safeWd()
cmakeFile := path.Join(buildDir, GTEST_CMAKE)
units := make([]cmakeUnit, 0)
for _, tc := range tcs {
- cfg := tc.AdapterConfig().(*GtestConfig)
+ cfg := tc.AdapterConfig().(*Config)
cfg.ensureSatisfied(tc.Path)
units = append(units, makeUnit(tc, adapter.dirs))
@@ -172,9 +172,10 @@ func (adapter *GtestAdapter) Build(tcs []*planr.TestCase) {
}
// ./planr eval 0.93s user 0.16s system 100% cpu 1.089 total
-func (adapter *GtestAdapter) Evaluate(tcs []*planr.TestCase) {
+func (adapter *Adapter) Evaluate(tcs []planr.TestCase) [] planr.TestCase {
var wg sync.WaitGroup
- for _, tc := range tcs {
+ for i := range tcs {
+ tc := &tcs[i]
wg.Add(1)
go compile(&wg, tc)
}
@@ -183,14 +184,15 @@ func (adapter *GtestAdapter) Evaluate(tcs []*planr.TestCase) {
files := exes(tcs)
resultById := adapter.execTests(files)
- for _, tc := range tcs {
- result, ok := resultById[id(tc)]
+ for i := range tcs {
+ tc := &tcs[i]
+ result, ok := resultById[id(*tc)]
// compilation failure
if !ok {
if tc.Result.Status == planr.PASSING {
- cfg := tc.AdapterConfig().(*GtestConfig)
+ cfg := tc.AdapterConfig().(*Config)
log.Printf(
"Could not find testcase %s with name=\"%s\" and suite=\"%s\". Does such a test exist in the test source?",
@@ -200,7 +202,7 @@ func (adapter *GtestAdapter) Evaluate(tcs []*planr.TestCase) {
)
tc.Result.Status = planr.COMPILATION_FAILURE
- tc.Result.DebugOutput += fmt.Sprintf("planr: Did not find testcase %s in any test executable\n", id(tc))
+ tc.Result.DebugOutput += fmt.Sprintf("planr: Did not find testcase %s in any test executable\n", id(*tc))
}
continue
@@ -212,8 +214,10 @@ func (adapter *GtestAdapter) Evaluate(tcs []*planr.TestCase) {
tc.Result.TestOutput = result.testOutput
}
+
+ return tcs
}
-func New() *GtestAdapter {
- return new(GtestAdapter)
+func NewAdapter() *Adapter {
+ return new(Adapter)
}