Repository navigation
feat: print the scenario narrative without source prefixes - #8
Merged
Merged
Conversation
A running scenario now writes its narrative through testing.T.Output
instead of Log. Lines no longer repeat the Feature call site as a
prefix; each ends with the file and line that declared it:
Scenario: two books cost 2000 # cart_test.go:34
Given an empty cart # cart_test.go:35
When the customer adds two books # cart_test.go:38
Then the total is 2000 # cart_test.go:41
Rules and the Outline print on one line above the title. Background
takes a colon. The Setup line is removed. The stop report follows the
failure directly and names its source as file:line. Skip messages
capitalise the node kind.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes
The output of a running scenario (shown with
-vor on failure) changes format.Before:
After:
bdd.Featurecall site as a prefix. Each line ends with the file and line that declared it: the scenario, thebdd.Casefor an Outline example, and each hook and step.Rule: outer > Rule: inner.Backgroundprints with a colon (Background: an empty cart); the other keywords do not.Setup:line is removed. A setup failure is still reported asstopped in Setup.file:lineinstead of an absolute path.bdd: Scenario: ... pending: ...(wasbdd: scenario: ...).Anything that parses the old log lines will need updating. Exported API, generated test names and lifecycle order are unchanged. Lines logged by user code keep the standard
file:line:prefix and still appear under the operation that logged them.Why
Every framework line had the same prefix, the
bdd.Featurecall line, which told the reader nothing, and the output never said where a step was declared unless the scenario failed.How
The narrative is written through
testing.T.Output()(Go 1.25+; the module requires 1.27), which uses the test's output stream without adding a source prefix. The stop report uses the same stream from adefer, replacing theCleanupit needed when it went throughLog. New file:narrative.go.Verification
Run locally on Go 1.27.3, darwin/arm64:
gofmt -l .reports nothing;go vet ./...is clean;go test -race -count=1 ./...passes.TestNarrativeNamesEachLineWithItsDeclarationSitechecks each line's declaration site againsttesting's own attribution of a marker logged on that line, plus line order, interleaving with user logs, and column alignment.Helperon the leaf closure, narrative line printed after the operation) each failed a test.Where to look
narrative.goandfeaturePlan.runLeafinsuite.go.#column. This is cosmetic.Beforehooks are still listed, asBefore hook # file:line.