Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions parser/gotest/gotest.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,21 @@ func SetSubtestMode(mode SubtestMode) Option {
}
}

// AssumeNoBuildOutput is an Option disables "build_output" event parsing. This
// option is most useful when running tests that are known to build correctly,
// or have already been built (e.g. via go test -c, or an alternative build
// system).
func AssumeNoBuildOutput() Option {
return func(p *Parser) {
p.assumeNoBuildOutput = true
}
}

// Parser is a Go test output Parser.
type Parser struct {
packageName string
subtestMode SubtestMode
packageName string
subtestMode SubtestMode
assumeNoBuildOutput bool

timestampFunc func() time.Time

Expand Down Expand Up @@ -208,7 +219,7 @@ func (p *Parser) parseLine(line string) (events []Event) {
return p.benchSummary(matches[1], matches[2], matches[3], matches[4], matches[5], matches[6])
} else if matches := regexEndBenchmark.FindStringSubmatch(line); len(matches) == 3 {
return p.endBench(matches[1], matches[2])
} else if strings.HasPrefix(line, "# ") {
} else if !p.assumeNoBuildOutput && strings.HasPrefix(line, "# ") {
fields := strings.Fields(strings.TrimPrefix(line, "# "))
if len(fields) == 1 || len(fields) == 2 {
return p.buildOutput(fields[0])
Expand Down
37 changes: 37 additions & 0 deletions parser/gotest/gotest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,40 @@ func TestParseLine(t *testing.T) {
})
}
}

func TestParseLine_AssumeNoBuildOutput(t *testing.T) {
tests := []parseLineTest{
{
"# package/name/failing1",
[]Event{{Type: "output", Data: "# package/name/failing1"}},
},
{
"# package/name/failing2 [package/name/failing2.test]",
[]Event{{Type: "output", Data: "# package/name/failing2 [package/name/failing2.test]"}},
},
}

// Include all the other tests that don't produce build_output as well, they
// should continue functioning normally.
Outer:
for _, test := range parseLineTests {
for _, event := range test.events {
if event.Type == "build_output" {
continue Outer
}
}

tests = append(tests, test)
}

for i, test := range tests {
name := fmt.Sprintf("%d-%s", i, test.Name())
t.Run(name, func(t *testing.T) {
parser := NewParser(AssumeNoBuildOutput())
events := parser.parseLine(test.input)
if diff := cmp.Diff(test.events, events); diff != "" {
t.Errorf("parseLine(%q) returned unexpected events, diff (-want, +got):\n%v", test.input, diff)
}
})
}
}