Skip to content

Commit

Permalink
Fix #[should_panic] with unsupported tests (#4196)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda authored Oct 13, 2024
1 parent 3b46cbe commit a69e9cc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
* Fixed triggering lints in testing facilities.
[#4195](https://github.com/rustwasm/wasm-bindgen/pull/4195)

* Fixed `#[should_panic]` not working with `#[wasm_bindgen_test(unsupported = ...)]`.
[#4196](https://github.com/rustwasm/wasm-bindgen/pull/4196)

--------------------------------------------------------------------------------

## [0.2.95](https://github.com/rustwasm/wasm-bindgen/compare/0.2.94...0.2.95)
Expand Down
18 changes: 15 additions & 3 deletions crates/test-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn wasm_bindgen_test(

let mut tokens = Vec::<TokenTree>::new();

let should_panic = match should_panic {
let should_panic_par = match &should_panic {
Some(Some(lit)) => {
quote! { ::core::option::Option::Some(::core::option::Option::Some(#lit)) }
}
Expand All @@ -99,9 +99,9 @@ pub fn wasm_bindgen_test(
};

let test_body = if attributes.r#async {
quote! { cx.execute_async(test_name, #ident, #should_panic, #ignore); }
quote! { cx.execute_async(test_name, #ident, #should_panic_par, #ignore); }
} else {
quote! { cx.execute_sync(test_name, #ident, #should_panic, #ignore); }
quote! { cx.execute_sync(test_name, #ident, #should_panic_par, #ignore); }
};

// We generate a `#[no_mangle]` with a known prefix so the test harness can
Expand All @@ -127,6 +127,18 @@ pub fn wasm_bindgen_test(
tokens.extend(
quote! { #[cfg_attr(not(all(target_arch = "wasm32", target_os = "unknown")), #path)] },
);

if let Some(should_panic) = should_panic {
let should_panic = if let Some(lit) = should_panic {
quote! { should_panic = #lit }
} else {
quote! { should_panic }
};

tokens.extend(
quote! { #[cfg_attr(not(all(target_arch = "wasm32", target_os = "unknown")), #should_panic)] }
)
}
}

tokens.extend(leading_tokens);
Expand Down

0 comments on commit a69e9cc

Please sign in to comment.