Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DONT MERGE YET - REVIEW COMMENTS PLEASE - Test renovation - in preparation for fixing the Hook handler bug and adding other features. #659

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Gopkg.toml
_artifacts

vendor
/junk/
23 changes: 17 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,25 @@ check-go-version:
exit 1; \
fi

test: check-go-version
@echo "running all tests"
@go fmt ./...
@go run honnef.co/go/tools/cmd/[email protected] github.com/cucumber/godog
@go run honnef.co/go/tools/cmd/[email protected] github.com/cucumber/godog/cmd/godog
test: check-go-version checks gotest clitest

checks:
@echo check godog
go fmt ./...
go run honnef.co/go/tools/cmd/[email protected] ./...
go vet ./...
@echo check examples
cd _examples && go vet ./...
cd _examples && go test -v ./...


gotest:
@echo "running all tests"
go test -race ./...
go run ./cmd/godog -f progress -c 4

clitest:
@echo "running all tests via cli"
go run ./cmd/godog -f progress -c 4 --strict

gherkin:
@if [ -z "$(VERS)" ]; then echo "Provide gherkin version like: 'VERS=commit-hash'"; exit 1; fi
Expand Down
2 changes: 1 addition & 1 deletion _examples/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestFeatures(t *testing.T) {
},
}

if suite.Run() != 0 {
if suite.Run() != godog.ExitSuccess {
t.Fatal("non-zero status returned, failed to run feature tests")
}
}
Expand Down
4 changes: 2 additions & 2 deletions _examples/custom-formatter/emoji.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ func init() {
godog.Format("emoji", "Progress formatter with emojis", emojiFormatterFunc)
}

