Skip to content

Commit

Permalink
feat: outputting literal step text as steps as executed when using ve…
Browse files Browse the repository at this point in the history
…rbose go test output (#20)
  • Loading branch information
0xste committed Nov 24, 2023
1 parent 4e290f5 commit d39ed9c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ tests. `Runner.ShortTags` method can be used to select a set of tags to
* `Before()`, `After()`, `BeforeStep()`, or and `AfterStep()` can be used to register custom hooks.
* `Tags` and `ShortTags` can be used with tag expressions as described above.
* `NonParallel()` disables parallel tests.
* `--verbose` or `-v` with `go test` will emit the current test step definition to stdout while your tests are running, this is useful for debugging failing tests.

### Property-based testing using Rapid

Expand Down
2 changes: 1 addition & 1 deletion run_doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (r *docRunner) runDoc(t *testing.T) {
t.Parallel()
}

r.runScenario(t, pickle)
r.runScenario(t, pickle, testing.Verbose())
})
}
}
5 changes: 4 additions & 1 deletion run_scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/regen-network/gocuke/internal/tag"
)

func (r *docRunner) runScenario(t *testing.T, pickle *messages.Pickle) {
func (r *docRunner) runScenario(t *testing.T, pickle *messages.Pickle, verbose bool) {
t.Helper()

tags := tag.NewTagsFromPickleTags(pickle.Tags)
Expand Down Expand Up @@ -57,6 +57,7 @@ func (r *docRunner) runScenario(t *testing.T, pickle *messages.Pickle) {
t: t,
pickle: pickle,
stepDefs: stepDefs,
verbose: verbose,
}).runTestCase()
})
} else {
Expand All @@ -65,6 +66,7 @@ func (r *docRunner) runScenario(t *testing.T, pickle *messages.Pickle) {
t: t,
pickle: pickle,
stepDefs: stepDefs,
verbose: verbose,
}).runTestCase()
}
}
Expand All @@ -76,6 +78,7 @@ type scenarioRunner struct {
pickle *messages.Pickle
stepDefs []*stepDef
step *messages.PickleStep
verbose bool
}

func (r *scenarioRunner) runTestCase() {
Expand Down
4 changes: 4 additions & 0 deletions run_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,9 @@ func (r *scenarioRunner) runStep(step *messages.PickleStep, def *stepDef) {
}
}

if r.verbose {
r.t.Logf("Step: %s", step.Text)
}

def.theFunc.Call(values)
}

0 comments on commit d39ed9c

Please sign in to comment.