diff --git a/fmt_progress_test.go b/fmt_progress_test.go index 53780be..690d7a7 100644 --- a/fmt_progress_test.go +++ b/fmt_progress_test.go @@ -82,7 +82,8 @@ func FeatureContext(s *godog.Suite) { ` - require.True(t, r.run()) + failed := r.concurrent(1, func() Formatter { return progressFunc("progress", w) }) + require.True(t, failed) actual := buf.String() assert.Equal(t, expected, actual) @@ -107,10 +108,11 @@ func TestProgressFormatterWhenStepPanics(t *testing.T) { }, } - require.True(t, r.run()) + failed := r.concurrent(1, func() Formatter { return progressFunc("progress", w) }) + require.True(t, failed) actual := buf.String() - assert.Contains(t, actual, "godog/fmt_progress_test.go:106") + assert.Contains(t, actual, "godog/fmt_progress_test.go:107") } func TestProgressFormatterWithPassingMultisteps(t *testing.T) { @@ -135,7 +137,8 @@ func TestProgressFormatterWithPassingMultisteps(t *testing.T) { }, } - assert.False(t, r.run()) + failed := r.concurrent(1, func() Formatter { return progressFunc("progress", w) }) + require.False(t, failed) } func TestProgressFormatterWithFailingMultisteps(t *testing.T) { @@ -160,7 +163,8 @@ func TestProgressFormatterWithFailingMultisteps(t *testing.T) { }, } - require.True(t, r.run()) + failed := r.concurrent(1, func() Formatter { return progressFunc("progress", w) }) + require.True(t, failed) expected := `.F 2 @@ -202,7 +206,8 @@ func TestProgressFormatterWithPanicInMultistep(t *testing.T) { }, } - assert.True(t, r.run()) + failed := r.concurrent(1, func() Formatter { return progressFunc("progress", w) }) + require.True(t, failed) } func TestProgressFormatterMultistepTemplates(t *testing.T) { @@ -226,7 +231,8 @@ func TestProgressFormatterMultistepTemplates(t *testing.T) { }, } - require.False(t, r.run()) + failed := r.concurrent(1, func() Formatter { return progressFunc("progress", w) }) + require.False(t, failed) expected := `.U 2 @@ -291,7 +297,8 @@ Feature: basic }, } - assert.False(t, r.run()) + failed := r.concurrent(1, func() Formatter { return progressFunc("progress", w) }) + require.False(t, failed) } func TestProgressFormatterWhenMultiStepHasStepWithArgument(t *testing.T) { @@ -326,7 +333,8 @@ Feature: basic }, } - require.True(t, r.run()) + failed := r.concurrent(1, func() Formatter { return progressFunc("progress", w) }) + require.True(t, failed) expected := `.F 2 diff --git a/run.go b/run.go index 874c684..f50851b 100644 --- a/run.go +++ b/run.go @@ -110,23 +110,6 @@ func (r *runner) concurrent(rate int, formatterFn func() Formatter) (failed bool return } -func (r *runner) run() bool { - suite := &Suite{ - fmt: r.fmt, - randomSeed: r.randomSeed, - stopOnFailure: r.stopOnFailure, - strict: r.strict, - features: r.features, - } - r.initializer(suite) - - r.fmt.TestRunStarted() - suite.run() - r.fmt.Summary() - - return suite.failed -} - // RunWithOptions is same as Run function, except // it uses Options provided in order to run the // test suite without parsing flags @@ -169,10 +152,10 @@ func RunWithOptions(suite string, contextInitializer func(suite *Suite), opt Opt } } - if opt.Concurrency > 1 && !supportsConcurrency(opt.Format) { - fmt.Fprintln(os.Stderr, fmt.Errorf("format \"%s\" does not support concurrent execution", opt.Format)) - return exitOptionError + if opt.Concurrency < 1 { + opt.Concurrency = 1 } + formatter := FindFmt(opt.Format) if nil == formatter { var names []string @@ -214,12 +197,7 @@ func RunWithOptions(suite string, contextInitializer func(suite *Suite), opt Opt _, filename, _, _ := runtime.Caller(1) os.Setenv("GODOG_TESTED_PACKAGE", runsFromPackage(filename)) - var failed bool - if opt.Concurrency > 1 { - failed = r.concurrent(opt.Concurrency, func() Formatter { return formatter(suite, output) }) - } else { - failed = r.run() - } + failed := r.concurrent(opt.Concurrency, func() Formatter { return formatter(suite, output) }) // @TODO: should prevent from having these os.Setenv("GODOG_SEED", "") @@ -275,18 +253,3 @@ func Run(suite string, contextInitializer func(suite *Suite)) int { return RunWithOptions(suite, contextInitializer, opt) } - -func supportsConcurrency(format string) bool { - switch format { - case "progress", "junit": - return true - case "events": - return true - case "cucumber": - return true - case "pretty": - return true - default: - return true // enables concurrent custom formatters to work - } -} diff --git a/run_test.go b/run_test.go index 223f7a9..abf485d 100644 --- a/run_test.go +++ b/run_test.go @@ -75,10 +75,12 @@ func TestFailsOrPassesBasedOnStrictModeWhenHasPendingSteps(t *testing.T) { }, } - assert.False(t, r.run()) + failed := r.concurrent(1, func() Formatter { return progressFunc("progress", ioutil.Discard) }) + require.False(t, failed) r.strict = true - assert.True(t, r.run()) + failed = r.concurrent(1, func() Formatter { return progressFunc("progress", ioutil.Discard) }) + require.True(t, failed) } func TestFailsOrPassesBasedOnStrictModeWhenHasUndefinedSteps(t *testing.T) { @@ -98,10 +100,12 @@ func TestFailsOrPassesBasedOnStrictModeWhenHasUndefinedSteps(t *testing.T) { }, } - assert.False(t, r.run()) + failed := r.concurrent(1, func() Formatter { return progressFunc("progress", ioutil.Discard) }) + require.False(t, failed) r.strict = true - assert.True(t, r.run()) + failed = r.concurrent(1, func() Formatter { return progressFunc("progress", ioutil.Discard) }) + require.True(t, failed) } func TestShouldFailOnError(t *testing.T) { @@ -121,7 +125,8 @@ func TestShouldFailOnError(t *testing.T) { }, } - assert.True(t, r.run()) + failed := r.concurrent(1, func() Formatter { return progressFunc("progress", ioutil.Discard) }) + require.True(t, failed) } func TestFailsWithUnknownFormatterOptionError(t *testing.T) {