Skip to content

Commit

Permalink
handle panic
Browse files Browse the repository at this point in the history
  • Loading branch information
Sasidhar Chennamsetty committed Nov 6, 2019
1 parent 82d6533 commit d009767
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"encoding/json"
"io"
"path"
"path/filepath"
"regexp"
"strings"
"time"
)

Expand All @@ -14,8 +16,8 @@ type Result int

// Test result constants
const (
FAIL Result = iota
PASS
PASS Result = iota
FAIL
SKIP
)

Expand Down Expand Up @@ -84,6 +86,9 @@ func Parse(r io.Reader, pkgName string) (*Report, error) {

var cur *Test

var currentTest string
var currentSuite string

// parse lines
for {
l, _, err := reader.ReadLine()
Expand All @@ -95,6 +100,37 @@ func Parse(r io.Reader, pkgName string) (*Report, error) {

line := string(l)

if strings.HasPrefix(line, "=== RUN ") {
fullTestPath := strings.TrimSpace(line[8:])
currentTest = filepath.Base(fullTestPath)
currentSuite = filepath.Base(filepath.Dir(fullTestPath))
}

if strings.Contains(line, "test timed out after") {
for suite, testmap := range suites {
var finalTests []*Test
var suiteTime = time.Duration(0)
for _, testinfo := range testmap {
finalTests = append(finalTests, testinfo)
suiteTime += testinfo.Duration
}
if filepath.Base(suite) == currentSuite {
t := &Test{
Name: currentTest,
Result: FAIL,
}
finalTests = append(finalTests, t)
}
report.Packages = append(report.Packages, Package{
Name: suite,
Duration: suiteTime,
Time: int(suiteTime / time.Millisecond),
Tests: finalTests,
})
}
return report, nil
}

type Info struct {
Suite string
Test string
Expand Down

0 comments on commit d009767

Please sign in to comment.