Skip to content
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

Implement #[should_panic(expected = "...")] handling #3293

Merged
merged 13 commits into from
Feb 13, 2023

Conversation

daxpedda
Copy link
Collaborator

@daxpedda daxpedda commented Feb 9, 2023

Catching panics was already in place, it was just a matter of properly parsing should_panic and printing the correct error messages.

I tried to stay as close as possible to the output Rust gives.

EDIT:
I found out later that there was no proper way to "only" get the panic message, so I just customized the panic hook to store any panic message in the thread local output we already had around.

Fixes #2286.

Copy link
Collaborator

@ranile ranile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for implementing this! This is a welcome addition

Looking through the code, I don't see tests for the failing case where the test should panic but actually doesn't. It would be great to have tests for that.

crates/test/src/rt/mod.rs Outdated Show resolved Hide resolved
crates/futures/tests/tests.rs Show resolved Hide resolved
@daxpedda
Copy link
Collaborator Author

daxpedda commented Feb 9, 2023

I can't find a place for failing tests.
Should I make one? I would use trybuild for that, which apparently was already used for the wasm-bindgen macro testing.

@daxpedda daxpedda closed this Feb 9, 2023
@daxpedda daxpedda reopened this Feb 9, 2023
@daxpedda
Copy link
Collaborator Author

daxpedda commented Feb 9, 2023

CI is failing for unrelated reasons.

@daxpedda daxpedda closed this Feb 9, 2023
@daxpedda daxpedda reopened this Feb 9, 2023
Comment on lines +159 to +175
#[wasm_bindgen_test]
#[should_panic]
async fn should_panic() {
panic!()
}

#[wasm_bindgen_test]
#[should_panic = "error message"]
async fn should_panic_string() {
panic!("error message")
}

#[wasm_bindgen_test]
#[should_panic(expected = "error message")]
async fn should_panic_expected() {
panic!("error message")
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these tests a part of wasm-bindgen-futures's test suite?

Copy link
Collaborator Author

@daxpedda daxpedda Feb 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was testing it with async functions to make sure that the parsing is correct.

crates/test-macro/src/lib.rs Outdated Show resolved Hide resolved
crates/test-macro/src/lib.rs Outdated Show resolved Hide resolved
crates/test-macro/src/lib.rs Outdated Show resolved Hide resolved
crates/test/src/rt/mod.rs Show resolved Hide resolved
@daxpedda daxpedda force-pushed the should-panic branch 3 times, most recently from 3de85ce to 542ba73 Compare February 10, 2023 12:20
@daxpedda daxpedda force-pushed the should-panic branch 2 times, most recently from 352238f to 135f8b7 Compare February 11, 2023 12:23
@daxpedda daxpedda closed this Feb 11, 2023
@daxpedda daxpedda reopened this Feb 11, 2023
@daxpedda daxpedda force-pushed the should-panic branch 4 times, most recently from 36b972a to b596082 Compare February 11, 2023 14:02
Co-Authored-By: Liam Murphy <43807659+Liamolucko@users.noreply.github.com>
Copy link
Collaborator

@Liamolucko Liamolucko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Liamolucko Liamolucko merged commit d9e113b into rustwasm:main Feb 13, 2023
Liamolucko added a commit to Liamolucko/wasm-bindgen that referenced this pull request Feb 16, 2023
Apparently, rustwasm#3293 didn't quite update them properly, causing CI to fail. I'm not sure why CI passed when checking the PR but failed on `main`, but this should fix the CI failure.
@daxpedda daxpedda mentioned this pull request Feb 16, 2023
alexcrichton pushed a commit that referenced this pull request Feb 16, 2023
* Update expected results for UI tests

Apparently, #3293 didn't quite update them properly, causing CI to fail. I'm not sure why CI passed when checking the PR but failed on `main`, but this should fix the CI failure.

* Use updated trybuild

It looks like trybuild moved where it puts its output, and so CI's up-to-date trybuild and my older local trybuild disagreed on what a path should be.
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.

Support #[should_panic] in tests
3 participants