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

Rule is not supported #440

Closed
michaelsauter opened this issue Nov 16, 2021 · 0 comments · Fixed by #480
Closed

Rule is not supported #440

michaelsauter opened this issue Nov 16, 2021 · 0 comments · Fixed by #480

Comments

@michaelsauter
Copy link

What version of godog are you using?

> godog version: 0.12.2

What version of Go are you using?

> go version: 1.16

What did you do?

Given a feature file like the following:

Feature: simple feature
  simple feature description

  Rule: simple rule
    Example: simple example

Running godog will panic:

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x70 pc=0x11cc0c6]

goroutine 34 [running]:
github.com/cucumber/godog/internal/formatters.(*Pretty).printStep(0xc0002020d0, 0xc000250360, 0xc000208680)
        /Users/michaelsauter/go/pkg/mod/github.com/cucumber/godog@v0.12.2/internal/formatters/fmt_pretty.go:384 +0xf26

Additional context

I've looked a bit into the source code and added the following test to pretty.feature:

  Scenario: Support of Feature Plus Rule Node
    Given a feature "features/simple.feature" file:
    """
        Feature: simple feature
            simple feature description

        Rule: simple rule
            Scenario: simple scenario
                simple scenario description
    """
    When I run feature suite with formatter "pretty"
    Then the rendered output will be as follows:
    """
      Feature: simple feature
        simple feature description

        Rule: simple rule # features/simple.feature:3

        Scenario: simple scenario # features/simple.feature:4

      1 scenarios (1 undefined)
      No steps
      0s
    """

This lead me to apply the following fix in fmt_pretty.go:

func (f *Pretty) scenarioLengths(pickle *messages.Pickle) (scenarioHeaderLength int, maxLength int) {
	feature := f.Storage.MustGetFeature(pickle.Uri)
	astRule := feature.FindRule(pickle.AstNodeIds[0])
	astScenario := feature.FindScenario(pickle.AstNodeIds[0])
	astBackground := feature.FindBackground(pickle.AstNodeIds[0])

	if astScenario != nil {
		scenarioHeaderLength = f.lengthPickle(astScenario.Keyword, astScenario.Name)
		maxLength = f.longestStep(astScenario.Steps, scenarioHeaderLength)
	}

	if astBackground != nil {
		maxLength = f.longestStep(astBackground.Steps, maxLength)
	}
	if astRule != nil {
		for _, rc := range astRule.Children {
			if rc.Scenario != nil {
				maxLength = f.longestStep(rc.Scenario.Steps, maxLength)
			} else if rc.Background != nil {
				maxLength = f.longestStep(rc.Scenario.Steps, maxLength)
			}
		}
	}

	return scenarioHeaderLength, maxLength
}

... but there are many more issues in the pretty formatter, plus I realized all the other formatters would need to be fixed, too. Seems like supporting rules will be quite the effort. Are there plans to do this already?

dumpsterfireproject added a commit to dumpsterfireproject/godog that referenced this issue May 30, 2022
dumpsterfireproject added a commit to dumpsterfireproject/godog that referenced this issue May 30, 2022
dumpsterfireproject added a commit to dumpsterfireproject/godog that referenced this issue Jun 10, 2022
dumpsterfireproject added a commit to dumpsterfireproject/godog that referenced this issue Jun 10, 2022
mattwynne pushed a commit that referenced this issue Jun 17, 2022
* Pretty Print when using rules (#440)

* Pretty Print when using rules (#440)

* fix a few formatting mistakes (#440)

* added test with rule and scenario outline (#440)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant