Skip to content

Rule is not supported #440

@michaelsauter

Description

@michaelsauter

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions