From d39ed9c8c42f4283a735e38dd2e818b43a37f8de Mon Sep 17 00:00:00 2001 From: Stefano Date: Fri, 24 Nov 2023 04:26:42 +0000 Subject: [PATCH] feat: outputting literal step text as steps as executed when using verbose go test output (#20) --- README.md | 1 + run_doc.go | 2 +- run_scenario.go | 5 ++++- run_step.go | 4 ++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 94ccc47..d5d5f13 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/run_doc.go b/run_doc.go index bbcc629..e65999e 100644 --- a/run_doc.go +++ b/run_doc.go @@ -31,7 +31,7 @@ func (r *docRunner) runDoc(t *testing.T) { t.Parallel() } - r.runScenario(t, pickle) + r.runScenario(t, pickle, testing.Verbose()) }) } } diff --git a/run_scenario.go b/run_scenario.go index b07ef41..bb1b78b 100644 --- a/run_scenario.go +++ b/run_scenario.go @@ -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) @@ -57,6 +57,7 @@ func (r *docRunner) runScenario(t *testing.T, pickle *messages.Pickle) { t: t, pickle: pickle, stepDefs: stepDefs, + verbose: verbose, }).runTestCase() }) } else { @@ -65,6 +66,7 @@ func (r *docRunner) runScenario(t *testing.T, pickle *messages.Pickle) { t: t, pickle: pickle, stepDefs: stepDefs, + verbose: verbose, }).runTestCase() } } @@ -76,6 +78,7 @@ type scenarioRunner struct { pickle *messages.Pickle stepDefs []*stepDef step *messages.PickleStep + verbose bool } func (r *scenarioRunner) runTestCase() { diff --git a/run_step.go b/run_step.go index 70b2116..cfa5d3a 100644 --- a/run_step.go +++ b/run_step.go @@ -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) }