package gtest import ( "log" "os" "path" "os/exec" "golang.flu0r1ne.net/planr" ) const GTEST_CMAKE = "CMakeLists.txt" func safeWd() string{ wd, err := os.Getwd() if err != nil { log.Fatalf("Could not get GtestBuildDir %s %v\n", wd, err) } return wd } type Adapter struct { dirs planr.DirConfig buildDir string } func (a *Adapter) Config() planr.AdapterConfig { return planr.AdapterConfig { Name: "gtest", ParseConfig: ParseConfig, ParseDefaultConfig: ParseDefaultConfig, } } func (a *Adapter) Init(ctx planr.PipelineContext) { a.dirs = ctx.Dirs a.buildDir = ctx.AdapterDir } func (adapter Adapter) Build(tcs []planr.TestCase) { finalizeConfigs(tcs) exes := createExecutables(tcs) cmakeFile := path.Join(adapter.buildDir, GTEST_CMAKE) cmakeUnits := cmakeUnits(exes, adapter.dirs) generateCmakeScript(cmakeFile, cmakeUnits) cmd := exec.Command("cmake", "-S", ".", "-B", ".") cmd.Dir = adapter.buildDir planr.Exec(cmd) cmd = exec.Command("make", "gtest", "gmock") cmd.Dir = adapter.buildDir planr.Exec(cmd) } func (adapter *Adapter) Evaluate(tcs []planr.TestCase) [] planr.TestResult { finalizeConfigs(tcs) results := make([]planr.TestResult, 0) exes := createExecutables(tcs) c := make(chan []planr.TestResult, len(exes)) for i := range exes { go func(exe *executable) { succeed, buildFailures := exe.compile(adapter.buildDir) if ! succeed { c <- buildFailures return } runtimeResults := exe.execute(adapter.buildDir) c <- runtimeResults }(&exes[i]) } for range exes { results = append(results, (<-c)...) } return results } func NewAdapter() *Adapter { return new(Adapter) }