Giter Club home page Giter Club logo

godog's Introduction

#StandWithUkraine Build Status PkgGoDev codecov pull requests issues

Godog

Godog logo

The API is likely to change a few times before we reach 1.0.0

Please read the full README, you may find it very useful. And do not forget to peek into the Release Notes and the CHANGELOG from time to time.

Package godog is the official Cucumber BDD framework for Golang, it merges specification and test documentation into one cohesive whole, using Gherkin formatted scenarios in the format of Given, When, Then.

The project was inspired by behat and cucumber.

Why Godog/Cucumber

A single source of truth

Godog merges specification and test documentation into one cohesive whole.

Living documentation

Because they're automatically tested by Godog, your specifications are always bang up-to-date.

Focus on the customer

Business and IT don't always understand each other. Godog's executable specifications encourage closer collaboration, helping teams keep the business goal in mind at all times.

Less rework

When automated testing is this much fun, teams can easily protect themselves from costly regressions.

Read more

Contributions

Godog is a community driven Open Source Project within the Cucumber organization. We welcome contributions from everyone, and we're ready to support you if you have the enthusiasm to contribute.

See the contributing guide for more detail on how to get started.

See the releasing guide for release flow details.

Getting help

We have a community Slack where you can chat with other users, developers, and BDD practitioners.

Here are some useful channels to try:

Examples

You can find a few examples here.

Note that if you want to execute any of the examples and have the Git repository checked out in the $GOPATH, you need to use: GO111MODULE=off. Issue for reference.

Godogs

The following example can be found here.

Step 1 - Setup a go module

Create a new go module named godogs in your go workspace by running mkdir godogs

From now on, use godogs as your working directory by running cd godogs

Initiate the go module inside the godogs directory by running go mod init godogs

Step 2 - Create gherkin feature

Imagine we have a godog cart to serve godogs for lunch.

First of all, we describe our feature in plain text:

Feature: eat godogs
  In order to be happy
  As a hungry gopher
  I need to be able to eat godogs

  Scenario: Eat 5 out of 12
    Given there are 12 godogs
    When I eat 5
    Then there should be 7 remaining

Run vim features/godogs.feature and add the text above into the vim editor and save the file.

Step 3 - Create godog step definitions

NOTE: Same as go test, godog respects package level isolation. All your step definitions should be in your tested package root directory. In this case: godogs.

Create and copy the step definitions below into a new file by running vim godogs_test.go:

package main

import "github.com/cucumber/godog"

func iEat(arg1 int) error {
        return godog.ErrPending
}

func thereAreGodogs(arg1 int) error {
        return godog.ErrPending
}

func thereShouldBeRemaining(arg1 int) error {
        return godog.ErrPending
}

func InitializeScenario(ctx *godog.ScenarioContext) {
        ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs)
        ctx.Step(`^I eat (\d+)$`, iEat)
        ctx.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
}

Alternatively, you can also specify the keyword (Given, When, Then...) when creating the step definitions:

