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