diff options
author | Flu0r1ne <flur01ne@flu0r1ne.net> | 2021-08-05 15:56:10 -0500 |
---|---|---|
committer | Flu0r1ne <flur01ne@flu0r1ne.net> | 2021-08-05 15:56:10 -0500 |
commit | 72a70b127636ae8a83e2a2bd53b69143e3c5ded0 (patch) | |
tree | fdddf5cccdb487d63909f97074d111e67c79ded7 /adapters/gtest_adapter.go | |
parent | f90a14d5d723c5d2b87f2eaa19f441dec33bb9b2 (diff) | |
download | planr-72a70b127636ae8a83e2a2bd53b69143e3c5ded0.tar.xz planr-72a70b127636ae8a83e2a2bd53b69143e3c5ded0.zip |
Runtime & reorganziation
Diffstat (limited to 'adapters/gtest_adapter.go')
-rw-r--r-- | adapters/gtest_adapter.go | 188 |
1 files changed, 0 insertions, 188 deletions
diff --git a/adapters/gtest_adapter.go b/adapters/gtest_adapter.go deleted file mode 100644 index fd06a48..0000000 --- a/adapters/gtest_adapter.go +++ /dev/null @@ -1,188 +0,0 @@ -package adapters - -import ( - "bytes" - "log" - "os" - "path" - "strings" - "text/template" - - "github.com/BurntSushi/toml" - "golang.flu0r1ne.net/planr" -) - -/* - CONFIGURATION -*/ -type GtestDefaults struct { - Name *string - Suite *string - Testfile *string - Test_root *string - Srcs *[]string - Srcs_root *string -} - -func (child *GtestDefaults) Inherit(p interface{}) { - parent := p.(*GtestDefaults) - - 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.Test_root == nil) { child.Test_root = parent.Test_root } - if(child.Srcs == nil) { child.Srcs = parent.Srcs } - if(child.Srcs_root == nil) { child.Srcs_root = parent.Srcs_root } -} - - -type GtestConfig struct { - GtestDefaults -} - - -func (cfg GtestConfig) joinTests(path_ string) string { - if cfg.Test_root == nil { - return planr.JoinConfigDir("tests", path_) - } - - return planr.JoinConfigDir(*cfg.Test_root, path_) -} - -func (cfg GtestConfig) joinSrcs(path_ string) string { - if cfg.Srcs_root == nil { - return planr.JoinConfigDir("../src", path_) - } - - return planr.JoinConfigDir(*cfg.Srcs_root, path_) -} - -func (cfg GtestConfig) srcList() string { - var srcList string - - if cfg.Srcs != nil { - srcs := make([]string, len(*cfg.Srcs)) - for i, src := range *cfg.Srcs { - srcs[i] = cfg.joinSrcs(src) - } - - srcList = strings.Join(srcs, "\n ") - } - - return srcList -} - -func (g GtestConfig) EnsureSatisfied(path string) { - if g.Name == nil { - log.Fatalf("\"name\" is not defined for unit: %s\n", path) - } else if g.Suite == nil { - log.Fatalf("\"suite\" is not defined for unit: %s\n", path) - } else if g.Testfile == nil { - log.Fatalf("\"testfile\" is not defined for unit: %s\n", path) - } -} - -func primitiveDecode(primitive toml.Primitive, config interface{}) { - if err := toml.PrimitiveDecode(primitive, config); err != nil { - log.Fatal(err) - } -} - -func ParseConfig(prim toml.Primitive) planr.InheritableConfig { - config := GtestConfig{} - - primitiveDecode(prim, &config) - - return &config -} - -func ParseDefaultConfig(prim toml.Primitive) planr.InheritableConfig { - config := GtestDefaults{} - - primitiveDecode(prim, &config) - - return &config -} - -/* - BUILD PROCESS -*/ - -type GtestAdapter struct { - unitTmpl *template.Template - cbuf bytes.Buffer -} - -func (a *GtestAdapter) Config() planr.AdapterConfig { - return planr.AdapterConfig { - Name: "gtest", - ParseConfig: ParseConfig, - ParseDefaultConfig: ParseDefaultConfig, - } -} - -func (a *GtestAdapter) InitializeBuild() { - a.unitTmpl = UnitTemplate() - a.cbuf = bytes.Buffer{} - - WriteCMakeBoiler(&a.cbuf) -} - -const GTEST_CMAKE = "CMakeLists.txt" - -func Chdir(dir string) { - if err := os.Chdir(dir); err != nil { - log.Fatal(err) - } -} - -func (a *GtestAdapter) Build(tc planr.TestCase) { - cfg := tc.AdapterConfig("gtest").(*GtestConfig) - cfg.EnsureSatisfied(tc.Path) - - cname := tc.Cname - testfile := cfg.joinTests(*cfg.Testfile) - srcList := cfg.srcList() - - err := a.unitTmpl.Execute(&a.cbuf, struct {Cname, File, Srcs string} { - cname, testfile, srcList, - }) - - if err != nil { - log.Fatal(err) - } -} - -func (a *GtestAdapter) FinalizeBuild() { - dir := a.Config().ConfigDir() - cmakeFile := path.Join(dir, GTEST_CMAKE) - - file, err := os.OpenFile(cmakeFile, 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", cmakeFile, err) - } - - file.Write(a.cbuf.Bytes()) - - Chdir(dir) - - planr.RunCmd("cmake", "-S", ".", "-B", ".") -} - -func (a *GtestAdapter) Make() { - planr.RunCmd("make", "-k") -} - -func (a *GtestAdapter) Evaluate(tc planr.TestCase) planr.TestResult { - return planr.TestResult {} -} - -func (a *GtestAdapter) Cleanup() { } |