wasm_bindgen_test/
lib.rs

1//! Runtime support for the `#[wasm_bindgen_test]` attribute
2//!
3//! More documentation can be found in the README for this crate!
4
5#![cfg_attr(not(feature = "std"), no_std)]
6#![cfg_attr(target_feature = "atomics", feature(thread_local))]
7#![deny(missing_docs)]
8
9extern crate alloc;
10
11pub use wasm_bindgen_test_macro::{wasm_bindgen_bench, wasm_bindgen_test};
12
13// Custom allocator that only returns pointers in the 2GB-4GB range
14// To ensure we actually support more than 2GB of memory
15#[cfg(all(test, feature = "gg-alloc"))]
16#[global_allocator]
17static A: gg_alloc::GgAlloc<std::alloc::System> = gg_alloc::GgAlloc::new(std::alloc::System);
18
19/// Helper macro which acts like `println!` only routes to `console.error`
20/// instead.
21#[macro_export]
22macro_rules! console_error {
23    ($($arg:tt)*) => (
24        $crate::__rt::console_error(&format_args!($($arg)*))
25    )
26}
27
28/// Helper macro which acts like `println!` only routes to `console.log`
29/// instead.
30#[macro_export]
31macro_rules! console_log {
32    ($($arg:tt)*) => (
33        $crate::__rt::console_log(&format_args!($($arg)*))
34    )
35}
36
37/// A macro used to configured how this test is executed by the
38/// `wasm-bindgen-test-runner` harness.
39///
40/// This macro is invoked as:
41///
42/// ```ignore
43/// wasm_bindgen_test_configure!(foo bar baz);
44/// ```
45///
46/// where all of `foo`, `bar`, and `baz`, would be recognized options to this
47/// macro. The currently known options to this macro are:
48///
49/// * `run_in_browser` - requires that this test is run in a browser rather than
50///   node.js, which is the default for executing tests.
51/// * `run_in_dedicated_worker` - requires that this test is run in a web worker rather than
52///   node.js, which is the default for executing tests.
53/// * `run_in_shared_worker` - requires that this test is run in a shared worker rather than
54///   node.js, which is the default for executing tests.
55/// * `run_in_service_worker` - requires that this test is run in a service worker rather than
56///   node.js, which is the default for executing tests.
57///
58/// This macro may be invoked at most one time per test suite (an entire binary
59/// like `tests/foo.rs`, not per module)
60#[macro_export]
61macro_rules! wasm_bindgen_test_configure {
62    (run_in_browser $($others:tt)*) => (
63        const _: () = {
64            #[link_section = "__wasm_bindgen_test_unstable"]
65            #[cfg(target_arch = "wasm32")]
66            pub static __WBG_TEST_RUN_IN_BROWSER: [u8; 1] = [0x01];
67            $crate::wasm_bindgen_test_configure!($($others)*);
68        };
69    );
70    (run_in_worker $($others:tt)*) => (
71        const _: () = {
72            #[link_section = "__wasm_bindgen_test_unstable"]
73            #[cfg(target_arch = "wasm32")]
74            pub static __WBG_TEST_RUN_IN_DEDICATED_WORKER: [u8; 1] = [0x02];
75            $crate::wasm_bindgen_test_configure!($($others)*);
76        };
77    );
78    (run_in_dedicated_worker $($others:tt)*) => (
79        const _: () = {
80            #[link_section = "__wasm_bindgen_test_unstable"]
81            #[cfg(target_arch = "wasm32")]
82            pub static __WBG_TEST_RUN_IN_DEDICATED_WORKER: [u8; 1] = [0x02];
83            $crate::wasm_bindgen_test_configure!($($others)*);
84        };
85    );
86    (run_in_shared_worker $($others:tt)*) => (
87        const _: () = {
88            #[link_section = "__wasm_bindgen_test_unstable"]
89            #[cfg(target_arch = "wasm32")]
90            pub static __WBG_TEST_RUN_IN_SHARED_WORKER: [u8; 1] = [0x03];
91            $crate::wasm_bindgen_test_configure!($($others)*);
92        };
93    );
94    (run_in_service_worker $($others:tt)*) => (
95        const _: () = {
96            #[link_section = "__wasm_bindgen_test_unstable"]
97            #[cfg(target_arch = "wasm32")]
98            pub static __WBG_TEST_RUN_IN_SERVICE_WORKER: [u8; 1] = [0x04];
99            $crate::wasm_bindgen_test_configure!($($others)*);
100        };
101    );
102    (run_in_node_experimental $($others:tt)*) => (
103        const _: () = {
104            #[link_section = "__wasm_bindgen_test_unstable"]
105            #[cfg(target_arch = "wasm32")]
106            pub static __WBG_TEST_run_in_node_experimental: [u8; 1] = [0x05];
107            $crate::wasm_bindgen_test_configure!($($others)*);
108        };
109    );
110    () => ()
111}
112
113#[path = "rt/mod.rs"]
114pub mod __rt;
115
116// Make this only available to wasm32 so that we don't
117// import minicov on other archs.
118// That way you can use normal cargo test without minicov
119#[cfg(target_arch = "wasm32")]
120mod coverage;
121
122// <https://github.com/bheisler/criterion.rs>
123//
124// A modified `criterion.rs`, retaining only the basic benchmark capabilities.
125pub use __rt::criterion::Criterion;