Skip to content

Forward attributes on spec! it cases - #3

Merged
brianp merged 1 commit into
mainfrom
spec-attr-passthrough
Jul 21, 2026
Merged

Forward attributes on spec! it cases#3
brianp merged 1 commit into
mainfrom
spec-attr-passthrough

Conversation

@brianp

@brianp brianp commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Follow-up to the discussion on #1, where Bruce mentioned he'd have liked arbitrary attributes to be supported.

In attribute style (#[test_suite]) you can already put #[ignore], #[cfg(...)], #[should_panic], and so on directly on a #[test] fn, and the macro carries them through. The spec! DSL couldn't do that. There was no syntax to attach an attribute to an it, so anything that needed one meant dropping out of the DSL.

This wires it up. Attributes written before an it are parsed and emitted on the generated #[test] function:

spec! {
    mod with_attrs {
        #[should_panic(expected = "boom")]
        it "panics as expected" { panic!("boom"); }

        #[ignore]
        it "skipped unless you pass --ignored" { /* ... */ }

        #[cfg(feature = "integration")]
        it "only compiled with the integration feature" { /* ... */ }
    }
}

Works on async it too.

Attributes on hooks (before/after/before_each/after_each) are rejected with a compile error rather than silently dropped, since a hook isn't a standalone function. Gating a hook is a separate, harder thing and I left it out.

Independent of the #[after] fix in #2, so this branches straight off main.

Attributes written before an `it` (#[ignore], #[should_panic], #[cfg(...)],
and so on) are now parsed and emitted on the generated test function, so the
DSL matches what attribute-style #[test_suite] already allows.

Attributes on hooks (before/after/before_each/after_each) are rejected with a
clear compile error, since a hook isn't a standalone function and the
attribute would otherwise be dropped silently.
@brianp
brianp force-pushed the spec-attr-passthrough branch from e3327fd to 74e3d11 Compare July 21, 2026 15:46
@brianp
brianp merged commit e2cfa8a into main Jul 21, 2026
5 checks passed
@brianp
brianp deleted the spec-attr-passthrough branch July 21, 2026 16:10
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.

1 participant