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.go77
1 files changed, 47 insertions, 30 deletions
diff --git a/adapters/gtest/adapter.go b/adapters/gtest/adapter.go
index f4fde27..9331cf7 100644
--- a/adapters/gtest/adapter.go
+++ b/adapters/gtest/adapter.go
@@ -11,55 +11,38 @@ import (
"path"
"sync"
"time"
-
"golang.flu0r1ne.net/planr"
)
const GTEST_CMAKE = "CMakeLists.txt"
-func mkUnit(tc *planr.TestCase) cmakeUnit {
+func makeUnit(tc *planr.TestCase, dirs planr.DirConfig) cmakeUnit {
cfg := tc.AdapterConfig().(*GtestConfig)
+ testpath := path.Join(dirs.TestsDir(), *cfg.Testfile)
+ srclist := cfg.srcList(dirs.SrcDir())
+
return cmakeUnit {
tc.Cname,
- cfg.joinTests(*cfg.Testfile),
- cfg.srcList(),
+ testpath,
+ srclist,
};
}
+func safeWd() string{
+ wd, err := os.Getwd()
-type GtestAdapter struct {}
-
-func (a *GtestAdapter) Config() planr.AdapterConfig {
- return planr.AdapterConfig {
- Name: "gtest",
- ParseConfig: ParseConfig,
- ParseDefaultConfig: ParseDefaultConfig,
- }
-}
-
-func (adapter *GtestAdapter) Build(tcs []*planr.TestCase) {
- buildDir := adapter.Config().Dir()
- cmakeFile := path.Join(buildDir, GTEST_CMAKE)
-
- units := make([]cmakeUnit, 0)
- for _, tc := range tcs {
-
- cfg := tc.AdapterConfig().(*GtestConfig)
- cfg.ensureSatisfied(tc.Path)
-
- units = append(units, mkUnit(tc))
+ if err != nil {
+ log.Fatalf("Could not get GtestBuildDir %s %v\n", wd, err)
}
- genCmake(cmakeFile, units)
-
- planr.RunCmd("cmake", "-S", ".", "-B", ".")
+ return wd
}
type ResultFromId map[string] Result
func (adapter *GtestAdapter) execTests(cnames []string) ResultFromId {
- buildDir := adapter.Config().Dir()
+ buildDir := safeWd()
lut := make(ResultFromId, 0)
for _, exe := range cnames {
@@ -154,6 +137,40 @@ func compile(wg * sync.WaitGroup, tc *planr.TestCase) {
tc.Result.DebugOutput = string(out)
}
+type GtestAdapter struct {
+ dirs planr.DirConfig
+}
+
+func (a *GtestAdapter) Config() planr.AdapterConfig {
+ return planr.AdapterConfig {
+ Name: "gtest",
+ ParseConfig: ParseConfig,
+ ParseDefaultConfig: ParseDefaultConfig,
+ }
+}
+
+func (a *GtestAdapter) Init(dirs planr.DirConfig) {
+ a.dirs = dirs
+}
+
+func (adapter *GtestAdapter) 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.ensureSatisfied(tc.Path)
+
+ units = append(units, makeUnit(tc, adapter.dirs))
+ }
+
+ genCmake(cmakeFile, units)
+
+ planr.RunCmd("cmake", "-S", ".", "-B", ".")
+}
+
// ./planr eval 0.93s user 0.16s system 100% cpu 1.089 total
func (adapter *GtestAdapter) Evaluate(tcs []*planr.TestCase) {
var wg sync.WaitGroup
@@ -169,7 +186,7 @@ func (adapter *GtestAdapter) Evaluate(tcs []*planr.TestCase) {
for _, tc := range tcs {
result, ok := resultById[id(tc)]
- // compilation failure
+ // compilation failure
if !ok {
fmt.Printf("CAN'T FIND %s: status %d\n", tc.Cname, tc.Result.Status)