func InitializeScenario(ctx *godog.ScenarioContext) {
        ctx.Given(`^there are (\d+) godogs$`, thereAreGodogs)
        ctx.When(`^I eat (\d+)$`, iEat)
        ctx.Then(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
}

Our module should now look like this:

godogs
- features
  - godogs.feature
- go.mod
- go.sum
- godogs_test.go

Run go test in the godogs directory to run the steps you have defined. You should now see that the scenario runs with a warning stating there are no tests to run.

testing: warning: no tests to run
PASS
ok      godogs  0.225s

By adding some logic to these steps, you will be able to thoroughly test the feature you just defined.

Step 4 - Create the main program to test

Let's keep it simple by only requiring an amount of godogs for now.

Create and copy the code below into a new file by running vim godogs.go

package main

// Godogs available to eat
var Godogs int

func main() { /* usual main func */ }

Our module should now look like this:

godogs
- features
  - godogs.feature
- go.mod
- go.sum
- godogs.go
- godogs_test.go

Step 5 - Add some logic to the step definitions

Now lets implement our step definitions to test our feature requirements.

Replace the contents of godogs_test.go with the code below by running vim godogs_test.go.

package main

import (
  "context"
  "errors"
  "fmt"
  "testing"

  "github.com/cucumber/godog"
)

// godogsCtxKey is the key used to store the available godogs in the context.Context.
type godogsCtxKey struct{}

func thereAreGodogs(ctx context.Context, available int) (context.Context, error) {
  return context.WithValue(ctx, godogsCtxKey{}, available), nil
}

func iEat(ctx context.Context, num int) (context.Context, error) {
  available, ok := ctx.Value(godogsCtxKey{}).(int)
  if !ok {
    return ctx, errors.New("there are no godogs available")
  }

  if available < num {
    return ctx, fmt.Errorf("you cannot eat %d godogs, there are %d available", num, available)
  }

  available -= num

  return context.WithValue(ctx, godogsCtxKey{}, available), nil
}

func thereShouldBeRemaining(ctx context.Context, remaining int) error {
  available, ok := ctx.Value(godogsCtxKey{}).(int)
  if !ok {
    return errors.New("there are no godogs available")
  }

  if available != remaining {
    return fmt.Errorf("expected %d godogs to be remaining, but there is %d", remaining, available)
  }

  return nil
}

func TestFeatures(t *testing.T) {
  suite := godog.TestSuite{
    ScenarioInitializer: InitializeScenario,
    Options: &godog.Options{
      Format:   "pretty",
      Paths:    []string{"features"},
      TestingT: t, // Testing instance that will run subtests.
    },
  }

  if suite.Run() != 0 {
    t.Fatal("non-zero status returned, failed to run feature tests")
  }
}

func InitializeScenario(sc *godog.ScenarioContext) {
  sc.Step(`^there are (\d+) godogs$`, thereAreGodogs)
  sc.Step(`^I eat (\d+)$`, iEat)
  sc.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
}

In this example, we are using context.Context to pass the state between the steps. Every scenario starts with an empty context and then steps and hooks can add relevant information to it. Instrumented context is chained through the steps and hooks and is safe to use when multiple scenarios are running concurrently.

When you run godog again with go test -v godogs_test.go, you should see a passing run:

=== RUN   TestFeatures
Feature: eat godogs
  In order to be happy
  As a hungry gopher
  I need to be able to eat godogs
=== RUN   TestFeatures/Eat_5_out_of_12

  Scenario: Eat 5 out of 12          # features/godogs.feature:6
    Given there are 12 godogs        # godog_test.go:15 -> command-line-arguments.thereAreGodogs
    When I eat 5                     # godog_test.go:19 -> command-line-arguments.iEat
    Then there should be 7 remaining # godog_test.go:34 -> command-line-arguments.thereShouldBeRemaining

1 scenarios (1 passed)
3 steps (3 passed)
279.917µs
--- PASS: TestFeatures (0.00s)
    --- PASS: TestFeatures/Eat_5_out_of_12 (0.00s)
PASS
ok      command-line-arguments  0.164s

You may hook to ScenarioContext Before event in order to reset or pre-seed the application state before each scenario. You may hook into more events, like sc.StepContext() After to print all state in case of an error. Or BeforeSuite to prepare a database.

By now, you should have figured out, how to use godog. Another piece of advice is to make steps orthogonal, small and simple to read for a user. Whether the user is a dumb website user or an API developer, who may understand a little more technical context - it should target that user.

When steps are orthogonal and small, you can combine them just like you do with Unix tools. Look how to simplify or remove ones, which can be composed.

TestFeatures acts as a regular Go test, so you can leverage your IDE facilities to run and debug it.

Code of Conduct

Everyone interacting in this codebase and issue tracker is expected to follow the Cucumber code of conduct.

References and Tutorials

Documentation

See pkg documentation for general API details. See Circle Config for supported go versions. See godog -h for general command options.

See implementation examples:

FAQ

Running Godog with go test

You may integrate running godog in your go test command.

Subtests of *testing.T

You can run test suite using go Subtests. In this case it is not necessary to have godog command installed. See the following example.

package main_test

import (
	"testing"

	"github.com/cucumber/godog"
)

func TestFeatures(t *testing.T) {
  suite := godog.TestSuite{
    ScenarioInitializer: func(s *godog.ScenarioContext) {
      // Add step definitions here.
    },
    Options: &godog.Options{
      Format:   "pretty",
      Paths:    []string{"features"},
      TestingT: t, // Testing instance that will run subtests.
    },
  }

  if suite.Run() != 0 {
    t.Fatal("non-zero status returned, failed to run feature tests")
  }
}

Then you can run suite.

go test -test.v -test.run ^TestFeatures$

Or a particular scenario.

go test -test.v -test.run ^TestFeatures$/^my_scenario$

TestMain

You can run test suite using go TestMain func available since go 1.4. In this case it is not necessary to have godog command installed. See the following examples.

The following example binds godog flags with specified prefix godog in order to prevent flag collisions.

package main

import (
	"os"
	"testing"

	"github.com/cucumber/godog"
	"github.com/cucumber/godog/colors"
	"github.com/spf13/pflag" // godog v0.11.0 and later
)

var opts = godog.Options{
	Output: colors.Colored(os.Stdout),
	Format: "progress", // can define default values
}

func init() {
	godog.BindFlags("godog.", pflag.CommandLine, &opts) // godog v0.10.0 and earlier
	godog.BindCommandLineFlags("godog.", &opts)        // godog v0.11.0 and later
}

func TestMain(m *testing.M) {
	pflag.Parse()
	opts.Paths = pflag.Args()

	status := godog.TestSuite{
		Name: "godogs",
		TestSuiteInitializer: InitializeTestSuite,
		ScenarioInitializer:  InitializeScenario,
		Options: &opts,
	}.Run()

	// Optional: Run `testing` package's logic besides godog.
	if st := m.Run(); st > status {
		status = st
	}

	os.Exit(status)
}

Then you may run tests with by specifying flags in order to filter features.

go test -v --godog.random --godog.tags=wip
go test -v --godog.format=pretty --godog.random -race -coverprofile=coverage.txt -covermode=atomic

The following example does not bind godog flags, instead manually configuring needed options.

func TestMain(m *testing.M) {
	opts := godog.Options{
		Format:    "progress",
		Paths:     []string{"features"},
		Randomize: time.Now().UTC().UnixNano(), // randomize scenario execution order
	}

	status := godog.TestSuite{
		Name: "godogs",
		TestSuiteInitializer: InitializeTestSuite,
		ScenarioInitializer:  InitializeScenario,
		Options: &opts,
	}.Run()

	// Optional: Run `testing` package's logic besides godog.
	if st := m.Run(); st > status {
		status = st
	}

	os.Exit(status)
}

You can even go one step further and reuse go test flags, like verbose mode in order to switch godog format. See the following example:

func TestMain(m *testing.M) {
	format := "progress"
	for _, arg := range os.Args[1:] {
		if arg == "-test.v=true" { // go test transforms -v option
			format = "pretty"
			break
		}
	}

	opts := godog.Options{
		Format: format,
		Paths:     []string{"features"},
	}

	status := godog.TestSuite{
		Name: "godogs",
		TestSuiteInitializer: InitializeTestSuite,
		ScenarioInitializer:  InitializeScenario,
		Options: &opts,
	}.Run()

	// Optional: Run `testing` package's logic besides godog.
	if st := m.Run(); st > status {
		status = st
	}

	os.Exit(status)
}

Now when running go test -v it will use pretty format.

Tags

If you want to filter scenarios by tags, you can use the -t=<expression> or --tags=<expression> where <expression> is one of the following:

  • @wip - run all scenarios with wip tag
  • ~@wip - exclude all scenarios with wip tag
  • @wip && ~@new - run wip scenarios, but exclude new
  • @wip,@undone - run wip or undone scenarios

Using assertion packages like testify with Godog

A more extensive example can be found here.

func thereShouldBeRemaining(ctx context.Context, remaining int) error {
	assert.Equal(
    godog.T(ctx), Godogs, remaining, 
    "Expected %d godogs to be remaining, but there is %d", remaining, Godogs,
  )
	return nil
}

Embeds

If you're looking to compile your test binary in advance of running, you can compile the feature files into the binary via go:embed:

//go:embed features/*
var features embed.FS

var opts = godog.Options{
	Paths: []string{"features"},
	FS:    features,
}

Now, the test binary can be compiled with all feature files embedded, and can be ran independently from the feature files:

> go test -c ./test/integration/integration_test.go
> mv integration.test /some/random/dir
> cd /some/random/dir
> ./integration.test

NOTE: godog.Options.FS is as fs.FS, so custom filesystem loaders can be used.

CLI Mode

NOTE: The godog CLI has been deprecated. It is recommended to use go test instead.

Another way to use godog is to run it in CLI mode.

In this mode godog CLI will use go under the hood to compile and run your test suite.

Godog does not intervene with the standard go test command behavior. You can leverage both frameworks to functionally test your application while maintaining all test related source code in _test.go files.

Godog acts similar compared to go test command, by using go compiler and linker tool in order to produce test executable. Godog contexts need to be exported the same way as Test functions for go tests. Note, that if you use godog command tool, it will use go executable to determine compiler and linker.

Install

go install github.com/cucumber/godog/cmd/godog@latest

Adding @v0.12.0 will install v0.12.0 specifically instead of master.

With go version prior to 1.17, use go get github.com/cucumber/godog/cmd/[email protected]. Running within the $GOPATH, you would also need to set GO111MODULE=on, like this:

GO111MODULE=on go get github.com/cucumber/godog/cmd/[email protected]

Configure common options for godog CLI

There are no global options or configuration files. Alias your common or project based commands: alias godog-wip="godog --format=progress --tags=@wip"

Concurrency

When concurrency is configured in options, godog will execute the scenarios concurrently, which is supported by all supplied formatters.

In order to support concurrency well, you should reset the state and isolate each scenario. They should not share any state. It is suggested to run the suite concurrently in order to make sure there is no state corruption or race conditions in the application.

It is also useful to randomize the order of scenario execution, which you can now do with --random command option or godog.Options.Randomize setting.

Building your own custom formatter

A simple example can be found here.

License

Godog and Gherkin are licensed under the MIT and developed as a part of the cucumber project

godog's People

Contributors

aslakhellesoy avatar axw avatar chirino avatar ckstettler avatar dumpsterfireproject avatar funvit avatar glibas avatar l3pp4rd avatar leviable avatar lolvlvl avatar longyue0521 avatar lonnblad avatar luke-hill avatar marianmacik avatar mattwynne avatar mdeolmosmeli avatar mpkorstanje avatar mroth avatar mrsheepuk avatar mxygem avatar nightlyone avatar omnicolor avatar patrickvalle avatar philoserf avatar pktpls avatar pykselle avatar renovate[bot] avatar rvflash avatar smikulcik avatar vearutop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

godog's Issues

Panic in fmt_pretty

Probably related to #42

Attempting to run godog in the godog code folder results in the following panic:

image

Community chat ?

Hi,

What about gitter, IRC or slack to talk all together about this framework ?

Thanks

panic in pretty printing, when background step is longer than scenario step

given

Feature:
Background:
Given very long string here we cannot imagine how long

Scenario:
Given short

leads to panic in pretty printer.

The following patch fixes it for me:

--- a/fmt_pretty.go
+++ b/fmt_pretty.go
@@ -256,6 +256,9 @@ func (f *pretty) printStepKind(res *stepResult) {
        // first step of scenario, print header and calculate comment position
        case f.scenario != nil && f.steps == len(f.scenario.Steps):
                f.commentPos = f.longestStep(f.scenario.Steps, f.length(f.scenario))
+               if bgLength := f.longestStep(f.feature.Background.Steps, f.length(f.feature.Background)); bgLength > f.commentPos {
+                       f.commentPos = bgLength
+               }
                text := s(f.indent) + bcl(f.scenario.Keyword+": ", white) + f.scenario.Name
                text += s(f.commentPos-f.length(f.scenario)+1) + f.line(f.scenario.Location)
                fmt.Println("\n" + text)

Environment variables

Firsteval, congrats for the good work ! Great project !

I'm currently wondering how are environment variables supported. Typically say we have an authentication feature, and two scenari in it (authentication successfull and authentication failure) but It would be preferable to inject credentials from envrironment for the valid authentication scenario. What would be the best way to do this with godog ?

Use "features" instead of "examples" for `feature`-files-directory

@l3pp4rd Good morning, hope you're fine?

Background

I'm going to write my second go app. I would like to see, if I can setup a similar aruba-thing in go we have with ruby.

Current situation

You use the term examples for your feature directory in your README.md which I find confusing.

Proposed change

Does it makes sense to change that to features instead? Event in godog -h you use the term features.

godog -h

# =>   godog [options] [<paths>]
# => 
# => Arguments:
# =>   paths:                Optional path(s) to execute. Can be:
# =>                             - dir (features/)
# =>                             - feature (*.feature)
# =>                             - scenario at specific line (*.feature:10)
# =>                         If no paths are listed, suite tries features path by default.
# => 

Motivation

Having the same terms over all cucumbers make it easier for users to recognize things.

figure out a better option for vendor packages. gherkin and ansicolor

these could be built into the project directly, without requiring a separate go get because managing dependency versions sometimes just breaks compatibility and avoiding that would be best option. Since this library does not and will not have many dependencies - only gerkin parser.

Preffered way to pass some test context between steps?

Hi,

I'm currently working on building some tests for an authenticating proxy, and i'm a bit stuck about how to pass results between stages of the test. At the moment i'm using a sort of "feature" struct, which i'm populating and consuming information from, is this the "idiomatic" way? Or is there some way i'm unaware of?

For instance, I want to test my implementationg of the OAUTH2 flow, so there's a lot of

    Scenario: A Request made                                                                                            
        Given an upstream server that pings                                                                             
        And an ADFS server that is preauthenticated                                                                     
        And a client                                                                                                    
        When I start a proxy server configured for the ADFS server                                                      
        And I request /Index.html from the proxy server                                                                 
        Then I should be redirected to the ADFS login URL                                                               
        When I follow the redirect                                                                                      
        Then I should be redirected to the callback URL with a query parameter                                          
        When I follow the redirect                                                                                      
        Then I should be redirected to the original page (relative URL)                                                 
        Then I should get an OK response with index.html in the body          

Is there some internal godog context? Any help or guidance would be really appreciated. Thanks

Out of Memory

I previously used v0.2.0 and everything was fine, however with the update to the latest version I experience an out of memory error when doing the following steps. Am I missing anything very obvious?

$ echo $GOPATH
/home/chris/Workspace/my-new-project

$ go version
go version go1.6.3 linux/amd64

$ go get github.com/DATA-DOG/godog/cmd/godog
$ ./bin/godog --version
Godog version is: v0.5.3

$ tree -L 4
.
├── bin
│   └── godog
├── features
│   └── godogs.feature
├── pkg
│   └── linux_amd64
│       └── github.com
│           └── DATA-DOG
└── src
    └── github.com
        └── DATA-DOG
            └── godog

10 directories, 2 files

$ cat features/godogs.feature 
Feature: eat godogs
  In order to be happy
  As a hungry gopher
  I need to be able to eat godogs

  Scenario: Eat 5 out of 12
    Given there are 12 godogs
    When I eat 5
    Then there should be 7 remaining

$ ./bin/godog 
fatal error: runtime: out of memory

runtime stack:
runtime.throw(0x6e5240, 0x16)
    /usr/lib/golang/src/runtime/panic.go:547 +0x90
runtime.sysMap(0xcc90470000, 0xe0730000, 0x0, 0x813818)
    /usr/lib/golang/src/runtime/mem_linux.go:206 +0x9b
runtime.(*mheap).sysAlloc(0x7fac80, 0xe0730000, 0x1159bb570)
    /usr/lib/golang/src/runtime/malloc.go:429 +0x191
runtime.(*mheap).grow(0x7fac80, 0x70398, 0x0)
    /usr/lib/golang/src/runtime/mheap.go:651 +0x63
runtime.(*mheap).allocSpanLocked(0x7fac80, 0x70394, 0xc809b37900)
    /usr/lib/golang/src/runtime/mheap.go:553 +0x4f6
runtime.(*mheap).alloc_m(0x7fac80, 0x70394, 0x100000000, 0x7fc110)
    /usr/lib/golang/src/runtime/mheap.go:437 +0x119
runtime.(*mheap).alloc.func1()
    /usr/lib/golang/src/runtime/mheap.go:502 +0x41
runtime.systemstack(0x7ffef176b4d0)
    /usr/lib/golang/src/runtime/asm_amd64.s:307 +0xab
runtime.(*mheap).alloc(0x7fac80, 0x70394, 0x10100000000, 0x414e4c)
    /usr/lib/golang/src/runtime/mheap.go:503 +0x63
runtime.largeAlloc(0xe0728000, 0x7f3900000000, 0xca00000004)
    /usr/lib/golang/src/runtime/malloc.go:766 +0xb3
runtime.mallocgc.func3()
    /usr/lib/golang/src/runtime/malloc.go:664 +0x33
runtime.systemstack(0x7f7e00)
    /usr/lib/golang/src/runtime/asm_amd64.s:291 +0x79
runtime.mstart()
    /usr/lib/golang/src/runtime/proc.go:1051

goroutine 1 [running]:
runtime.systemstack_switch()
    /usr/lib/golang/src/runtime/asm_amd64.s:245 fp=0xc82003f380 sp=0xc82003f378
runtime.mallocgc(0xe0728000, 0x5fe580, 0x0, 0xcae990d710)
    /usr/lib/golang/src/runtime/malloc.go:665 +0x9eb fp=0xc82003f458 sp=0xc82003f380
runtime.newarray(0x5fe580, 0xe072800, 0x3)
    /usr/lib/golang/src/runtime/malloc.go:798 +0xc9 fp=0xc82003f498 sp=0xc82003f458
runtime.growslice(0x5f4620, 0xcbdcaea000, 0xb38ec00, 0xb38ec00, 0xb38ec01, 0x0, 0x0, 0x0)
    /usr/lib/golang/src/runtime/slice.go:100 +0x2c1 fp=0xc82003f508 sp=0xc82003f498
github.com/DATA-DOG/godog.maybeVendorPaths(0xc8200dd4a0, 0x24, 0x0, 0x0, 0x0)
    /home/chris/Workspace/my-new-project/src/github.com/DATA-DOG/godog/builder.go:277 +0x597 fp=0xc82003f6a0 sp=0xc82003f508
github.com/DATA-DOG/godog.Build(0x0, 0x0, 0x0, 0x0)
    /home/chris/Workspace/my-new-project/src/github.com/DATA-DOG/godog/builder.go:133 +0x13ab fp=0xc82003fc70 sp=0xc82003f6a0
main.buildAndRun(0x0, 0x0, 0x0)
    /home/chris/Workspace/my-new-project/src/github.com/DATA-DOG/godog/cmd/godog/main.go:24 +0x4b fp=0xc82003fd28 sp=0xc82003fc70
main.main()
    /home/chris/Workspace/my-new-project/src/github.com/DATA-DOG/godog/cmd/godog/main.go:85 +0x66c fp=0xc82003ff50 sp=0xc82003fd28
runtime.main()
    /usr/lib/golang/src/runtime/proc.go:188 +0x2b0 fp=0xc82003ffa0 sp=0xc82003ff50
runtime.goexit()
    /usr/lib/golang/src/runtime/asm_amd64.s:1998 +0x1 fp=0xc82003ffa8 sp=0xc82003ffa0

Build using latest gherkin-go is broken

2 days ago gherkin-go updated some types declared at ast.go

ScenarioOutline.Examples is now an []interface{}
https://github.com/cucumber/gherkin-go/blob/master/ast.go#L46-L50

type ScenarioOutline struct {
    ScenarioDefinition
    Tags     []*Tag        `json:"tags"`
    Examples []interface{} `json:"examples"`
}

Code that uses Examples is now failing due to not recognised methods.

Scenario:

godog$ git rev-parse HEAD
38c79db503ff4ad0cbb7c1fd04531f243d992c7d
gherkin-go$  git rev-parse HEAD
64f5ebccd5511abba41bf4fa5664faf289c9b102

go versions tested
osx (1.4.3, 1.5.0, 1.6.0)
alpine docker container (1.4.3)

Build output:

/go/src/github.com/DATA-DOG/godog # go build .
# github.com/DATA-DOG/godog
./fmt.go:224: ex.TableBody undefined (type interface {} has no field or method TableBody)
./fmt_pretty.go:136: example.TableBody undefined (type interface {} has no field or method TableBody)
./fmt_pretty.go:176: example.TableHeader undefined (type interface {} has no field or method TableHeader)
./fmt_pretty.go:181: example.Keyword undefined (type interface {} has no field or method Keyword)
./fmt_pretty.go:181: example.Name undefined (type interface {} has no field or method Name)
./fmt_pretty.go:183: example.TableHeader undefined (type interface {} has no field or method TableHeader)
./fmt_pretty.go:190: example.TableBody undefined (type interface {} has no field or method TableBody)
./suite.go:271: example.TableHeader undefined (type interface {} has no field or method TableHeader)
./suite.go:272: example.TableBody undefined (type interface {} has no field or method TableBody)
./suite.go:272: too many errors

support vendoring

In a project using vendoring, I cannot use the vendored copy of godog.

Steps to reproduce:

  • have a project in a single repostory with 3 directories:
    ** "foo" the package implementing things
    ** "features" where I have my *.feature files and step_test.go
    ** "vendor" where I vendored all my dependencies using govendor add '+all,^vendor,^local,^std' using https://github.com/kardianos/govendor (including "github.com/DATA-DOG/godog")
  • now remove godog package via
    rm -rf $GOPATHsrc/github.com/DATA-DOG/godog
  • trying to run godog ./features/*.features leads to
# _/tmp/godog-1465317047292377579
godog_runner_test.go:4:2: cannot find package "github.com/DATA-DOG/godog" in any of:
    /usr/local/go/src/github.com/DATA-DOG/godog (from $GOROOT)
    GOPATH/src/github.com/DATA-DOG/godog (from $GOPATH)
FAIL    _/tmp/godog-1465317047292377579 [setup failed]

It also doesn't work, when I go to the "features" directory and run godog *.features as well.

Integrate with go test tool?

Is is possible for me to run my features using the go test command?
I would like to have a test file with maybe a single test function which will invoke the godog runner command with a suite which is prepared by it. Then I wouldn't need to depend on the godog command to run my tests. I can just integrate it will all my other tests.

godog does not print stack trace when panic is caught

Having used Behave (python) and Cucumber (Java), I really appreciate Godog, which I have integrated into a Go project.

I have one problem with it: When a problem occurs (especially an error raised), only the message is displayed, leaving me with no idea where the issue actually occurred:

runtime error: index out of range

Is there a way to tell godog to be more verbose so I can work out what index was out of range?

Assistance with error

Hi,

We have been using Godog for a while with no issues. I ran an update and now get the error:

# _/tmp/godog-1464349241273590437
godog_runner_test.go:13:29: expected ';', found 'IDENT' featureContext
godog_runner_test.go:16:2: expected '}', found 'EOF'
FAIL    _/tmp/godog-1464349241273590437 [setup failed]

The error message is very unclear and doesn't point to any of my feature or step files. Also, I absolutely did not change my working godog test code at all - the only change was running go get -u github.com/DATA-DOG/godog/cmd/godog.

Can you advise on how to resolve?

failed to compile testmain package:

I am getting a compilation error when running godog on example folder.

Go version:

$ go version
go version go1.7.4 darwin/amd64

I installed godog:

$ go get -u github.com/DATA-DOG/godog

Then I go into the godogs example directory:

$ cd $GOPATH
$ cd src/go/src/github.com/DATA-DOG/godog/examples/godogs

And run godog:

$ godog
failed to compile testmain package:

step definition arguments + reflect

  • consider an attempt to fill the step function arguments based on their type. since we have a limited argument types, it should not be too complicated.
  • measure the performance impact and whether it should be pushed into the mainstream (it is way more convenient, haven't noticed any highly visible performance decrease)

Test position when running in concurrency

Hi,

When launching the test in concurrency, we don't know in which position the test is in the queue.

This kind of feature is for instance used in parallel_test (https://github.com/grosser/parallel_tests) with the env variable TEST_ENV_NUMBER. This is slightly difference though, in parallel this information is set in a environment variable as different processes are launched. In godog it would more linked to the Suite I guess.

Do you think it's a good idea to add that in Godog, or would you prefer that the testers take care about that ?

Thanks,

Bug with table tests

My current environment

$ go version
go version go1.6.2 linux/amd64


$ godog -version
Godog version is: v0.5.0

I have created a feature with a scenario outline, I have added 2 examples sucessfully but when I try to add a third example I get an "index out of range" runtime error

Seems to be an issue with the output printer, as it continues to execute the test cases.

You can re-created with the following

I have re-created with this file (Failing with the 3rd example), note I have no _test.go file as not needed to re-created the error
sample.feature

Feature: demo
  Background:
    Given Something
  Scenario Outline: making http call
    When I make "<method>" on "<path>"
    Then I should get status code <status-code>
    Examples:
      | description                    | method    | path         | status-code |
      | Fails for post on /health 1    | POST      | /health      | 405         |
      | Fails for post on /health 2    | POST      | /health      | 405         |
      | Fails for post on /health 3    | POST      | /health      | 405         |

When I run

cd go/src/datadoginv 
godog .

I get this

Feature: demo

  Background: 
    Given Something

  Scenario Outline: making http call            # sample.feature:4
    When I make "<method>" on "<path>"
    Then I should get status code <status-code>

    Examples: 
      | description                 | method | path    | status-code |
      | Fails for post on /health 1 | POST   | /health | 405         |
      | Fails for post on /health 2 | POST   | /health | 405         |
      | Fails for post on /health 3 | POST   | /health | 405         |
panic: runtime error: index out of range

goroutine 1 [running]:
panic(0x6774a0, 0xc82000e0b0)
    /usr/local/go-versions/go1.6.2/src/runtime/panic.go:481 +0x3e6
github.com/DATA-DOG/godog.(*pretty).printOutlineExample(0xc820076fc0, 0xc820120000)
    /home/pmcgrath/go/src/github.com/DATA-DOG/godog/fmt_pretty.go:187 +0x19a2
github.com/DATA-DOG/godog.(*pretty).printStepKind(0xc820076fc0, 0xc8200bf0c0)
    /home/pmcgrath/go/src/github.com/DATA-DOG/godog/fmt_pretty.go:295 +0x15a7
github.com/DATA-DOG/godog.(*pretty).Undefined(0xc820076fc0, 0xc820012cd0)
    /home/pmcgrath/go/src/github.com/DATA-DOG/godog/fmt_pretty.go:335 +0x200
github.com/DATA-DOG/godog.(*Suite).runStep(0xc8200ac2a0, 0xc820012cd0, 0x7f328f1e3028, 0xc82000f8c0, 0x0, 0x0)
    /home/pmcgrath/go/src/github.com/DATA-DOG/godog/suite.go:202 +0xa6
github.com/DATA-DOG/godog.(*Suite).runSteps(0xc8200ac2a0, 0xc82011f090, 0x2, 0x2, 0x7f328f1e3028, 0xc82000f8c0, 0x7f328f1e3028, 0xc82000f8c0)
    /home/pmcgrath/go/src/github.com/DATA-DOG/godog/suite.go:246 +0xba
github.com/DATA-DOG/godog.(*Suite).runOutline(0xc8200ac2a0, 0xc820120000, 0xc82005a720, 0x0, 0x0)
    /home/pmcgrath/go/src/github.com/DATA-DOG/godog/suite.go:310 +0x81c
github.com/DATA-DOG/godog.(*Suite).runFeature(0xc8200ac2a0, 0xc820122000)
    /home/pmcgrath/go/src/github.com/DATA-DOG/godog/suite.go:336 +0x34a
github.com/DATA-DOG/godog.(*Suite).run(0xc8200ac2a0)
    /home/pmcgrath/go/src/github.com/DATA-DOG/godog/suite.go:170 +0xdf
github.com/DATA-DOG/godog.(*runner).run(0xc8200bed00, 0xc8200bed00)
    /home/pmcgrath/go/src/github.com/DATA-DOG/godog/run.go:58 +0xe6
github.com/DATA-DOG/godog.Run(0x738cf0, 0xc820000180)
    /home/pmcgrath/go/src/github.com/DATA-DOG/godog/run.go:118 +0x5c2
main.main()
    /tmp/godog-1468325360368887697/_testmain.go:10 +0x23

app.go

package main

import "fmt"

func main() {
    fmt.Print("Dummy app")
}

Exit status is not correct

See example below.

  • tests are failing
  • it prints out exit status 1
  • godog exits with status code 0
  • Expected: godog should exit with status code 1
vagrant@fishbrain-bonito:~/go/src/github.com/fishbrain/bonito$ make integration
export GOPATH=`pwd`/:`pwd`/vendor/:/home/vagrant/go && godog
Feature: Customer.io Notifications

  Scenario: Success                                                                            # ../customerio.feature:6

[...]

    returned body was not expected. Actual: {"data":{"avatar":"https://cdn-staging.fishbrain.com/avatar/42/big","firstname":"John","follow_url":"https://deeplink.me/staging.fishbrain.com/profile/Johan","lastname":"Smith","name":"Angler follow you","type":"new_follower","username":"Johan"},"name":"new_follower"}

--- Failed scenarios:

    ../customerio.feature:10

1 scenarios (1 failed)
4 steps (3 passed, 1 failed)
624.71419ms
exit status 1
vagrant@fishbrain-bonito:~/go/src/github.com/fishbrain/bonito$ echo $?
0

Output when using go test

When using go test to run godog features as described in the readme (using
TestMain), when the tests are successful, I don't get any output about which
features / steps are run in case of success, but I do get output for example
from a gin http server running as part of the test suite.

Is this intended behavior?

godog binary should support -h and/or --help

As a user I would like to see what options I can pass to a binary so that I don't need to remember them all.

Usually this is accomplished by accepting -h or --help as parameters.

Test fails with pretty formatter when using background and scenario outline together

I have the following feature file

Feature: Prove that there is an error with the pretty formatter
  Blabla
  Blabla
  Blabla

  Background:
    Given the following customers exist
      | ID | flag           | number        |
      | 1  | true           | 0             |
      | 2  | true           | 1             |


  Scenario Outline: Add two numbers
    Given I have number <a>
    And I have another number <b>
    When I add them together
    Then I should receive <c>

    Examples:
      | a | b | c |
      | 1 | 2 | 3 |
      | 1 | 2 | 3 |
      | 1 | 2 | 3 |
      | 1 | 2 | 3 |
      | 1 | 2 | 3 |
      | 1 | 2 | 3 |
      | 1 | 2 | 3 |

And a dummy implementation of test

package main

import (
    "gopkg.in/cucumber/gherkin-go.v3"
    "github.com/DATA-DOG/godog"
)

func theFollowingCustomersExist(arg1 *gherkin.DataTable) error {
    return nil
}

func iHaveNumber(arg1 int) error {
    return nil
}

func iHaveAnotherNumber(arg1 int) error {
    return nil
}

func iAddThemTogether( ) error {
    return nil
}

func iShouldReceive(arg1 int) error {
    return nil
}

func featureContext(s *godog.Suite) {
    s.Step(`^the following customers exist$`, theFollowingCustomersExist)
    s.Step(`^I have number (\d+)$`, iHaveNumber)
    s.Step(`^I have another number (\d+)$`, iHaveAnotherNumber)
    s.Step(`^I add them together$`, iAddThemTogether)
    s.Step(`^I should receive (\d+)$`, iShouldReceive)
}

When I run test with -f progress everything passes

➜  features godog -f progress  scenario_outline_and_background_error.feature
................................... 35


7 scenarios (7 passed)
35 steps (35 passed)
741.667µs

Using pretty formatter there is a weird failure:

➜  features godog -f pretty scenario_outline_and_background_error.feature   
Feature: Prove that there is an error with the pretty formatter
  Blabla
  Blabla
  Blabla

  Background: 
    Given the following customers exist # main.theFollowingCustomersExist
      | ID | flag | number |
      | 1  | true | 0      |
      | 2  | true | 1      |

  Scenario Outline: Add two numbers # scenario_outline_and_background_error.feature:13
    Given I have number <a>         # main.iHaveNumber
    And I have another number <b>   # main.iHaveAnotherNumber
    When I add them together        # main.iAddThemTogether
    Then I should receive <c>       # main.iShouldReceive

    Examples: 
      | a | b | c |
      | 1 | 2 | 3 |
      | 1 | 2 | 3 |
      | 1 | 2 | 3 |
      | 1 | 2 | 3 |
      | 1 | 2 | 3 |
      | 1 | 2 | 3 |
      | 1 | 2 | 3 |

--- Failed scenarios:

    scenario_outline_and_background_error.feature:15

7 scenarios (6 passed, 1 failed)
36 steps (35 passed, 1 failed)
779.458µs

If you have only 4 examples, the pretty formatter works as expected

Using go 1.7

go version
go1.7 darwin/amd64

Translation support

should be solved by #6

  • create translation files
  • translate gherkin token keywords
  • need to be able to run specific features with different languages

recompile and link dependent packages with test files

Currently godog builds a test file from current directory _.go file sources. It may be possible to build dependent packages with __test.go* files and link them including a dependent package suite contexts for godog.
It may require some hard work to achieve this, but very useful to have in the future, instead of running godog per each package.

Getting "imported and not used" errors when I try to run tests for a main package

I have a feature and test file in the same directory as the main package for an application that I wanted to test, but when I run godog . it fails with a bunch of "imported and not used" errors.
One for each the import statements.

From looking at the code it seems there is an issue with the merge function where it does not remove all of the imports, which were needed for my main function.

In my case I have a single main function like your cmd/godog package which calls library type package functions but does some flags type parsing.

If I move the feature file and its test file to another directory it works, my use case is for running api tests.

I have been able to re-create by making two alterations to your api example @ https://github.com/DATA-DOG/godog/blob/master/examples/api/api.go

  1. Add import "os"
  2. Add the following at the top of the main function - serves no purpose, just to illustrate the failure
    fmt.Println(os.Getenv("PATH"))

Since the main method is removed and it does not remove the "os" import I get

/tmp/1459347300796577005godog.go:11: imported and not used: "os"

Thanks in advance
Pat

Panic of fmt pretty

Hi,

The formatter pretty panics when having the following step:
s.Step(^there are( not)? (\d+) godogs$, thereAreGodogs)

Stack trace of the panic is:

panic: runtime error: slice bounds out of range

goroutine 1 [running]:
panic(0x208d80, 0xc420010130)
        /usr/local/Cellar/go/1.7.4_2/libexec/src/runtime/panic.go:500 +0x1a1
github.com/DATA-DOG/godog.(*pretty).printStep(0xc4201248c0, 0xc4201063c0, 0xc420106500, 0x2629b8)
        /Users/Dogild/apomux/workspace/code/go/src/github.com/DATA-DOG/godog/fmt_pretty.go:224 +0x358
github.com/DATA-DOG/godog.(*pretty).printStepKind(0xc4201248c0, 0xc42010d1c0)
        /Users/Dogild/apomux/workspace/code/go/src/github.com/DATA-DOG/godog/fmt_pretty.go:309 +0x340
github.com/DATA-DOG/godog.(*pretty).Failed(0xc4201248c0, 0xc4201063c0, 0xc420106500, 0x332660, 0xc4201057c0)
        /Users/Dogild/apomux/workspace/code/go/src/github.com/DATA-DOG/godog/fmt_pretty.go:347 +0x169
github.com/DATA-DOG/godog.(*Suite).runStep.func1(0xc4200adb88, 0xc4201181c0, 0xc4201063c0, 0xc420106500)
        /Users/Dogild/apomux/workspace/code/go/src/github.com/DATA-DOG/godog/suite.go:234 +0xbd
github.com/DATA-DOG/godog.(*Suite).runStep(0xc4201181c0, 0xc4201063c0, 0x0, 0x0, 0x332660, 0xc4201057c0)
        /Users/Dogild/apomux/workspace/code/go/src/github.com/DATA-DOG/godog/suite.go:244 +0x17a
github.com/DATA-DOG/godog.(*Suite).runSteps(0xc4201181c0, 0xc420108d80, 0x3, 0x4, 0x0, 0x0, 0xc4201030e0, 0x21)
        /Users/Dogild/apomux/workspace/code/go/src/github.com/DATA-DOG/godog/suite.go:250 +0x7d
github.com/DATA-DOG/godog.(*Suite).runScenario(0xc4201181c0, 0xc420120580, 0x0, 0x17, 0xc42011a480)
        /Users/Dogild/apomux/workspace/code/go/src/github.com/DATA-DOG/godog/suite.go:367 +0x117
github.com/DATA-DOG/godog.(*Suite).runFeature(0xc4201181c0, 0xc420102de0)
        /Users/Dogild/apomux/workspace/code/go/src/github.com/DATA-DOG/godog/suite.go:342 +0x2f3
github.com/DATA-DOG/godog.(*Suite).run(0xc4201181c0)
        /Users/Dogild/apomux/workspace/code/go/src/github.com/DATA-DOG/godog/suite.go:173 +0xa9
github.com/DATA-DOG/godog.(*runner).run(0xc42010ce00, 0x4)
        /Users/Dogild/apomux/workspace/code/go/src/github.com/DATA-DOG/godog/run.go:61 +0xcb
github.com/DATA-DOG/godog.RunWithOptions(0x23c9a4, 0x4, 0x262a48, 0x0, 0x0, 0x0, 0x23d5f3, 0x6, 0x1, 0xc42000a2d0, ...)
        /Users/Dogild/apomux/workspace/code/go/src/github.com/DATA-DOG/godog/run.go:120 +0x3bc
github.com/DATA-DOG/godog.Run(0x23c9a4, 0x4, 0x262a48, 0xc4200001a0)
        /Users/Dogild/apomux/workspace/code/go/src/github.com/DATA-DOG/godog/run.go:149 +0x1c7
main.main()
        /var/folders/m4/xc317mcn10z87p6h40wrj0m80000gn/T/go-build207215723/github.com/DATA-DOG/godog/examples/godogs/_test/_testmain.go:14 +0x42

It looks like the method FindStringSubmatchIndex returns an array with some -1 values, which causes the slice of bounds.

To reproduce, modify the example in examples/godogs, with

func FeatureContext(s *godog.Suite) {
	s.Step(`^there are( not)? (\d+) godogs$`, thereAreGodogs)

And

func iEat(grammar string, num int) error {
	if Godogs < num {

Panic in pretty formatter when using scenario outline and background together

Given this feature file

Feature: Prove that there is an error with the pretty formatter
  Blabla
  Blabla
  Blabla

  Background:
    Given the following customers exist
      | ID | flag           | number        |
      | 1  | true           | 0             |
      | 2  | true           | 1             |


  Scenario Outline: Add two numbers
    Given I have number <a>
    And I have another number <b>
    When I add them together
    Then I should receive <c>

    Examples:
    | a | b | c |
    | 1 | 2 | 3 |
    | 1 | 2 | 3 |
    | 1 | 2 | 3 |
    | 1 | 2 | 3 |
    | 1 | 2 | 3 |
    | 1 | 2 | 3 |
    | 1 | 2 | 3 |

When I run godog with pretty format it panics. Other formats like progress generates the missing code needed to implement this feature file.

 godog -f pretty scenario_outline_and_background_error.feature
Feature: Prove that there is an error with the pretty formatter
  Blabla
  Blabla
  Blabla

  Background: 
    Given the following customers exist
      | ID | flag | number |
      | 1  | true | 0      |
      | 2  | true | 1      |

  Scenario Outline: Add two numbers # scenario_outline_and_background_error.feature:13
    Given I have number <a>
    And I have another number <b>
    When I add them together
    Then I should receive <c>

    Examples: 
      | a | b | c |
      | 1 | 2 | 3 |
      | 1 | 2 | 3 |
      | 1 | 2 | 3 |
      | 1 | 2 | 3 |
      | 1 | 2 | 3 |
      | 1 | 2 | 3 |
      | 1 | 2 | 3 |
panic: runtime error: index out of range

goroutine 17 [running]:
panic(0x1ed520, 0xc4200100a0)
    /usr/local/opt/go/libexec/src/runtime/panic.go:500 +0x1a1
github.com/DATA-DOG/godog.(*pretty).printOutlineExample(0xc42011c000, 0xc420132000)
    /Users/andras.laczi/golang/src/github.com/DATA-DOG/godog/fmt_pretty.go:186 +0x1093
github.com/DATA-DOG/godog.(*pretty).printStepKind(0xc42011c000, 0xc4200ff700)
    /Users/andras.laczi/golang/src/github.com/DATA-DOG/godog/fmt_pretty.go:286 +0x768
github.com/DATA-DOG/godog.(*pretty).Undefined(0xc42011c000, 0xc4200f4c80)
    /Users/andras.laczi/golang/src/github.com/DATA-DOG/godog/fmt_pretty.go:326 +0x15b
github.com/DATA-DOG/godog.(*Suite).runStep(0xc42011e0e0, 0xc4200f4c80, 0x303520, 0xc4200fa0f0, 0x0, 0x0)
    /Users/andras.laczi/golang/src/github.com/DATA-DOG/godog/suite.go:201 +0x344
github.com/DATA-DOG/godog.(*Suite).runSteps(0xc42011e0e0, 0xc420136960, 0x4, 0x4, 0x303520, 0xc4200fa0f0, 0x303520, 0xc4200fa0f0)
    /Users/andras.laczi/golang/src/github.com/DATA-DOG/godog/suite.go:245 +0x7d
github.com/DATA-DOG/godog.(*Suite).runOutline(0xc42011e0e0, 0xc420132000, 0xc4201101e0, 0x2d, 0x8)
    /Users/andras.laczi/golang/src/github.com/DATA-DOG/godog/suite.go:309 +0x747
github.com/DATA-DOG/godog.(*Suite).runFeature(0xc42011e0e0, 0xc4200f9e60)
    /Users/andras.laczi/golang/src/github.com/DATA-DOG/godog/suite.go:335 +0x260
github.com/DATA-DOG/godog.(*Suite).run(0xc42011e0e0)
    /Users/andras.laczi/golang/src/github.com/DATA-DOG/godog/suite.go:169 +0xa9
github.com/DATA-DOG/godog.(*runner).run.func1(0xc4200f43c0, 0xc4200fb09e, 0xc4200f9e60)
    /Users/andras.laczi/golang/src/github.com/DATA-DOG/godog/run.go:30 +0x12e
created by github.com/DATA-DOG/godog.(*runner).run
    /Users/andras.laczi/golang/src/github.com/DATA-DOG/godog/run.go:36 +0xa7
exit status 2

If you remove the background section the pretty formatter works as expected.

Using go 1.7

go version go1.7 darwin/amd64

Auto-generated snippets with "." in it is wrong - double escaped

.feature file:

Then there should be an event created on "GaddCommander" in Customer.io with the contents:
      """
        ...
      """

Generated snippet:

func thereShouldBeAnEventCreatedOninCustomerioWithTheContents(arg1 string, arg2 *gherkin.DocString) error {
    return godog.ErrPending
}

func featureContext(s *godog.Suite) {
    s.Step(`^there should be an event created on "([^"]*)" in Customer\\.io with the contents:$`, thereShouldBeAnEventCreatedOninCustomerioWithTheContents)
}

Expected: Customer\\.io should be Customer\.io

I am logging this for now as FYI. I might create a PR for it later if I have the time.

reflect: Call using *gherkin.DocString as type *gherkin.DocString

After updating to latest godog all multiline string text started failing

eg. Feature

    When  I publish a message:
      """
      {
          "data": {
              "point1": 1,
              "point2": 2,
              "point3": 3
          }
      }
      """

Step Definition

func iPublishAMessage(input *gherkin.DocString) error {
    log.Println("Gherking", input, input.Content)
        //... Do publish
    return nil

}

The following error appears
reflect: Call using *gherkin.DocString as type *gherkin.DocString

Is there something wrong here?

Json formatter

For custom output transformations a unified format may be useful..

--stop-on-failure doesn't stop

I recently updated to v0.4.3 and noticed that adding the --stop-on-failure flag doesn't stop executing when a scenario fails.

Feedback: test compile errors could give more useful info

Example:

$ godog .
# command-line-arguments
/tmp/1461229988472036489godog.go:70: no new variables on left side of :=
$

Would be nicer with:

my_test.go:50: no new variables on left side of :=

Perhaps check how go test does it.

Cannot get to work in project with GB

Hi,
This looks very good, thanks for open sourcing it!

In a project using GB, I cannot get Godog to find my _test.go files. Am I doing something wrong, or does it not work yet with GB-projects? Do you know of any workarounds? I think this should give enough info:

vagrant@fishbrain-bonito:~/bonito$ ls features/ src/github.com/fishbrain/bonito/cmd/bonito/
features/:
customerio.feature

src/github.com/fishbrain/bonito/cmd/bonito/:
main.go  main_test.go
vagrant@fishbrain-bonito:~/bonito$ cat src/github.com/fishbrain/bonito/cmd/bonito/main_test.go
package main

import "github.com/DATA-DOG/godog"

func thereAreGodogs(arg1 int) error {
  return godog.ErrPending
}

func iEat(arg1 int) error {
  return godog.ErrPending
}

func thereShouldBeRemaining(arg1 int) error {
  return godog.ErrPending
}

func featureContext(s *godog.Suite) {
  s.Step(`^there are (\d+) godogs$`, thereAreGodogs)
  s.Step(`^I eat (\d+)$`, iEat)
  s.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
}
vagrant@fishbrain-bonito:~/bonito$ GOPATH=`pwd`/:`pwd`/vendor/:${GOPATH} godog
Feature: eat godogs
  In order to be happy
  As a hungry gopher
  I need to be able to eat godogs

  Scenario: Eat 5 out of 12          # features/customerio.feature:6
    Given there are 12 godogs
    When I eat 5
    Then there should be 7 remaining

1 scenarios (1 undefined)
3 steps (3 undefined)
7.058498ms

You can implement step definitions for undefined steps with these snippets:

func thereAreGodogs(arg1 int) error {
  return godog.ErrPending
}

func iEat(arg1 int) error {
  return godog.ErrPending
}

func thereShouldBeRemaining(arg1 int) error {
  return godog.ErrPending
}

func featureContext(s *godog.Suite) {
  s.Step(`^there are (\d+) godogs$`, thereAreGodogs)
  s.Step(`^I eat (\d+)$`, iEat)
  s.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
}
vagrant@fishbrain-bonito:~/bonito$ GOPATH=`pwd`/:`pwd`/vendor/:${GOPATH} godog -d
there were no contexts registered, could not find any step definition..

I would be open to submitting a PR if you can give any pointers.

Concurrent runner for non pretty formatter

We can and should run features concurrently, but probably not for pretty format.
Add a concurrency option, which defaults to 1. Not all suites will support that..

Best would be to allow run any format with a concurrency level provided by -c, --concurrency=1 flag.
For pretty format, keep output per feature and flush it when a feature has finished running scenarios (this behavior would only be with a higher than 1 concurrency level).

It would be too complex to handle contexts and variables which may be written synchronously. Will use the approach like beflash but after the #4 is done.

Pretty format index out of range with Scenario Outline and Background step

Pretty format works fine with Scenario Outlines in the feature file unless there is one (or more) Background steps. When I change the godogs example to look like this:

Feature: eat godogs with an outline
In order to be happy
As a hungry gopher
I need to be able to eat different amounts of godogs

Background: Start with a decent amount
Given there are 12 godogs

Scenario Outline: Eat various numbers of godogs
When I eat
Then there should be remaining

Examples: Leaving some behind
  | amount | left |
  | 5      | 7    |
  | 8      | 4    |
  | 11     | 1    |

Examples: Eating them all
  | amount | left |
  | 12     | 0    |

And then run godog against it with the default (pretty) formatter, I get this panic:

C:\Users\David\Documents\development\godog_outline>bin\godog.exe src\godog_outline.feature
Feature: eat godogs with an outline
In order to be happy
As a hungry gopher
I need to be able to eat different amounts of godogs

Background: Start with a decent amount

Scenario Outline: Eat various numbers of godogs # src\godog_outline.feature:9
When I eat
Then there should be remaining

Examples: Leaving some behind
  | amount | left |
  | 5      | 7    |
  | 8      | 4    |
  | 11     | 1    |

panic: runtime error: index out of range

goroutine 17 [running]:
github.com/DATA-DOG/godog.(_pretty).printOutlineExample(0xc08209c000, 0xc0820bc000)
c:/Users/David/Documents/development/godog_outline/src/github.com/DATA-DOG/godog/fmt_pretty.go:190 +0x195f
github.com/DATA-DOG/godog.(_pretty).printStepKind(0xc08209c000, 0xc082084e40)
c:/Users/David/Documents/development/godog_outline/src/github.com/DATA-DOG/godog/fmt_pretty.go:257 +0x132
github.com/DATA-DOG/godog.(_pretty).Undefined(0xc08209c000, 0xc0820884b0)
c:/Users/David/Documents/development/godog_outline/src/github.com/DATA-DOG/godog/fmt_pretty.go:297 +0x207
github.com/DATA-DOG/godog.(_Suite).runStep(0xc08209e0e0, 0xc0820884b0, 0x860028, 0xc08208a100, 0x0, 0x0)
c:/Users/David/Documents/development/godog_outline/src/github.com/DATA-DOG/godog/suite.go:201 +0xb5
github.com/DATA-DOG/godog.(_Suite).runSteps(0xc08209e0e0, 0xc0820ca310, 0x2, 0x2, 0x860028, 0xc08208a100, 0x860028, 0xc08208a100)
c:/Users/David/Documents/development/godog_outline/src/github.com/DATA-DOG/godog/suite.go:245 +0xc1
github.com/DATA-DOG/godog.(_Suite).runOutline(0xc08209e0e0, 0xc0820bc000, 0xc082092240, 0x0, 0x0)
c:/Users/David/Documents/development/godog_outline/src/github.com/DATA-DOG/godog/suite.go:298 +0x74e
github.com/DATA-DOG/godog.(_Suite).runFeature(0xc08209e0e0, 0xc082083700)
c:/Users/David/Documents/development/godog_outline/src/github.com/DATA-DOG/godog/suite.go:324 +0x351
github.com/DATA-DOG/godog.(_Suite).run(0xc08209e0e0)
c:/Users/David/Documents/development/godog_outline/src/github.com/DATA-DOG/godog/suite.go:169 +0xe6
github.com/DATA-DOG/godog.(_runner).run.func1(0xc082088320, 0xc08208b940, 0xc082083700)
c:/Users/David/Documents/development/godog_outline/src/github.com/DATA-DOG/godog/run.go:30 +0x14f
created by github.com/DATA-DOG/godog.(_runner).run
c:/Users/David/Documents/development/godog_outline/src/github.com/DATA-DOG/godog/run.go:36 +0xd9

goroutine 1 [semacquire]:
sync.runtime_Semacquire(0xc08208832c)
c:/go/src/runtime/sema.go:43 +0x2d
sync.(_WaitGroup).Wait(0xc082088320)
c:/go/src/sync/waitgroup.go:126 +0xbb
github.com/DATA-DOG/godog.(_runner).run(0xc082088320, 0xc082088300)
c:/Users/David/Documents/development/godog_outline/src/github.com/DATA-DOG/godog/run.go:38 +0x109
github.com/DATA-DOG/godog.Run(0x6b2238)
c:/Users/David/Documents/development/godog_outline/src/github.com/DATA-DOG/godog/run.go:101 +0x82d
main.main()
C:/Users/David/AppData/Local/Temp/1453177288086389100godog.go:9 +0x2a
exit status 2


We are working on a fix; looks like the problem is in the counting of steps.

As an aside, I have a JUnit-style formatter that I wrote so that we can run our tests in CI. It works OK with outlines so this bug isn't holding us up. Any interest in having me add the JUnit formatter in a pull request? It seems to go along with the comments in bug #4.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.