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/config.go | 96 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 adapters/gtest/config.go (limited to 'adapters/gtest/config.go') diff --git a/adapters/gtest/config.go b/adapters/gtest/config.go new file mode 100644 index 0000000..6a6c8bf --- /dev/null +++ b/adapters/gtest/config.go @@ -0,0 +1,96 @@ +package gtest + +import ( + "log" + "golang.flu0r1ne.net/planr" + "strings" + "github.com/BurntSushi/toml" +) + +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 (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 (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 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 +} -- cgit v1.2.3