From 5d351e86c4f1c0cb152619be3d3c0c46021cedfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20L=C3=B6nnblad?= Date: Sat, 14 Mar 2020 13:36:21 -0300 Subject: [PATCH] Made progress formatter verification a bit more accurate --- fmt_progress_test.go | 46 ++++++++++++++++++-------------------------- stacktrace_test.go | 22 +++++---------------- suite_context.go | 6 ++++-- 3 files changed, 28 insertions(+), 46 deletions(-) diff --git a/fmt_progress_test.go b/fmt_progress_test.go index a9efde2..54dfc81 100644 --- a/fmt_progress_test.go +++ b/fmt_progress_test.go @@ -47,19 +47,18 @@ func TestProgressFormatterOutput(t *testing.T) { }, } - expected := ` -...F-.P-.UU.....F..P..U 23 + expected := `...F-.P-.UU.....F..P..U 23 --- Failed steps: Scenario: failing scenario # any.feature:10 When failing # any.feature:11 - Error: errored + Error: errored Scenario Outline: outline # any.feature:22 - When failing # any.feature:24 - Error: errored + When failing # any.feature:24 + Error: errored 8 scenarios (2 passed, 2 failed, 2 pending, 2 undefined) @@ -79,13 +78,13 @@ func nextUndefined() error { func FeatureContext(s *godog.Suite) { s.Step(` + "`^undefined$`" + `, undefined) s.Step(` + "`^next undefined$`" + `, nextUndefined) -}` +} + +` require.True(t, r.run()) - expected = trimAllLines(expected) - actual := trimAllLines(buf.String()) - + actual := buf.String() assert.Equal(t, expected, actual) } @@ -111,7 +110,7 @@ func TestProgressFormatterWhenStepPanics(t *testing.T) { require.True(t, r.run()) actual := buf.String() - assert.Contains(t, actual, "godog/fmt_progress_test.go:107") + assert.Contains(t, actual, "godog/fmt_progress_test.go:106") } func TestProgressFormatterWithPassingMultisteps(t *testing.T) { @@ -163,15 +162,14 @@ func TestProgressFormatterWithFailingMultisteps(t *testing.T) { require.True(t, r.run()) - expected := ` -.F 2 + expected := `.F 2 --- Failed steps: -Scenario: passing scenario # some.feature:4 -Then two # some.feature:6 -Error: sub2: sub-sub: errored + Scenario: passing scenario # some.feature:4 + Then two # some.feature:6 + Error: sub2: sub-sub: errored 1 scenarios (1 failed) @@ -179,8 +177,7 @@ Error: sub2: sub-sub: errored 0s ` - expected = trimAllLines(expected) - actual := trimAllLines(buf.String()) + actual := buf.String() assert.Equal(t, expected, actual) } @@ -231,8 +228,7 @@ func TestProgressFormatterMultistepTemplates(t *testing.T) { require.False(t, r.run()) - expected := ` -.U 2 + expected := `.U 2 1 scenarios (1 undefined) @@ -258,11 +254,10 @@ func FeatureContext(s *godog.Suite) { s.Step(` + "`^unavailable \"([^\"]*)\" cost (\\d+)$`" + `, unavailableCost) s.Step(` + "`^three$`" + `, three) } + ` - expected = trimAllLines(expected) - actual := trimAllLines(buf.String()) - + actual := buf.String() assert.Equal(t, expected, actual) } @@ -333,8 +328,7 @@ Feature: basic require.True(t, r.run()) - expected := ` -.F 2 + expected := `.F 2 --- Failed steps: @@ -349,8 +343,6 @@ Feature: basic 0s ` - expected = trimAllLines(expected) - actual := trimAllLines(buf.String()) - + actual := buf.String() assert.Equal(t, expected, actual) } diff --git a/stacktrace_test.go b/stacktrace_test.go index 88c4b24..7dcfbb4 100644 --- a/stacktrace_test.go +++ b/stacktrace_test.go @@ -3,17 +3,10 @@ package godog import ( "fmt" "runtime" - "strings" "testing" -) -func trimLineSpaces(s string) string { - var res []string - for _, ln := range strings.Split(s, "\n") { - res = append(res, strings.TrimSpace(ln)) - } - return strings.Join(res, "\n") -} + "github.com/stretchr/testify/assert" +) func callstack1() *stack { return callstack2() @@ -37,14 +30,9 @@ func TestStacktrace(t *testing.T) { stack: callstack1(), } - expect := "err msg" + expected := "err msg" actual := fmt.Sprintf("%s", err) - if expect != actual { - t.Fatalf("expected formatted trace error message to be: %s, but got %s", expect, actual) - } - actual = trimLineSpaces(fmt.Sprintf("%+v", err)) - if strings.Index(actual, "stacktrace_test.go") == -1 { - t.Fatalf("does not have stacktrace in actual: %s", actual) - } + assert.Equal(t, expected, actual) + assert.NotContains(t, actual, "stacktrace_test.go") } diff --git a/suite_context.go b/suite_context.go index af02f9b..b6a4109 100644 --- a/suite_context.go +++ b/suite_context.go @@ -545,11 +545,13 @@ func (s *suiteContext) theRenderOutputWillBe(docstring *messages.PickleStepArgum suiteCtxReg := regexp.MustCompile(`suite_context.go:\d+`) suiteCtxFuncReg := regexp.MustCompile(`github.com/cucumber/godog.SuiteContext.func(\d+)`) - expected := trimAllLines(strings.TrimSpace(docstring.Content)) + expected := docstring.Content + expected = trimAllLines(expected) expected = suiteCtxReg.ReplaceAllString(expected, "suite_context.go:0") expected = suiteCtxFuncReg.ReplaceAllString(expected, "SuiteContext.func$1") - actual := trimAllLines(strings.TrimSpace(s.out.String())) + actual := s.out.String() + actual = trimAllLines(actual) actual = suiteCtxReg.ReplaceAllString(actual, "suite_context.go:0") actual = suiteCtxFuncReg.ReplaceAllString(actual, "SuiteContext.func$1")