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
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: rustup update --no-self-update 1.56.0 && rustup default 1.56.0
- run: rustup update --no-self-update 1.59.0 && rustup default 1.59.0
- run: cargo test -p wasm-bindgen-macro
- run: cargo test -p wasm-bindgen-test-macro

build_examples:
runs-on: ubuntu-latest
Expand Down
18 changes: 18 additions & 0 deletions crates/futures/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,21 @@ async fn can_use_an_async_iterable_as_stream() {
assert_eq!(stream.next().await, Some(Ok(JsValue::from(24))));
assert_eq!(stream.next().await, None);
}

#[wasm_bindgen_test]
#[should_panic]
async fn should_panic() {
panic!()
}

#[wasm_bindgen_test]
#[should_panic = "error message"]
daxpedda marked this conversation as resolved.
Show resolved Hide resolved
async fn should_panic_string() {
panic!("error message")
}

#[wasm_bindgen_test]
#[should_panic(expected = "error message")]
async fn should_panic_expected() {
panic!("error message")
}
Comment on lines +159 to +175
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.

20 changes: 0 additions & 20 deletions crates/macro/ui-tests/async-errors.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ error[E0277]: the trait bound `Result<(), ()>: IntoJsResult` is not satisfied
= help: the following implementations were found:
<Result<(), E> as IntoJsResult>
<Result<T, E> as IntoJsResult>
note: required by `into_js_result`
--> $WORKSPACE/src/lib.rs
|
| fn into_js_result(self) -> Result<JsValue, JsValue>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `Result<(), BadType>: IntoJsResult` is not satisfied
Expand All @@ -23,11 +18,6 @@ error[E0277]: the trait bound `Result<(), BadType>: IntoJsResult` is not satisfi
= help: the following implementations were found:
<Result<(), E> as IntoJsResult>
<Result<T, E> as IntoJsResult>
note: required by `into_js_result`
--> $WORKSPACE/src/lib.rs
|
| fn into_js_result(self) -> Result<JsValue, JsValue>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `wasm_bindgen::JsValue: From<BadType>` is not satisfied
Expand All @@ -44,11 +34,6 @@ error[E0277]: the trait bound `wasm_bindgen::JsValue: From<BadType>` is not sati
and $N others
= note: required because of the requirements on the impl of `Into<wasm_bindgen::JsValue>` for `BadType`
= note: required because of the requirements on the impl of `IntoJsResult` for `BadType`
note: required by `into_js_result`
--> $WORKSPACE/src/lib.rs
|
| fn into_js_result(self) -> Result<JsValue, JsValue>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `Result<BadType, wasm_bindgen::JsValue>: IntoJsResult` is not satisfied
Expand All @@ -60,9 +45,4 @@ error[E0277]: the trait bound `Result<BadType, wasm_bindgen::JsValue>: IntoJsRes
= help: the following implementations were found:
<Result<(), E> as IntoJsResult>
<Result<T, E> as IntoJsResult>
note: required by `into_js_result`
--> $WORKSPACE/src/lib.rs
|
| fn into_js_result(self) -> Result<JsValue, JsValue>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)
24 changes: 12 additions & 12 deletions crates/macro/ui-tests/invalid-imports.stderr
Original file line number Diff line number Diff line change
@@ -1,71 +1,71 @@
error: it is currently not sound to use lifetimes in function signatures
--> $DIR/invalid-imports.rs:7:16
--> ui-tests/invalid-imports.rs:7:16
|
7 | fn f() -> &'static u32;
| ^^^^^^^

error: imported methods must have at least one argument
--> $DIR/invalid-imports.rs:10:5
--> ui-tests/invalid-imports.rs:10:5
|
10 | fn f1();
| ^^^^^^^^

error: first argument of method must be a shared reference
--> $DIR/invalid-imports.rs:12:14
--> ui-tests/invalid-imports.rs:12:14
|
12 | fn f2(x: u32);
| ^^^

error: first argument of method must be a path
--> $DIR/invalid-imports.rs:14:14
--> ui-tests/invalid-imports.rs:14:14
|
14 | fn f3(x: &&u32);
| ^^^^^

error: paths with type parameters are not supported yet
--> $DIR/invalid-imports.rs:20:15
--> ui-tests/invalid-imports.rs:20:15
|
20 | fn f4(x: &Bar<T>);
| ^^^^^^

error: paths with type parameters are not supported yet
--> $DIR/invalid-imports.rs:22:15
--> ui-tests/invalid-imports.rs:22:15
|
22 | fn f4(x: &Fn(T));
| ^^^^^

error: constructor returns must be bare types
--> $DIR/invalid-imports.rs:25:5
--> ui-tests/invalid-imports.rs:25:5
|
25 | fn f();
| ^^^^^^^

error: return value of constructor must be a bare path
--> $DIR/invalid-imports.rs:29:5
--> ui-tests/invalid-imports.rs:29:5
|
29 | fn f() -> &Bar;
| ^^^^^^^^^^^^^^^

error: must be Result<...>
--> $DIR/invalid-imports.rs:32:15
--> ui-tests/invalid-imports.rs:32:15
|
32 | fn f() -> u32;
| ^^^

error: must be Result<...>
--> $DIR/invalid-imports.rs:34:15
--> ui-tests/invalid-imports.rs:34:15
|
34 | fn f() -> &u32;
| ^^^^

error: must have at least one generic parameter
--> $DIR/invalid-imports.rs:36:15
--> ui-tests/invalid-imports.rs:36:15
|
36 | fn f() -> Result<>;
| ^^^^^^^^

error: it is currently not sound to use lifetimes in function signatures
--> $DIR/invalid-imports.rs:38:22
--> ui-tests/invalid-imports.rs:38:22
|
38 | fn f() -> Result<'a>;
| ^^
24 changes: 12 additions & 12 deletions crates/macro/ui-tests/invalid-methods.stderr
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
error: #[wasm_bindgen] default impls are not supported
--> $DIR/invalid-methods.rs:7:1
--> ui-tests/invalid-methods.rs:7:1
|
7 | default impl A {
| ^^^^^^^

error: #[wasm_bindgen] unsafe impls are not supported
--> $DIR/invalid-methods.rs:11:1
--> ui-tests/invalid-methods.rs:11:1
|
11 | unsafe impl A {
| ^^^^^^

error: #[wasm_bindgen] trait impls are not supported
--> $DIR/invalid-methods.rs:15:6
--> ui-tests/invalid-methods.rs:15:6
|
15 | impl Clone for A {
| ^^^^^

error: #[wasm_bindgen] generic impls aren't supported
--> $DIR/invalid-methods.rs:19:5
--> ui-tests/invalid-methods.rs:19:5
|
19 | impl<T> A {
| ^^^

error: unsupported self type in #[wasm_bindgen] impl
--> $DIR/invalid-methods.rs:23:6
--> ui-tests/invalid-methods.rs:23:6
|
23 | impl &'static A {
| ^^^^^^^^^^

error: const definitions aren't supported with #[wasm_bindgen]
--> $DIR/invalid-methods.rs:30:5
--> ui-tests/invalid-methods.rs:30:5
|
30 | const X: u32 = 3;
| ^^^^^^^^^^^^^^^^^

error: type definitions in impls aren't supported with #[wasm_bindgen]
--> $DIR/invalid-methods.rs:31:5
--> ui-tests/invalid-methods.rs:31:5
|
31 | type Y = u32;
| ^^^^^^^^^^^^^

error: macros in impls aren't supported
--> $DIR/invalid-methods.rs:32:5
--> ui-tests/invalid-methods.rs:32:5
|
32 | x!();
| ^^^^^

error: can only #[wasm_bindgen] non-const functions
--> $DIR/invalid-methods.rs:39:9
--> ui-tests/invalid-methods.rs:39:9
|
39 | pub const fn foo() {}
| ^^^^^

warning: unused macro definition
--> $DIR/invalid-methods.rs:26:1
warning: unused macro definition: `x`
--> ui-tests/invalid-methods.rs:26:14
|
26 | macro_rules! x { () => () }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^
|
= note: `#[warn(unused_macros)]` on by default
12 changes: 0 additions & 12 deletions crates/macro/ui-tests/missing-catch.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,3 @@ error[E0277]: the trait bound `Result<wasm_bindgen::JsValue, wasm_bindgen::JsVal
|
6 | pub fn foo() -> Result<JsValue, JsValue>;
| ^^^ the trait `FromWasmAbi` is not implemented for `Result<wasm_bindgen::JsValue, wasm_bindgen::JsValue>`
|
note: required by a bound in `FromWasmAbi`
--> $WORKSPACE/src/convert/traits.rs
|
| / pub trait FromWasmAbi: WasmDescribe {
| | /// The wasm ABI type that this converts from when coming back out from the
| | /// ABI boundary.
| | type Abi: WasmAbi;
... |
| | unsafe fn from_abi(js: Self::Abi) -> Self;
| | }
| |_^ required by this bound in `FromWasmAbi`
84 changes: 32 additions & 52 deletions crates/macro/ui-tests/start-function.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,41 @@ error: the start function cannot have generics
| ^^^

error[E0277]: the trait bound `Result<wasm_bindgen::JsValue, ()>: wasm_bindgen::__rt::Start` is not satisfied
--> ui-tests/start-function.rs:15:1
|
15 | #[wasm_bindgen(start)]
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `wasm_bindgen::__rt::Start` is not implemented for `Result<wasm_bindgen::JsValue, ()>`
|
= help: the following implementations were found:
<Result<(), E> as wasm_bindgen::__rt::Start>
note: required by `start`
--> $WORKSPACE/src/lib.rs
|
| fn start(self);
| ^^^^^^^^^^^^^^^
= note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)
--> ui-tests/start-function.rs:15:1
|
15 | #[wasm_bindgen(start)]
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `wasm_bindgen::__rt::Start` is not implemented for `Result<wasm_bindgen::JsValue, ()>`
|
= help: the following implementations were found:
<Result<(), E> as wasm_bindgen::__rt::Start>
= note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `Result<wasm_bindgen::JsValue, wasm_bindgen::JsValue>: wasm_bindgen::__rt::Start` is not satisfied
--> ui-tests/start-function.rs:18:1
|
18 | #[wasm_bindgen(start)]
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `wasm_bindgen::__rt::Start` is not implemented for `Result<wasm_bindgen::JsValue, wasm_bindgen::JsValue>`
|
= help: the following implementations were found:
<Result<(), E> as wasm_bindgen::__rt::Start>
note: required by `start`
--> $WORKSPACE/src/lib.rs
|
| fn start(self);
| ^^^^^^^^^^^^^^^
= note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)
--> ui-tests/start-function.rs:18:1
|
18 | #[wasm_bindgen(start)]
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `wasm_bindgen::__rt::Start` is not implemented for `Result<wasm_bindgen::JsValue, wasm_bindgen::JsValue>`
|
= help: the following implementations were found:
<Result<(), E> as wasm_bindgen::__rt::Start>
= note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `Result<wasm_bindgen::JsValue, ()>: wasm_bindgen::__rt::Start` is not satisfied
--> ui-tests/start-function.rs:27:1
|
27 | #[wasm_bindgen(start)]
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `wasm_bindgen::__rt::Start` is not implemented for `Result<wasm_bindgen::JsValue, ()>`
|
= help: the following implementations were found:
<Result<(), E> as wasm_bindgen::__rt::Start>
note: required by `start`
--> $WORKSPACE/src/lib.rs
|
| fn start(self);
| ^^^^^^^^^^^^^^^
= note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)
--> ui-tests/start-function.rs:27:1
|
27 | #[wasm_bindgen(start)]
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `wasm_bindgen::__rt::Start` is not implemented for `Result<wasm_bindgen::JsValue, ()>`
|
= help: the following implementations were found:
<Result<(), E> as wasm_bindgen::__rt::Start>
= note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `Result<wasm_bindgen::JsValue, wasm_bindgen::JsValue>: wasm_bindgen::__rt::Start` is not satisfied
--> ui-tests/start-function.rs:30:1
|
30 | #[wasm_bindgen(start)]
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `wasm_bindgen::__rt::Start` is not implemented for `Result<wasm_bindgen::JsValue, wasm_bindgen::JsValue>`
|
= help: the following implementations were found:
<Result<(), E> as wasm_bindgen::__rt::Start>
note: required by `start`
--> $WORKSPACE/src/lib.rs
|
| fn start(self);
| ^^^^^^^^^^^^^^^
= note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)
--> ui-tests/start-function.rs:30:1
|
30 | #[wasm_bindgen(start)]
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `wasm_bindgen::__rt::Start` is not implemented for `Result<wasm_bindgen::JsValue, wasm_bindgen::JsValue>`
|
= help: the following implementations were found:
<Result<(), E> as wasm_bindgen::__rt::Start>
= note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)
11 changes: 0 additions & 11 deletions crates/macro/ui-tests/traits-not-implemented.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,4 @@ error[E0277]: the trait bound `A: IntoWasmAbi` is not satisfied
5 | #[wasm_bindgen]
| ^^^^^^^^^^^^^^^ the trait `IntoWasmAbi` is not implemented for `A`
|
note: required by a bound in `IntoWasmAbi`
--> $WORKSPACE/src/convert/traits.rs
|
| / pub trait IntoWasmAbi: WasmDescribe {
| | /// The wasm ABI type that this converts into when crossing the ABI
| | /// boundary.
| | type Abi: WasmAbi;
... |
| | fn into_abi(self) -> Self::Abi;
| | }
| |_^ required by this bound in `IntoWasmAbi`
= note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)
12 changes: 6 additions & 6 deletions crates/macro/ui-tests/unused-attributes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ error: unused variable: `readonly`
21 | #[wasm_bindgen(readonly)]
| ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_readonly`

error: unused variable: `typescript_type`
--> ui-tests/unused-attributes.rs:26:28
|
26 | #[wasm_bindgen(getter, typescript_type = "Thing[]")]
| ^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_typescript_type`

error: unused variable: `getter_with_clone`
--> ui-tests/unused-attributes.rs:24:16
|
Expand All @@ -33,9 +39,3 @@ error: unused variable: `final`
|
24 | #[wasm_bindgen(getter_with_clone, final)]
| ^^^^^ help: if this is intentional, prefix it with an underscore: `_final`

error: unused variable: `typescript_type`
--> ui-tests/unused-attributes.rs:26:28
|
26 | #[wasm_bindgen(getter, typescript_type = "Thing[]")]
| ^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_typescript_type`
Loading