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