From 3337257fe24b67871406217e98862d34647dd725 Mon Sep 17 00:00:00 2001 From: Flu0r1ne Date: Fri, 13 Aug 2021 16:31:04 -0500 Subject: Add colorized output and build traces --- adapters/gtest/adapter.go | 58 +++++++++++++++++++++++++++++++++++------------ adapters/gtest/results.go | 29 ++++++++++++++++-------- 2 files changed, 63 insertions(+), 24 deletions(-) (limited to 'adapters') diff --git a/adapters/gtest/adapter.go b/adapters/gtest/adapter.go index 600c956..3d769e3 100644 --- a/adapters/gtest/adapter.go +++ b/adapters/gtest/adapter.go @@ -2,14 +2,15 @@ package gtest import ( "context" + "errors" "fmt" "io/ioutil" "log" "os" "os/exec" - "time" "path" - "errors" + "time" + "golang.flu0r1ne.net/planr" ) @@ -61,7 +62,7 @@ func (adapter *GtestAdapter) Build(tcs []*planr.TestCase) { planr.RunCmd("cmake", "-S", ".", "-B", ".") } -type ResultFromId map[string] planr.TestResult +type ResultFromId map[string] Result func (adapter *GtestAdapter) execTests(cnames []string) ResultFromId { buildDir := adapter.Config().Dir() @@ -84,34 +85,35 @@ func (adapter *GtestAdapter) execTests(cnames []string) ResultFromId { defer cancel() defer os.Remove(f.Name()) - exitFail := false if err := cmd.Run(); err != nil { var exiterr *exec.ExitError - if errors.As(err, &exiterr) && exiterr.ExitCode() == 1{ - exitFail = true - } else { + if !errors.As(err, &exiterr) { log.Printf("%v\n", err) os.Exit(exiterr.ExitCode()) } } - if exitFail { - fmt.Printf("") - } - for _, r := range decodeResults(f) { - lut[exe + "." + r.id] = r.result + lut[exe + "." + r.id] = r } } return lut } +// An executable may contain more than one test +// Gather all executables and deduplicate them func exes(tcs []*planr.TestCase) []string { set := make(map[string] bool, 0) for _, tc := range tcs { + // Tests which have encountered a failure + // may not have an executable + if tc.Result.Status != planr.PASSING { + continue + } + if(!set[tc.Cname]) { set[tc.Cname] = true } @@ -134,13 +136,39 @@ func (adapter *GtestAdapter) Evaluate(tcs []*planr.TestCase) { buildDir := adapter.Config().Dir() chdir(buildDir) - planr.RunCmd("make", "-k") + for _, tc := range tcs { + cmd := exec.Command("make", tc.Cname) + out, err := cmd.CombinedOutput() + tc.Result = new(planr.TestResult) + + // Don't treat command failure as anything but a build failure + if err != nil{ + var exiterr *exec.ExitError + if errors.As(err, &exiterr) && exiterr.ExitCode() == 0 { + log.Fatal(err) + } + + tc.Result.Status = planr.COMPILATION_FAILURE + } + + tc.Result.DebugOutput = string(out) + } files := exes(tcs) resultById := adapter.execTests(files) for _, tc := range tcs { - result := resultById[id(tc)] - tc.Result = &result + result, ok := resultById[id(tc)] + + // compilation failure + if !ok { + continue + } + + if !result.pass { + tc.Result.Status = planr.RUNTIME_FAILURE + } + + tc.Result.FailureMsg = result.failureMsg } } diff --git a/adapters/gtest/results.go b/adapters/gtest/results.go index 88e4069..c556749 100644 --- a/adapters/gtest/results.go +++ b/adapters/gtest/results.go @@ -6,8 +6,6 @@ import ( "io" "log" "time" - - "golang.flu0r1ne.net/planr" ) type gFailure struct { @@ -48,8 +46,19 @@ type gResults struct { } type Result struct { - id string - result planr.TestResult + id string + pass bool + failureMsg string +} + +func failureMsg(failures []gFailure) string { + failure_msg := "" + + for _, failure := range failures { + failure_msg += failure.Failure + } + + return failure_msg } func decodeResults(r io.Reader) []Result { @@ -69,13 +78,15 @@ func decodeResults(r io.Reader) []Result { for _, test := range suite.Testsuite { n := len(test.Failures) - decoded = append(decoded, Result{ + + res := Result { id: suite.Name + "." + test.Name, - result: planr.TestResult { - Pass: n == 0, - }, - }) + pass: n == 0, + failureMsg: failureMsg(test.Failures), + } + + decoded = append(decoded, res) } } -- cgit v1.2.3