Skip to content

Commit

Permalink
tools test
Browse files Browse the repository at this point in the history
  • Loading branch information
smarterclayton committed Oct 13, 2017
1 parent fc0ac72 commit bcb4e0e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
4 changes: 4 additions & 0 deletions tools/junitreport/junitreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"flag"
"fmt"
"io"
"net/http"
_ "net/http/pprof"
"os"
"strings"

Expand Down Expand Up @@ -99,6 +101,8 @@ func main() {
os.Exit(2)
}

go http.ListenAndServe("127.0.0.1:6060", nil)

flag.Parse()

var rootSuiteNames []string
Expand Down
35 changes: 27 additions & 8 deletions tools/junitreport/pkg/parser/gotest/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gotest
import (
"bufio"
"fmt"
"strings"

"github.com/openshift/origin/tools/junitreport/pkg/api"
"github.com/openshift/origin/tools/junitreport/pkg/builder"
Expand Down Expand Up @@ -41,6 +42,8 @@ func (p *testOutputParser) Parse(input *bufio.Scanner) (*api.TestSuites, error)

var currentTestName []string
var tests map[string]*api.TestCase
var output map[string][]string
var messages map[string][]string
var currentSuite *api.TestSuite
var state int
var count int
Expand All @@ -67,6 +70,9 @@ func (p *testOutputParser) Parse(input *bufio.Scanner) (*api.TestSuites, error)

currentSuite = &api.TestSuite{}
tests = make(map[string]*api.TestCase)
output = make(map[string][]string)
messages = make(map[string][]string)

orderedTests = []string{name}
currentTestName = []string{name}
tests[currentTestName[0]] = &api.TestCase{
Expand All @@ -92,7 +98,7 @@ func (p *testOutputParser) Parse(input *bufio.Scanner) (*api.TestSuites, error)
}

// transition to result mode ONLY if it matches a result at the top level
if result, name, depth, duration, ok := ExtractResult(line); ok && depth == 0 {
if result, name, depth, duration, ok := ExtractResult(line); ok && tests[name] != nil && depth == 0 {
test := tests[name]
log(" found result %s %s %s\n", result, name, duration)
switch result {
Expand All @@ -113,7 +119,7 @@ func (p *testOutputParser) Parse(input *bufio.Scanner) (*api.TestSuites, error)
// in output mode, turn output lines into output on the particular test
if _, _, ok := ExtractOutput(line); ok {
log(" found output\n")
tests[currentTestName[0]].SystemOut += line + "\n"
output[currentTestName[0]] = append(output[currentTestName[0]], line)
continue
}
log(" fallthrough\n")
Expand Down Expand Up @@ -189,12 +195,13 @@ func (p *testOutputParser) Parse(input *bufio.Scanner) (*api.TestSuites, error)
depth = len(currentTestName)
}
name := currentTestName[depth-1]
test := tests[name]
switch {
case test.FailureOutput != nil:
test.FailureOutput.Output += output + "\n"
case test.SkipMessage != nil:
test.FailureOutput.Output += output + "\n"
if test, ok := tests[name]; ok {
switch {
case test.FailureOutput != nil:
messages[name] = append(messages[name], output)
case test.SkipMessage != nil:
messages[name] = append(messages[name], output)
}
}

case stateComplete:
Expand All @@ -208,6 +215,18 @@ func (p *testOutputParser) Parse(input *bufio.Scanner) (*api.TestSuites, error)
}
for _, name := range orderedTests {
test := tests[name]
messageLines := messages[name]
var extraOutput []string
for i, s := range messageLines {
if s == "=== OUTPUT" {
messageLines = messageLines[:i]
extraOutput = messageLines[i+1:]
}
}

lines := append(output[name], extraOutput...)
test.SystemOut = strings.Join(lines, "\n")

currentSuite.AddTestCase(test)
}
if err := currentSuite.SetDuration(duration); err != nil {
Expand Down

0 comments on commit bcb4e0e

Please sign in to comment.