From 72a70b127636ae8a83e2a2bd53b69143e3c5ded0 Mon Sep 17 00:00:00 2001 From: Flu0r1ne Date: Thu, 5 Aug 2021 15:56:10 -0500 Subject: Runtime & reorganziation --- adapters/gtest/templating.go | 84 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 adapters/gtest/templating.go (limited to 'adapters/gtest/templating.go') diff --git a/adapters/gtest/templating.go b/adapters/gtest/templating.go new file mode 100644 index 0000000..a78eaf8 --- /dev/null +++ b/adapters/gtest/templating.go @@ -0,0 +1,84 @@ +package gtest + +import ( + "io" + "log" + "text/template" + "os" +) + +type cmakeUnit struct { + Cname string + File string + Srcs string +}; + +func genCmake(out string, units []cmakeUnit) { + file, err := os.OpenFile(out, os.O_RDWR | os.O_CREATE, 0644) + defer func () { + err := file.Close() + + if err != nil { + log.Fatal(err) + } + }() + + if err != nil { + log.Fatalf("Could not open CMakeFile (%s)\n%v", out, err) + } + + writeBoiler(file) + + tmpl := unitTemplate() + + for _, unit := range units { + if err := tmpl.Execute(file, unit); err != nil { + log.Fatalf("Failed to generate unit %s: %v", unit.Cname, err); + } + } +} + + +func unitTemplate() *template.Template { + tmpl, err := template.New("gtest_unit").Parse(` +add_executable( + {{.Cname}} + {{.File}} + {{.Srcs}} +) + +target_link_libraries( + {{.Cname}} + gtest_main +) + +gtest_discover_tests( + {{.Cname}} +) +`) + + if err != nil { + log.Fatalf("Cannot load Gtest Unit Template %v", err) + } + + return tmpl +} + +func writeBoiler(w io.Writer) { + w.Write([]byte(` +cmake_minimum_required (VERSION 3.1.0) + +project(PlanRGtestAdapter) + +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip +) + +include(GoogleTest) +FetchContent_MakeAvailable(googletest) +`)) +} + + -- cgit v1.2.3