Skip to content

Commit a69e9cc

Browse files
authored
Fix #[should_panic] with unsupported tests (rustwasm#4196)
1 parent 3b46cbe commit a69e9cc

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
* Fixed triggering lints in testing facilities.
2323
[#4195](https://github.com/rustwasm/wasm-bindgen/pull/4195)
2424

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

2730
## [0.2.95](https://github.com/rustwasm/wasm-bindgen/compare/0.2.94...0.2.95)

crates/test-macro/src/lib.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn wasm_bindgen_test(
8282

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

85-
let should_panic = match should_panic {
85+
let should_panic_par = match &should_panic {
8686
Some(Some(lit)) => {
8787
quote! { ::core::option::Option::Some(::core::option::Option::Some(#lit)) }
8888
}
@@ -99,9 +99,9 @@ pub fn wasm_bindgen_test(
9999
};
100100

101101
let test_body = if attributes.r#async {
102-
quote! { cx.execute_async(test_name, #ident, #should_panic, #ignore); }
102+
quote! { cx.execute_async(test_name, #ident, #should_panic_par, #ignore); }
103103
} else {
104-
quote! { cx.execute_sync(test_name, #ident, #should_panic, #ignore); }
104+
quote! { cx.execute_sync(test_name, #ident, #should_panic_par, #ignore); }
105105
};
106106

107107
// We generate a `#[no_mangle]` with a known prefix so the test harness can
@@ -127,6 +127,18 @@ pub fn wasm_bindgen_test(
127127
tokens.extend(
128128
quote! { #[cfg_attr(not(all(target_arch = "wasm32", target_os = "unknown")), #path)] },
129129
);
130+
131+
if let Some(should_panic) = should_panic {
132+
let should_panic = if let Some(lit) = should_panic {
133+
quote! { should_panic = #lit }
134+
} else {
135+
quote! { should_panic }
136+
};
137+
138+
tokens.extend(
139+
quote! { #[cfg_attr(not(all(target_arch = "wasm32", target_os = "unknown")), #should_panic)] }
140+
)
141+
}
130142
}
131143

132144
tokens.extend(leading_tokens);

0 commit comments

Comments
 (0)