summaryrefslogtreecommitdiff
path: root/adapters/gtest
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/gtest')
-rw-r--r--adapters/gtest/adapter.go44
-rw-r--r--adapters/gtest/config.go18
2 files changed, 33 insertions, 29 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)
}
diff --git a/adapters/gtest/config.go b/adapters/gtest/config.go
index 457eb64..3305977 100644
--- a/adapters/gtest/config.go
+++ b/adapters/gtest/config.go
@@ -12,7 +12,7 @@ const (
DEFAULT_TIMEOUT = 1000
)
-type GtestDefaults struct {
+type Defaults struct {
Name *string
Suite *string
Testfile *string
@@ -20,8 +20,8 @@ type GtestDefaults struct {
Timeout *uint
}
-func (child *GtestDefaults) Inherit(p interface{}) {
- parent := p.(*GtestDefaults)
+func (child *Defaults) Inherit(p interface{}) {
+ parent := p.(*Defaults)
if(child.Name == nil) { child.Name = parent.Name }
if(child.Suite == nil) { child.Suite = parent.Suite }
@@ -31,11 +31,11 @@ func (child *GtestDefaults) Inherit(p interface{}) {
}
-type GtestConfig struct {
- GtestDefaults
+type Config struct {
+ Defaults
}
-func (g GtestConfig) ensureSatisfied(path string) {
+func (g Config) ensureSatisfied(path string) {
if g.Name == nil {
log.Fatalf("\"name\" is not defined for unit: %s\n", path)
} else if g.Suite == nil {
@@ -50,7 +50,7 @@ func (g GtestConfig) ensureSatisfied(path string) {
}
}
-func (cfg GtestConfig) srcList(srcDir string) string {
+func (cfg Config) srcList(srcDir string) string {
var srcList string
if cfg.Srcs != nil {
@@ -66,7 +66,7 @@ func (cfg GtestConfig) srcList(srcDir string) string {
}
func ParseConfig(prim toml.Primitive) (planr.InheritableConfig, error) {
- config := GtestConfig{}
+ config := Config{}
if err := toml.PrimitiveDecode(prim, &config); err != nil {
return nil, err
@@ -76,7 +76,7 @@ func ParseConfig(prim toml.Primitive) (planr.InheritableConfig, error) {
}
func ParseDefaultConfig(prim toml.Primitive) (planr.InheritableConfig, error) {
- config := GtestDefaults{}
+ config := Defaults{}
if err := toml.PrimitiveDecode(prim, &config); err != nil {
return nil, err