summaryrefslogtreecommitdiff
path: root/adapters/gtest/templating.go
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/gtest/templating.go')
-rw-r--r--adapters/gtest/templating.go41
1 files changed, 34 insertions, 7 deletions
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
}