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

Structs whose name begins with "Test" cause run-time failures in wasm-bindgen-test tests #2121

Closed
prestwich opened this issue May 3, 2020 · 1 comment · Fixed by #2123
Closed
Labels

Comments

@prestwich
Copy link

prestwich commented May 3, 2020

Describe the Bug

When using wasm-bindgen-test via wasm-pack test, if any struct have a name beginning with Test or test and have the #[wasm-bindgen] macro the tests will fail to run.

Steps to Reproduce

  1. wasm-bindgen = "0.2.62"
  2. wasm-bindgen-test = "0.3.12"
  3. Add the following to a fresth lib.rs and run wasm-pack test --node.
#[wasm_bindgen]
pub struct Test;

#[cfg(test)]
pub mod test {
    use wasm_bindgen_test::*;

    #[wasm_bindgen_test]
    fn pass() {
        assert_eq!(1, 1);
    }
}

Actual Behavior

These struct names work:

  • ConnectionTest
  • SocketTest
  • ATest
  • Attestation

These names fail:

  • Test
  • TestConnection
  • Testnet
  • Testify
  • test
  • testify

Removing the #[wasm-bindgen] macro causes everything to succeed. Packages can be built succesfully, imported into Node, and used normally. Only tests break

Failures produce the following error message (stack information has been trimmed):

$ wasm-pack test --node

panicked at 'exception thrown while creating a test: Error: recursive use of an object detected which would lead to unsafe aliasing in rust
@prestwich prestwich added the bug label May 3, 2020
alexcrichton added a commit to alexcrichton/wasm-bindgen that referenced this issue May 4, 2020
There was an unfortunate collision with how test symbols were named and
the various bindings functions exported by wasm-bindgen. This commit
fixes these issues by using a separate prefix for `#[wasm_bindgen_test]`
than other `#[wasm_bindgen]` functions which should avoid the name
clash.

Closes rustwasm#2121
@alexcrichton
Copy link
Contributor

Oh dear what a bizarre bug! Should be fixed in #2123 though, thanks for the report!

alexcrichton added a commit that referenced this issue May 4, 2020
There was an unfortunate collision with how test symbols were named and
the various bindings functions exported by wasm-bindgen. This commit
fixes these issues by using a separate prefix for `#[wasm_bindgen_test]`
than other `#[wasm_bindgen]` functions which should avoid the name
clash.

Closes #2121
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants