183 {input, expected} cases across 10 construct files under
tests/cases/, driven by a ~180-line std-only harness (==== / ----
format). Each case asserts formatting and idempotency; #SKIP parks
known formatter bugs and fails the suite once they start passing.
Documents four real formatter bugs found while deriving expected
output (block-comment re-indent non-idempotency, comment lifted out
of expression groups, closing block labels dropped, multi-instance
declaration layout) — parked as #SKIP, to be fixed in a follow-up
feature. Also adds rustfmt.toml matching the codebase style.
Dev: Opus agent; QA: Sonnet agent; review in
docs/features/case-tables/README.md.
Co-Authored-By: Claude Fable 5 <[email protected]>
case-tables
Goal
Give vfmt the backbone Verible's formatter has: a large table of small
text-in/text-out {input, expected} pairs, organized by construct, that runs
on every cargo test. Verible's formatter_test.cc is thousands of such
pairs and is where years of edge cases live; the existing snapshot suite in
tests/fixtures/ covers whole files well but is a poor place to pin down "what
exactly happens to this three-line construct". Each case asserts both
format(input) == expected and format(expected) == expected, so every pair
buys a formatting check and an idempotency check.
Assumptions
format_sourcetakes a complete source file, so every case input is a full compilation unit (module ... endmodule,package ... endpackage, ...). There is no fragment/statement-level entry point to test against.- Cases only exercise syntax the top-level
README.mdlists as supported. Nothing here depends on interfaces, classes, assertions-as-properties, etc. - Default
Config(2-space indent, 100 columns). No case varies the config; if configurable behavior needs coverage later, add a per-file header rather than a second directory. - A
#at the start of a line can only be a case header, never Verilog: a delay like#5is legal at statement level but never at the top level of a file, which is where every case input begins.
Handshakes
- Consumes
vlog_formatter::{format_source, Config}only. If the signature offormat_sourcechanges,tests/cases.rsneeds the same edit astests/fixtures.rs. - Consumes the runtime verification added by the correctness-safety-net
work (
src/verify.rs):format_sourcenow returnsErrwhen equivalence or convergence fails, and the harness reports that asformat failed: .... Cases that used to produce (wrong) output now produce an error instead — three of the bugs below are of that shape. - Promises nothing to other modules; nothing imports this test.
- Requests to other agents: none. All findings below are reported, not
fixed — formatter
src/is out of this feature's scope.
File format
One .cases file per construct area, under
crates/vlog_formatter/tests/cases/. Within a file:
# a short name for the case
module m;wire w;endmodule
----
module m;
wire w;
endmodule
====
# the next case
...
- A line that is exactly
====separates cases. The last case needs no trailing separator. - A line that is exactly
----separates input from expected output. - Lines starting with
#at the top of a case are its name (joined with spaces). Once a non-#, non-blank line is seen, the input has started and#is no longer special. - A case with a
#header line that starts withSKIP(written#SKIP ...;SKIPelsewhere in a name has no effect) is the parking lot for inputs the formatter gets wrong: the expected half holds the output we want. The harness asserts a#SKIPcase still fails — the moment the bug is fixed the suite demands the#SKIPline be deleted, turning the case into a live regression test. - Do not use bare
----or====lines inside case content (e.g. as an ASCII banner in a block comment) — they are always parsed as separators and will silently split the case at the wrong place. - Both halves are compared with a trailing newline, matching what
format_sourceproduces.
The harness (crates/vlog_formatter/tests/cases.rs, ~170 lines, std only)
discovers every *.cases file, parses it, and for each case asserts
format(input) == expected then format(expected) == expected. Failures are
collected (not aborted on the first one) and reported as
file:line [case name] plus a line-oriented diff (- expected, + got).
Status / TODO
- Harness
crates/vlog_formatter/tests/cases.rswith discovery,====/----parsing,#SKIPsupport, per-case diff reporting. module_headers.cases— 17 casesdeclarations.cases— 18 casesassignments.cases— 14 casesstatements.cases— 26 casesinstantiation.cases— 18 casesexpressions.cases— 26 casescomments.cases— 22 casesgenerate.cases— 12 casesfunctions_tasks.cases— 15 casestypedef.cases— 15 cases- TODO.md §5 "massive text-in/text-out table tests" checked off.
- Port more cases directly from Verible's
formatter_test.cc(only a thematic sample is covered so far; the count should grow by an order of magnitude). - Cases for
--indent/--line-lengthother than the defaults, once there is a way to express config in a case file. - Re-enable the four
#SKIPcases as the bugs below are fixed. - Close QA coverage gaps:
finalblocks, bare module-levelcase(without ageneratewrapper), aninitial fork ... joincase backing the style observation, comma-separated sensitivity lists, multipleimports in one module.
Suspected bugs (not fixed — out of scope for this feature)
1. Multi-line block comments are re-indented on every pass (idempotency violation, hard invariant #2). Highest severity: it breaks a documented hard invariant and makes any file with a banner comment inside a module body unformattable.
module m;
/*
* doc block
*/
wire w;
endmodule
Pass 1 produces * doc block (2 spaces of indent prepended to the original
1 space), pass 2 produces * doc block, pass 3 seven spaces — it grows
without bound. With runtime convergence checking in place this now fails
outright:
error: verification failed: formatting is not idempotent;
line 3 changed from " * doc block" to " * doc block"
The continuation lines of a block comment should be re-indented relative to
the comment's original opening column, not by prepending the current indent
to whatever the previous pass left. Parked as #SKIP in comments.cases.
2. A comment inside an expression is lifted out of its group instead of
forcing it to break. README.md states "A comment inside a group forces it
to break"; that holds for port lists, connection lists, case items and struct
members, but not for expression groups.
module m;
assign y = {
a, // high
b
};
endmodule
Before runtime verification existed this emitted assign y = {a, b}; // high
— the comment survived (invariant #3 held) but moved out of the concatenation
and changed meaning. Now it is rejected:
error: verification failed: token stream diverges at index 9:
input has comment `// high` at 3:2, output has identifier `b` at 2:18
The same happens for a comment inside parentheses ((a // hi\n + b)), inside a
call argument list (f(a, // hi\n b)), and inside an assignment pattern
('{a: 1, // hi\n b: 2}). Parked as #SKIP in comments.cases.
3. Closing block labels are dropped. endmodule : m is preserved, but
every other closing label is silently discarded:
| input | output |
|---|---|
initial begin : main ... end : main |
... end |
fork : f ... join : f |
... join |
function int f(); ... endfunction : f |
... endfunction |
task t; ... endtask : t |
... endtask |
package p; ... endpackage : p |
... endpackage |
This is token loss, so with runtime verification it is now a hard error
(token stream diverges ... input has symbol ':' ... output has keyword 'endmodule'). Parked as #SKIP in statements.cases; the opening label
(begin : main) is handled correctly and is covered by a passing case.
4. A declaration with several instances always breaks, and the continuation is not indented.
module m;
sub u0(.a(x)), u1(.a(y));
endmodule
gives
module m;
sub u0 (.a(x)),
u1 (.a(y));
endmodule
Two problems: the whole thing is 30 columns wide and should stay on one line,
and the continuation sits at the same indent as the head, so u1 reads as a
new statement. Parked as #SKIP in instantiation.cases with the one-line
form as the wanted output.
Style observations (kept as expected output — defensible, but worth a look)
-
Unpacked dimensions and instance-array ranges get a space before the bracket:
logic [7:0] mem [0:255];,sub u0 [3:0] (...). Verible writesmem[0:255]andu0[3:0]; packed dimensions after a type keyword do take a space in both. Whichever way this lands, it should be stated inREADME.mdnext to the "tight dimension expressions" rule. -
A long operator chain indents its first operand two columns less than the rest:
assign ready_signal = first_condition_name && second_condition_name && third_condition_name;A flat chain reads better all at one indent.
-
timeunit 1ns/1ps;becomestimeunit 1ns / 1ps;— the/there is a separator, not a division operator. -
initial begincuddles, butinitial forkdoes not:initialandforkend up on separate lines. -
A blank line between a leading comment and the item it documents is removed (
// between\n\nmodule b;→// between\nmodule b;). Reasonable, since the comment binds to the following item, but it is a silent change. -
typedef struct packed {...}always breaks one member per line even when it would fit; enums break only when they must.
Work log
2026-08-18 — dev agent
- Wrote
crates/vlog_formatter/tests/cases.rs. Chose the====/----plain-text format over one-file-per-case (thousands of tiny files) and over a Rust&[(&str, &str)]table (unreadable escaping for multi-line Verilog). The whole harness is one integration test that collects all failures before asserting, so a behavior change shows every affected case at once. - Added
#SKIP, which was not in the original plan, once the first genuinely-broken input turned up. Without it the choice would have been between committing a red test and losing the finding; with it, the wanted output is committed and the case flips green when the bug is fixed. - Derived every expected output by piping the input through
target/debug/vfmt -, then reviewed each one by hand against the "Style" section of the top-levelREADME.md. Four outputs failed that review and became the#SKIPcases; six more are recorded above as style observations where the output is defensible but debatable. - Mid-run the correctness-safety-net agent landed
src/verify.rs, which made bugs 1-3 hard errors instead of quietly wrong output. Rebuilt and re-derived every expected output against the new binary; no passing case changed. Confirmedverify.rsdeliberately whitelists the@*→@(*)spelling, so thealways @*case keeps@(*)as expected output. - 183 cases total, 179 asserted, 4
#SKIP.cargo testgreen,cargo clippy --all-targetsreports nothing fortests/cases.rs,cargo fmt --checkreports nothing fortests/cases.rs(it does report pre-existing diffs acrosssrc/files owned by other agents).
QA log
2026-08-18 — QA agent
Ran the full check suite, audited tests/cases.rs line by line with deliberate
probe .cases files (added, exercised, then deleted — none left in the
tree), spot-checked case output against the top-level README.md Style
section (read essentially every case across all 10 files, not just a
sample), and reproduced all four #SKIP bugs by temporarily stripping the
#SKIP prefix in the actual .cases files and re-running cargo test,
then restoring them byte-for-byte (diff confirmed clean).
Results
cargo test(full workspace): green.cases_tablereports 179 asserted (183 parsed − 4 skip), matching the claimed count exactly; independently recounted per-file with a script and got the same 17/18/14/26/18/26/22/12/ 15/15 = 183, 4 skip.cargo clippy --all-targets: 4 pre-existing warnings, none intests/cases.rs(format.rsdead_code,printer.rsmanual_repeat_n,parser.rsif_same_then_else x2). Confirmed viagrep -i cases.rson the clippy output.cargo fmt --check: 151 diff blocks acrosssrc/, none intests/cases.rs. Did not run in write mode.- Un-skipping all four
#SKIPcases at once and re-runningcargo test -p vlog_formatter --test casesreproduces exactly the four documented failures, with error text matching the README's bug write-ups verbatim (idempotency divergence at line 3, token-stream divergence at index 9/12, and the un-indented multi-instance continuation). Also reproduced each bug independently viatarget/debug/vfmt -on a minimal repro; error messages match character-for-character.
Findings
Should-fix
- Stale
#SKIPcases are not detected.cases.rs:138-140continues oncase.skipbefore ever callingformat_source, so a case marked#SKIPthat quietly starts passing (bug fixed elsewhere, or a bad#SKIPadded by mistake) gives zero signal —cargo teststays green forever. Verified by adding a#SKIP-tagged case whose expected output already matches actual output today; the suite reportsokwith no indication anything is skipped. Since the whole point of#SKIP(per this README) is "delete the line the moment the bug is fixed," nothing currently prompts that deletion. A cheap fix would be to assert skipped cases do fail (i.e., invert the check) so a newly-passing case turns into a failure demanding the#SKIPbe removed — that's a design change for the dev agent to consider, not something I should make. - A bare
----or====line inside case content (e.g. a block-comment ASCII banner) silently misparses instead of erroring clearly. Probed with a case whose input contains a legitimate/* ---- */banner line; the harness split the case at the banner instead of the real----separator, and the failure surfaced as an opaquelex error: unterminated block commentrather than anything pointing at the ambiguity. No existing case triggers this (checked all 10 files for bare----/====lines outside separators — none found), so it's latent, not live. Worth a one-line callout in the "File format" section warning case authors off using bare----/====as content, since bug #1 (block comments) is exactly the kind of case most likely to grow a banner divider later. - Coverage gaps against
README.md"Supported syntax": no case exercises afinalblock (initial/finalare both listed as supported), and no case exercises a bare module-levelcasewithout ageneratewrapper (module-levelif/forboth have non-generate cases ingenerate.cases,casedoesn't). Confirmed both parse and format correctly viatarget/debug/vfmt -— the formatter isn't wrong, the table just doesn't pin either down. Minor others:alwayswith a comma-separated (notor-separated) sensitivity list, multipleimportstatements in one module. None of these are blocking; they're the kind of gap the TODO already flags generally ("port more cases … the count should grow by an order of magnitude"). - The "defensible style observations" list has no case backing the
initial forkclaim. The README's style-observations section states "initial begincuddles, butinitial forkdoes not." I confirmed this is true (target/debug/vfmt -oninitial fork ... joinputsinitialandforkon separate lines), but no.casesfile actually contains aninitial fork(onlyforknested insideinitial begin, instatements.cases). The other five observations are backed by real cases (unpacked-dim spacing:declarations.cases/instantiation.cases; operator-chain indent and the exactly-100-column boundary:expressions.cases;timeunitspacing and blank-line-after-comment collapse:module_headers.cases/comments.cases; struct-always-breaks:typedef.cases). None of the six observations actually contradict a written Style rule — all are about behavior the Style section is simply silent on, so "defensible" is the right call for all six.
Nit
README.md's bug #4 write-up says the one-line multi-instance form "is 30 columns wide"; the actual wanted output (sub u0 (.a(x)), u1 (.a(y));) is 29 columns. Off by one, cosmetic only, not fixing since it doesn't affect the finding.- The File-format section describes
#SKIPas "a case whose name contains SKIP," but the parser (split_case,cases.rs:57-60) only sets the skip flag when a#-line starts withSKIPafter trimming, not whenSKIPappears anywhere in the assembled name. Harmless today — all four real#SKIPcases use the line-initial form the code expects — but a future case author relying on the literal wording could write# note: might SKIP thisexpecting it to be skipped and be wrong.
Harness audit (no bugs found beyond the above)
- Discovery (
cases_dir/read_dir) panics loudly if the directory is missing (.expect("cases dir")); an empty-but-present directory is caught byassert!(!files.is_empty(), ...). Neither path passes vacuously. (Verified by code inspection only — did not delete the real directory to test live, to avoid disturbing other in-flight work.) - Last case needing no trailing
====: verified live (probe file, single case, no trailing separator, parsed and ran correctly). - Missing
----separator: verified live, fails loudly with correctfile:line(zz_probe2.cases:1: case has no+ "----" +separator). - CRLF line endings: verified live with a CRLF-only probe file;
str::linesstrips the\r, no corruption, case parses and runs correctly. No CRLF files exist in the realtests/cases/tree today. - Blank lines directly after a
====separator (before the next case's name/content) were checked for across all 10 files — none exist, so the theoretical off-by-one instartline tracking (a blank line right after====would itself becomestart, one line before the name) is latent, not live. - No case has an empty input or empty expected half (checked programmatically across all 10 files).
file:lineaccuracy for a failure in the second case of a file (not just the first) was verified live and points at the exact line of the case's#header, not the file start or the previous case.- Diff rendering (
-expected /+got) matches its documented convention, confirmed on a live failing probe case.
Spot-check of case quality
Read essentially all 183 cases (not just ~20) against the Style section.
Nothing found where an expected output was rubber-stamping formatter
behavior that contradicts a written Style rule — the closest candidates
(unpacked-dim spacing, operator-chain indent, struct-always-breaks) are all
already called out as observations, and none of them contradict a stated
rule since the Style section doesn't speak to any of them. The "exactly 100
columns stays on one line" case (expressions.cases:231) was checked
byte-for-byte: the expected line is exactly 100 columns. All four #SKIP
expected outputs match the "wanted" output described in the bug write-ups
and are not what the formatter currently produces (confirmed above).
Claim verdicts
- Harness behavior (discovery,
====/----/#/#SKIPparsing, dual assertion, collected failures with file:line + diff): pass, with should-fix findings #1 and #2 above (both about corner cases the current design doesn't defend against, not about anything mis-implemented relative to the documented spec). - 183 cases (179 asserted + 4 SKIP) across 10 files, hand-reviewed against Style: pass, counts verified independently; found no case that contradicts a written rule.
- Four suspected bugs + six style observations: pass. All four bugs
reproduce exactly as documented (byte-identical error messages) both via
the harness and via the standalone binary. Five of six observations are
directly backed by a case; the sixth (
initial fork) is true but untested (finding #4).
Review
2026-08-18 — lead. Verdict: accepted and committed, with three lead fixes.
Good work on both sides. The harness is exactly the right size (~180 lines, std only), the format is readable, and the dev agent's decision to report formatter bugs instead of rubber-stamping output is the most valuable thing this feature produced — all four bugs are real, and two of them break hard invariants. The QA pass was genuinely adversarial (probe files, un-skip + restore, byte-level recounts) and left the tree clean; that is the standard going forward.
Changes I made while accepting (small and unambiguous, so lead-fixed rather than another dev round):
- Inverted
#SKIPsemantics (QA finding 1): a#SKIPcase must still fail; if it starts passing the suite now fails with "remove the #SKIP marker".tests/cases.rsgained a smallpasses()helper. Verified: all four parked bugs still fail, suite green. - File-format doc corrections (QA findings 2 and 6): documented the
line-initial
#SKIPrule as implemented, and warned against bare----/====banner lines inside case content. The parser was right; the prose was loose. - Coverage gaps → TODO (QA findings 3 and 4):
final, bare module-levelcase,initial fork, comma sensitivity lists, multiple imports — recorded as an unchecked TODO item for the next dev round on this feature, not silently dropped.
Direction for the next round: the four suspected bugs move to a dedicated
fix feature (they are formatter work, not test work); the six style
observations should each get a one-line ruling in the top-level README.md
Style section once decided — the QA agent is right that "defensible" only
holds while the Style section is silent.