summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlu0r1ne <flur01ne@flu0r1ne.net>2021-09-05 01:00:12 -0500
committerFlu0r1ne <flur01ne@flu0r1ne.net>2021-09-05 01:00:12 -0500
commit4cc29e50d59daf445f4152d10f9f41cb1828f702 (patch)
tree2726dc5648c574213fdadf22349017be73690bd2
parent151d516e68f5d43aa2d0c5ff462752d640b6a614 (diff)
downloaddeb-planr-4cc29e50d59daf445f4152d10f9f41cb1828f702.tar.xz
deb-planr-4cc29e50d59daf445f4152d10f9f41cb1828f702.zip
Remove pointers and cleanup templating, add version info
-rw-r--r--adapters/gtest/config.go27
-rw-r--r--adapters/gtest/executable.go15
-rw-r--r--adapters/gtest/templating.go41
3 files changed, 54 insertions, 29 deletions
diff --git a/adapters/gtest/config.go b/adapters/gtest/config.go
index 04d426c..533f266 100644
--- a/adapters/gtest/config.go
+++ b/adapters/gtest/config.go
@@ -13,21 +13,21 @@ const (
)
type Defaults struct {
- Name *string
- Suite *string
- Testfile *string
+ Name string
+ Suite string
+ Testfile string
Srcs []string
- Timeout *uint
+ Timeout uint
}
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 }
- if(child.Testfile == nil) { child.Testfile = parent.Testfile }
+ if(child.Name == "") { child.Name = parent.Name }
+ if(child.Suite == "") { child.Suite = parent.Suite }
+ if(child.Testfile == "") { child.Testfile = parent.Testfile }
if(len(child.Srcs) == 0) { child.Srcs = parent.Srcs }
- if(child.Timeout == nil) { child.Timeout = parent.Timeout }
+ if(child.Timeout == 0) { child.Timeout = parent.Timeout }
}
@@ -36,17 +36,16 @@ type Config struct {
}
func (c * Config) finalize(path string) {
- if c.Name == nil {
+ if c.Name == "" {
log.Fatalf("\"name\" is not defined for unit: %s\n", path)
- } else if c.Suite == nil {
+ } else if c.Suite == "" {
log.Fatalf("\"suite\" is not defined for unit: %s\n", path)
- } else if c.Testfile == nil {
+ } else if c.Testfile == "" {
log.Fatalf("\"testfile\" is not defined for unit: %s\n", path)
}
- if c.Timeout == nil {
- c.Timeout = new(uint)
- *c.Timeout = DEFAULT_TIMEOUT;
+ if c.Timeout == 0 {
+ c.Timeout = DEFAULT_TIMEOUT;
}
}
diff --git a/adapters/gtest/executable.go b/adapters/gtest/executable.go
index 78b0b56..25c83c1 100644
--- a/adapters/gtest/executable.go
+++ b/adapters/gtest/executable.go
@@ -27,7 +27,7 @@ func createExecutables(tcs []planr.TestCase) []executable {
for _, tc := range tcs {
cfg := tc.AdapterConfig().(*Config)
- file := *cfg.Testfile
+ file := cfg.Testfile
exe, contained := exes[file]
// For set comparison
@@ -55,7 +55,7 @@ func createExecutables(tcs []planr.TestCase) []executable {
if !reflect.DeepEqual(exe.srcs, cfg.Srcs) {
log.Fatalf(
"Two test case definitions %s and %s have different lists of sources",
- exe.testpath, *cfg.Testfile,
+ exe.testpath, cfg.Testfile,
)
}
@@ -119,12 +119,12 @@ func runGtest(exe string, tc planr.TestCase, builddir string) planr.TestResult {
log.Fatal(err)
}
- timeout := time.Duration(*cfg.Timeout) * time.Millisecond
+ timeout := time.Duration(cfg.Timeout) * time.Millisecond
ctx, cancel := context.WithTimeout(context.Background(), timeout)
jsonFlag := "--gtest_output=json:" + f.Name()
- testFlag := "--gtest_filter=" + *cfg.Suite + "." + *cfg.Name
+ testFlag := "--gtest_filter=" + cfg.Suite + "." + cfg.Name
cmd := exec.CommandContext(ctx, exePath, jsonFlag, testFlag)
@@ -151,14 +151,13 @@ func runGtest(exe string, tc planr.TestCase, builddir string) planr.TestResult {
log.Fatalf(
"Could not find testcase %s with name=\"%s\" and suite=\"%s\". Does such a test exist in the test source?",
tc.Cname,
- *cfg.Name,
- *cfg.Suite,
+ cfg.Name,
+ cfg.Suite,
)
}
- // TODO: Cleanup -- ZERO TESTS?
if len(results) > 1 {
- log.Fatalf("Unexpected number of results")
+ log.Fatalf("Unexpected number of results, filter should have produced one result")
}
decodeResult := results[0]
diff --git a/adapters/gtest/templating.go b/adapters/gtest/templating.go
index 57532fa..41c54c1 100644
--- a/adapters/gtest/templating.go
+++ b/adapters/gtest/templating.go
@@ -3,8 +3,9 @@ package gtest
import (
"io"
"log"
- "text/template"
"os"
+ "golang.flu0r1ne.net/planr"
+ "text/template"
)
type cmakeUnit struct {
@@ -27,7 +28,7 @@ func generateCmakeScript(out string, units []cmakeUnit) {
log.Fatalf("Could not open CMakeFile (%s)\n%v", out, err)
}
- writeBoiler(file)
+ writeCmakeBoilerplate(file)
tmpl := unitTemplate()
@@ -43,6 +44,10 @@ func generateCmakeScript(out string, units []cmakeUnit) {
func unitTemplate() *template.Template {
tmpl, err := template.New("gtest_unit").Parse(`
+################################################
+
+## {{.ExeNm}}
+
add_executable(
"{{.ExeNm}}"
"{{.File}}"
@@ -60,14 +65,30 @@ gtest_discover_tests(
`)
if err != nil {
- log.Fatalf("Cannot load Gtest Unit Template %v", err)
+ log.Fatalf("Cannot load Gtest unit template %v", err)
}
return tmpl
}
-func writeBoiler(w io.Writer) {
- w.Write([]byte(`
+const GOOGLE_TEST_URL = "https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip"
+
+func writeCmakeBoilerplate(w io.Writer) {
+ tmpl := boilderTemplate()
+
+ tmpl.Execute(w, struct {
+ Url string
+ Version string
+ }{
+ Url: GOOGLE_TEST_URL,
+ Version: planr.VERSION,
+ })
+}
+
+func boilderTemplate() *template.Template {
+ tmpl, err := template.New("gtest_boilerplate").Parse(`
+# AUTOMATICALLY GENERATED BY PLANR VERSION {{.Version}}
+
cmake_minimum_required (VERSION 3.1.0)
project(PlanRGtestAdapter)
@@ -75,10 +96,16 @@ project(PlanRGtestAdapter)
include(FetchContent)
FetchContent_Declare(
googletest
- URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
+ URL {{.Url}}
)
include(GoogleTest)
FetchContent_MakeAvailable(googletest)
-`))
+`)
+
+ if err != nil {
+ log.Fatalf("Cannot load Gtest Cmake boilerplate")
+ }
+
+ return tmpl
}