Skip to content

Conversation

@skogseth
Copy link
Contributor

@skogseth skogseth commented Nov 3, 2025

This is done by recursively parsing attributes following the #[libtest2::test] macro, and then parsing the first #[should_panic] macro encountered. If a macro is encountered then the test will be run within a catch_unwind, which is done by wrapping it in the assert_panic macro (function style).

Potentially supporting multiple #[should_panic] macros is left for the future.

Fixes #15

@coveralls
Copy link

coveralls commented Nov 3, 2025

Pull Request Test Coverage Report for Build 19136819629

Details

  • 34 of 37 (91.89%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+1.3%) to 31.931%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/libtest2/src/panic.rs 18 21 85.71%
Totals Coverage Status
Change from base Build 18990226994: 1.3%
Covered Lines: 539
Relevant Lines: 1688

💛 - Coveralls

The `test_parse` macro is changed to recursively parse attributes,
filtering out the `#[ignore]` macro. This should also make it fairly
trivial to add additional macros, such as `#[should_ignore]`.

There is a fair amount of complexity added to the macro with this
change, but on the other hand, it also succeeds in generating only the
necessary code. You win some, you lose some.
@epage
Copy link
Collaborator

epage commented Nov 5, 2025

Thanks, this is looking great!

@skogseth skogseth force-pushed the should_panic branch 2 times, most recently from 2731bc1 to ce0bd7c Compare November 6, 2025 13:04
@epage epage merged commit fcfc13a into assert-rs:main Nov 6, 2025
15 checks passed
@skogseth skogseth deleted the should_panic branch November 6, 2025 14:55
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.

#[should_panic] macro support

3 participants