func emojiFormatterFunc(suite string, out io.Writer) godog.Formatter {
func emojiFormatterFunc(suite string, out io.WriteCloser) godog.Formatter {
return newEmojiFmt(suite, out)
}

func newEmojiFmt(suite string, out io.Writer) *emojiFmt {
func newEmojiFmt(suite string, out io.WriteCloser) *emojiFmt {
return &emojiFmt{
ProgressFmt: godog.NewProgressFmt(suite, out),
out: out,
Expand Down
1 change: 1 addition & 0 deletions _examples/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lib/pq v1.10.3 h1:v9QZf2Sn6AmjXtQeFpdoq/eaNtYP6IN+7lcrygsIAtg=
github.com/lib/pq v1.10.3/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
Expand Down
1 change: 1 addition & 0 deletions _examples/incorrect-project-structure/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand Down
File renamed without changes.
5 changes: 4 additions & 1 deletion colors/ansi_others.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ package colors
import "io"

type ansiColorWriter struct {
w io.Writer
w io.WriteCloser
mode outputMode
}

func (cw *ansiColorWriter) Write(p []byte) (int, error) {
return cw.w.Write(p)
}
func (cw *ansiColorWriter) Close() error {
return cw.w.Close()
}
8 changes: 6 additions & 2 deletions colors/no_colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ import (
)

type noColors struct {
out io.Writer
out io.WriteCloser
lastbuf bytes.Buffer
}

// Uncolored will accept and io.Writer and return a
// new io.Writer that won't include colors.
func Uncolored(w io.Writer) io.Writer {
func Uncolored(w io.WriteCloser) io.WriteCloser {
return &noColors{out: w}
}

func (w *noColors) Close() error {
return w.out.Close()
}

func (w *noColors) Write(data []byte) (n int, err error) {
er := bytes.NewBuffer(data)
loop:
Expand Down
4 changes: 2 additions & 2 deletions colors/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ const (
// In the console of Windows, which change the foreground and background
// colors of the text by the escape sequence.
// In the console of other systems, which writes to w all text.
func Colored(w io.Writer) io.Writer {
func Colored(w io.WriteCloser) io.WriteCloser {
return createModeAnsiColorWriter(w, discardNonColorEscSeq)
}

// NewModeAnsiColorWriter create and initializes a new ansiColorWriter
// by specifying the outputMode.
func createModeAnsiColorWriter(w io.Writer, mode outputMode) io.Writer {
func createModeAnsiColorWriter(w io.WriteCloser, mode outputMode) io.WriteCloser {
if _, ok := w.(*ansiColorWriter); !ok {
return &ansiColorWriter{
w: w,
Expand Down
45 changes: 0 additions & 45 deletions example_subtests_test.go

This file was deleted.

32 changes: 15 additions & 17 deletions features/background.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,31 @@ Feature: run background
Feature: with background

Background:
Given a feature path "features/load.feature:6"
Given a background step is defined

Scenario: parse a scenario
When I parse features
Then I should have 1 scenario registered
Then step 'a background step is defined' should have been executed
"""
When I run feature suite
Then the suite should have passed
And the following steps should be passed:
"""
a feature path "features/load.feature:6"
I parse features
I should have 1 scenario registered
a background step is defined
step 'a background step is defined' should have been executed
"""

Scenario: should skip all consequent steps on failure
Scenario: should skip all subsequent steps on failure
Given a feature "normal.feature" file:
"""
Feature: with background

Background:
Given a failing step
And a feature path "features/load.feature:6"
Then this step should not be called

Scenario: parse a scenario
When I parse features
Then I should have 1 scenario registered
And this other step should not be called
And this last step should not be called
"""
When I run feature suite
Then the suite should have failed
Expand All @@ -45,9 +43,9 @@ Feature: run background
"""
And the following steps should be skipped:
"""
a feature path "features/load.feature:6"
I parse features
I should have 1 scenario registered
this step should not be called
this other step should not be called
this last step should not be called
"""

Scenario: should continue undefined steps
Expand All @@ -59,17 +57,17 @@ Feature: run background
Given an undefined step

Scenario: parse a scenario
When I do undefined action
Then I should have 1 scenario registered
When some other undefined step
Then this step should not be called
"""
When I run feature suite
Then the suite should have passed
And the following steps should be undefined:
"""
an undefined step
I do undefined action
some other undefined step
"""
And the following steps should be skipped:
"""
I should have 1 scenario registered
this step should not be called
"""
15 changes: 15 additions & 0 deletions features/docstring.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

Feature: docstring parsing

Scenario: should be able to convert a Doc String to a `*godog.DocString` argument
Given call func(*godog.DocString) with 'text':
"""
text
"""

Scenario: should be able to convert a Doc String to a `string` argument
Given call func(string) with 'text':
"""
text
"""

77 changes: 77 additions & 0 deletions features/errors.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
Feature: scenario hook errors
This feature checks the handling of errors in scenario hooks and steps

Scenario: no errors
Given a feature "normal.feature" file:
"""
Feature: the feature
Scenario: passing scenario
When passing step
"""
When I run feature suite

Then the suite should have passed
And the trace should be:
"""
Feature: the feature
Scenario: passing scenario
Step: passing step : passed
"""

Scenario: hook failures
Given a feature "normal.feature" file:
"""
Feature: failures
@fail_before_scenario
Scenario: fail before scenario
When passing step

@fail_after_scenario
Scenario: failing after scenario
And passing step

@fail_before_scenario
@fail_after_scenario
Scenario: failing before and after scenario
When passing step

@fail_before_scenario
Scenario: failing before scenario with failing step
When failing step

@fail_after_scenario
Scenario: failing after scenario with failing step
And failing step

@fail_before_scenario
@fail_after_scenario
Scenario: failing before and after scenario with failing step
When failing step
"""
When I run feature suite

Then the suite should have failed
And the trace should be:
"""
Feature: failures
Scenario: fail before scenario
Step: passing step : failed
Error: before scenario hook failed: failed in before scenario hook
Scenario: failing after scenario
Step: passing step : failed
Error: after scenario hook failed: failed in after scenario hook
Scenario: failing before and after scenario
Step: passing step : failed
Error: after scenario hook failed: failed in after scenario hook, step error: before scenario hook failed: failed in before scenario hook
Scenario: failing before scenario with failing step
Step: failing step : failed
Error: before scenario hook failed: failed in before scenario hook
Scenario: failing after scenario with failing step
Step: failing step : failed
Error: after scenario hook failed: failed in after scenario hook, step error: intentional failure
Scenario: failing before and after scenario with failing step
Step: failing step : failed
Error: after scenario hook failed: failed in after scenario hook, step error: before scenario hook failed: failed in before scenario hook
"""


Loading
Loading