Skip to content

fix(internal/harness): size the report columns to the results - #358

Open
OmarAlJarrah wants to merge 1 commit into
mainfrom
fix/harness-report-column-widths
Open

fix(internal/harness): size the report columns to the results#358
OmarAlJarrah wants to merge 1 commit into
mainfrom
fix/harness-report-column-widths

Conversation

@OmarAlJarrah

Copy link
Copy Markdown
Member

Summary

harness.Report laid its table out with printf field widths chosen by eye:

_, _ = fmt.Fprintf(&b, "%-40s %-20s %s\n", r.Spec, r.Outcome, r.Detail)

r.Spec is a spec path, and 168 of the 177 tracked testdata paths are longer
than 40 characters, so the outcome was not a column at all — it landed wherever
the path happened to end:

testdata/conformance/openapi/allof-boolean-branch.yaml ok
testdata/conformance/openapi/allof-inheritance.yaml ok

The trailing %-20s also padded every line with spaces the report had no use
for, since most lines have no Detail to follow them.

Both widths are now measured from the results being rendered, the way the CLI's
command column is derived rather than declared. Counting is in runes, which is
the unit fmt's %-*s pads in — a byte count would over-pad a non-ASCII path.
A line whose Detail is empty stops at its outcome instead of padding out to a
column with nothing to its right; that is also what sizes the outcome column,
since only rows carrying a Detail have a neighbour to line up against.

After:

testdata/conformance/openapi/allof-boolean-branch.yaml          ok
testdata/conformance/openapi/allof-inheritance.yaml             ok

Test plan

Three new tests in internal/harness, each confirmed to redden against the
defect it names rather than accepted because it went green:

  • TestReport_ColumnsAreSizedToTheResults — the outcome and detail columns
    start at the same offset on a long-path line and a short-path line, and the
    spec column is exactly the longest spec wide. Restoring %-40s %-20s %s
    fails it on both offsets.
  • TestReport_LinesAreNotPaddedPastTheirLastColumn — no line carries padding
    after its last column. Restoring the old format fails it.
  • TestReport_WidthsAreCountedInRunes — an eight-rune, eleven-byte path is
    padded to eight. Swapping utf8.RuneCountInString for len fails it with
    expected: 9, actual: 12.

columnStart fails when a column is absent, so two missing columns cannot
compare equal and assert nothing.

Full gate green: gofmt, go vet ./..., golangci-lint run (0 issues),
go build ./..., ./scripts/check-coverage.sh (all 4952 statements covered).

Closes #309

Report laid its table out with printf field widths chosen by eye -- %-40s
for the spec and %-20s for the outcome. Nearly every path in testdata is
longer than 40 characters (168 of 177 tracked paths), so the outcome was
not a column at all: it landed wherever the path happened to end. The
trailing %-20s also padded every line with spaces nothing followed.

Both widths are now measured from the results being rendered, in runes,
which is the unit fmt's %-*s pads in. A line whose Detail is empty stops
at its outcome rather than padding out to a column with nothing to its
right, which is also what sizes the outcome column: only rows carrying a
Detail have a neighbour to line up against.
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 this pull request may close these issues.

internal/harness: Report pads to hardcoded widths nearly every spec path exceeds

1 participant