Skip to content

Commit

Permalink
POC: Unmix convey reports when t.Parallel() is set.
Browse files Browse the repository at this point in the history
The basic problem is that Convey()'s id reporting isn't using t.Logf.
See golang/go#19280 (comment)

Ref: smartystreets#541
  • Loading branch information
pprabhu committed Oct 26, 2018
1 parent ef6db91 commit 46322d8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion convey/context.go
Expand Up @@ -93,7 +93,7 @@ func rootConvey(items ...interface{}) {

expectChildRun := true
ctx := &context{
reporter: buildReporter(),
reporter: buildReporter(entry.Test),

children: make(map[string]*context),

Expand Down
1 change: 1 addition & 0 deletions convey/discovery.go
Expand Up @@ -98,6 +98,7 @@ func parseSpecifier(items []interface{}) (actionSpecifier, []interface{}) {
// having to import the "testing" package.
type t interface {
Fail()
Logf(format string, args ...interface{})
}

const parseError = "You must provide a name (string), then a *testing.T (if in outermost scope), an optional FailureMode, and then an action (func())."
4 changes: 2 additions & 2 deletions convey/init.go
Expand Up @@ -33,7 +33,7 @@ func noStoryFlagProvided() bool {
return !story && !storyDisabled
}

func buildReporter() reporting.Reporter {
func buildReporter(test t) reporting.Reporter {
selectReporter := os.Getenv("GOCONVEY_REPORTER")

switch {
Expand All @@ -47,7 +47,7 @@ func buildReporter() reporting.Reporter {
// Story is turned on when verbose is set, so we need to check for dot reporter first.
return reporting.BuildDotReporter()
case story || selectReporter == "story":
return reporting.BuildStoryReporter()
return reporting.BuildStoryReporter(test)
default:
return reporting.BuildDotReporter()
}
Expand Down
13 changes: 13 additions & 0 deletions convey/reporting/console.go
Expand Up @@ -14,3 +14,16 @@ func (self *console) Write(p []byte) (n int, err error) {
func NewConsole() io.Writer {
return new(console)
}

type testConsole struct {
test t
}

func (self *testConsole) Write(p []byte) (n int, err error) {
self.test.Logf("%s", string(p))
return 0, nil
}

func NewTestConsole(test t) io.Writer {
return &testConsole{test}
}
8 changes: 6 additions & 2 deletions convey/reporting/init.go
Expand Up @@ -6,6 +6,10 @@ import (
"strings"
)

type t interface {
Logf(format string, args ...interface{})
}

func init() {
if !isColorableTerminal() {
monochrome()
Expand All @@ -30,8 +34,8 @@ func BuildDotReporter() Reporter {
NewProblemReporter(out),
consoleStatistics)
}
func BuildStoryReporter() Reporter {
out := NewPrinter(NewConsole())
func BuildStoryReporter(test t) Reporter {
out := NewPrinter(NewTestConsole(test))
return NewReporters(
NewGoTestReporter(),
NewStoryReporter(out),
Expand Down

0 comments on commit 46322d8

Please sign in to comment.