Skip to content

Support #[should_panic] in tests #2286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
d-e-s-o opened this issue Aug 16, 2020 · 3 comments · Fixed by #3293
Closed

Support #[should_panic] in tests #2286

d-e-s-o opened this issue Aug 16, 2020 · 3 comments · Fixed by #3293

Comments

@d-e-s-o
Copy link
Contributor

d-e-s-o commented Aug 16, 2020

I think it would be great to have support for the #[should_panic] attribute on tests. That is, the following works as expected when compiling natively:

#[test]
#[should_panic]
fn foo() {
  panic!("foo")
}

But if I am doing the same in WASM:

#[wasm_bindgen_test::wasm_bindgen_test]
#[should_panic]
fn foo() {
  panic!("foo")
}

I see warning: unused attribute and a panic:

panicked at 'foo', src/XXX:YYY:ZZ

Stack:

Error
    at target/wasm32-unknown-unknown/wbg-tmp/wasm-bindgen-test.js:751:15
   ...
@d-e-s-o
Copy link
Contributor Author

d-e-s-o commented Aug 16, 2020

Oh, well, do we have no unwinding support in WASM at all?

#[test]
fn foo() {
  use std::panic::catch_unwind;

  let _ = catch_unwind(|| {
    panic!("test");
  });
}

Even that panics.

@alexcrichton
Copy link
Contributor

Unfortunately this is not possible to easily support today because wasm does not have catchable exceptions, this will work once that proposal stabilizes, though!

@Tamschi
Copy link
Contributor

Tamschi commented May 9, 2021

I just tripped across this but had noticed earlier that the test runner now trampolines through JS to run the individual tests, which if I'm not mistaken gives it an interface to observe and handle the error.

Is it feasible to implement this feature on that basis now or is there another blocker?

WorldSEnder added a commit to WorldSEnder/yew that referenced this issue Dec 10, 2022
wasm_bindgen does not yet support #[should_panic]
see also rustwasm/wasm-bindgen#2286
WorldSEnder added a commit to yewstack/yew that referenced this issue Dec 10, 2022
* assert there are no circular references

the check is costly in release builds and should always fail
note that the current PartialEq impl is *not* symmetric!
should be fixed as well, with an improved design

* remove internal test for cyclic node refs

wasm_bindgen does not yet support #[should_panic]
see also rustwasm/wasm-bindgen#2286
WorldSEnder added a commit to WorldSEnder/yew that referenced this issue Jan 10, 2023
* assert there are no circular references

the check is costly in release builds and should always fail
note that the current PartialEq impl is *not* symmetric!
should be fixed as well, with an improved design

* remove internal test for cyclic node refs

wasm_bindgen does not yet support #[should_panic]
see also rustwasm/wasm-bindgen#2286
WorldSEnder added a commit to yewstack/yew that referenced this issue Jan 19, 2023
* assert there are no circular references

the check is costly in release builds and should always fail
note that the current PartialEq impl is *not* symmetric!
should be fixed as well, with an improved design

* remove internal test for cyclic node refs

wasm_bindgen does not yet support #[should_panic]
see also rustwasm/wasm-bindgen#2286
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants