Skip to content

Add trybuild tests for derive error paths - #51

Merged
michaelsproul merged 41 commits into
sigp:mainfrom
eserilev:trybuild-suite
Aug 18, 2026
Merged

Add trybuild tests for derive error paths#51
michaelsproul merged 41 commits into
sigp:mainfrom
eserilev:trybuild-suite

Conversation

@eserilev

@eserilev eserilev commented Jul 28, 2026

Copy link
Copy Markdown
Member

Adds a trybuild compile-fail suite alongside two small fixes

  • Restore the helpful error for enums missing enum_behaviour (it had
    regressed to "tree_hash_derive only supports structs and enums").
  • Emit darling parse failures via write_errors() instead of unwrap(), so
    attribute errors are compile errors rather than derive panics.

TRYBUILD=overwrite cargo test --test trybuild rewrites the stderr files in case a new rust version changes these error messages

Might make sense to review/merge only after the progressive branch has been merged

Copilot AI and others added 30 commits December 8, 2025 02:50
Co-authored-by: michaelsproul <4452260+michaelsproul@users.noreply.github.com>
Co-authored-by: michaelsproul <4452260+michaelsproul@users.noreply.github.com>
Co-authored-by: michaelsproul <4452260+michaelsproul@users.noreply.github.com>
Co-authored-by: michaelsproul <4452260+michaelsproul@users.noreply.github.com>
… stream in

Co-authored-by: michaelsproul <4452260+michaelsproul@users.noreply.github.com>
…er method

Co-authored-by: michaelsproul <4452260+michaelsproul@users.noreply.github.com>
…inary tree hashing

Co-authored-by: michaelsproul <4452260+michaelsproul@users.noreply.github.com>
michaelsproul and others added 6 commits July 27, 2026 16:12
Previously the consistency check between variant-level `tree_hash` and
`ssz` attributes compared the whole parsed `VariantOpts` structs. Since
both parsers tolerate unknown keys, an attribute that is present but does
not set `selector` (e.g. one carrying only ssz-specific keys) would parse
as `selector: None` and spuriously fail the consistency assertion against
the other attribute's explicit selector.

Merge the two attributes field-by-field instead, asserting consistency
only when both actually set a selector.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The variant checks in the transparent and union derive paths only
verified the field *count*, so a single named-field variant like
`A { x: u8 }` passed the check and then failed with a confusing
"expected tuple struct" error in the generated match pattern.

Check explicitly for a single unnamed field and panic with a proper
message naming the offending variant.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Regular unions already panic with "0-variant union is not permitted"
(via `compute_union_selectors`), but a 0-variant compatible union slipped
through selector validation and instead failed on the generated
`match self {}`, which is not exhaustive for `&Self` even when `Self` is
uninhabited. Panic with the same message as the regular union path.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
A `selector` attribute on a variant of a transparent enum was silently
ignored, because `parse_variant_opts` was only called from the union
derive path. Transparent enums never mix in a selector, so a manual one
is a configuration error: reject it in the same way that the regular
"union" behaviour already does.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.77%. Comparing base (e9e3a1b) to head (74c4ea2).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #51   +/-   ##
=======================================
  Coverage   93.77%   93.77%           
=======================================
  Files           8        8           
  Lines         739      739           
=======================================
  Hits          693      693           
  Misses         46       46           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@michaelsproul
michaelsproul changed the base branch from progressive to main August 18, 2026 02:09
@michaelsproul

Copy link
Copy Markdown
Member

Not sure why I got different output on my machine from CI? I've reverted the diff produced by my local: 74c4ea2

@michaelsproul michaelsproul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Very thorough!

@michaelsproul
michaelsproul merged commit 19fb50a into sigp:main Aug 18, 2026
8 checks passed
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.

4 participants