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