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

support a "go test" format #267

Open
slashfoo opened this issue Mar 21, 2020 · 3 comments
Open

support a "go test" format #267

slashfoo opened this issue Mar 21, 2020 · 3 comments
Labels
⚡ enhancement Request for new functionality

Comments

@slashfoo
Copy link

Desired feature description
I use :GoTest from within vim and using the plugin https://github.com/fatih/vim-go; like with other tools (e.g. :make command in vim), they feed from the output having a specific format to populate a list of errors and provide navigation to erroring files:linenumber combinations.

In specific, if I run godog from within go test, it'd be ideal if it'd output lines that matched the expected from the go test command and keep my workflow intact.

Example of failing-test output of a plain go test -v run:

=== RUN   TestSet
    TestSet: main_test.go:24: got = 3; want = 9
--- FAIL: TestSet (0.00s)
FAIL
exit status 1
FAIL    test_proj       0.038s

Desired solution description

Having this in my _test.go file:

...
var opt = godog.Options{Output: colors.Colored(os.Stdout),
	Strict: true,
	Format: "pretty"}
...
func TestMain(m *testing.M) {
...
	for _, arg := range os.Args[1:] {
		if arg == "-test.v=true" { // go test transforms -v option
			opt.Format = "go-test-v"
			break
		}
	}
...
	status = godog.RunWithOptions("test_proj", func(s *godog.Suite) {
		FeatureContext(s)
	}, opt)
...
}
...
func FeatureContext(s *godog.Suite) {
	s.Step(`^there are (\d+) hotdogs$`, set)
	s.Step(`^I eat (\d+)$`, subtract)
	s.Step(`^there should be (\d+) remaining`, checkRemaining)  // this is line:52

	s.BeforeScenario(func(interface{}) {
		Hotdogs = 0
	})
}

And when running go test -v see the output in the desired format, something like:

--- FAIL: TestSuite (0.00s)
    main_test.go:52: Expected 7 hotdogs, but there are only 6
FAIL
exit status 1
FAIL    test_proj       0.051s

Alternatives considered

  • not running with godog.RunWithOptions and instead using a wrapper that'd contain output in the expected format.

An example command for generating output approximating the expected:

godog --format=cucumber | jq -r '.[] | .elements[].steps[] | select(.result.status == "failed") | "    \(.keyword): \(.match.location): \(.result.error_message)"'

This is not an optimal solution as it brings me to the matching method for the step, not to the line in the _test.go where the godog.Suite is configured, which I could then use to navigate around in the code.

@slashfoo slashfoo added the ⚡ enhancement Request for new functionality label Mar 21, 2020
@mxygem
Copy link
Member

mxygem commented Apr 15, 2020

Hey @slashfoo - This is one of the few nonstandard Cucumber outputs that I'd like to officially support, but I can't promise any sort of timeline on when/if it'll be implemented. Our team is small, time-starved, and I assume trying to do what we can to make it through the world's craziness right now.

If you're open to and able to work on this yourself, I'd be happy to review the changes. If not, that's totally fine, too! 😄

@slashfoo
Copy link
Author

@jaysonesmith I'm happy to read that there's at least interest in officially supporting it. I also have limited availability, but if I happen to make any progress before it ships, I'll be sure to tag this bug.

@lonnblad lonnblad modified the milestone: v0.11.0 Jun 23, 2020
@vearutop
Copy link
Member

Hello, please check if new way of running scenarios as subtests would help your case: https://github.com/cucumber/godog#subtests-of-testingt.

https://github.com/cucumber/godog/blob/v0.12.0-rc2/example_subtests_test.go#L28-L45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚡ enhancement Request for new functionality
Projects
None yet
Development

No branches or pull requests

4 participants