mirror of
https://github.com/eyre-rs/eyre.git
synced 2025-09-27 04:50:50 +00:00

* add testing for wasm utilize wasm-bindgen-test as a developer dependency in order to actively run wasm tests. wasm currently doesn't have support for running doctests (and reportedly won't "anytime soon"), and in order to actually run the tests we need a wasm environment. the easiest of these to setup & use is wasm-pack which is primarly built for nodejs. however, if it works in nodejs it should ideally work in other wasm environments that are similar. as such a wasm-pack (which utilizies wasm-bindgen) as a developer dependency has been added that creates a simple error message, and validates it contains the text of the error (and sections) sans any formatting. this is meant to validate a base level of functionality as time goes on. * fix format * only add dev-dependency for wasm32 * fix clippy warning Co-authored-by: Jane Lusby <jlusby@yaah.dev>
24 lines
783 B
Rust
24 lines
783 B
Rust
#[cfg(target_arch = "wasm32")]
|
|
#[wasm_bindgen_test::wasm_bindgen_test]
|
|
pub fn color_eyre_simple() {
|
|
use color_eyre::eyre::WrapErr;
|
|
use color_eyre::*;
|
|
|
|
install().expect("Failed to install color_eyre");
|
|
let err_str = format!(
|
|
"{:?}",
|
|
Err::<(), Report>(eyre::eyre!("Base Error"))
|
|
.note("A note")
|
|
.suggestion("A suggestion")
|
|
.wrap_err("A wrapped error")
|
|
.unwrap_err()
|
|
);
|
|
// Print it out so if people run with `-- --nocapture`, they
|
|
// can see the full message.
|
|
println!("Error String is:\n\n{}", err_str);
|
|
assert!(err_str.contains("A wrapped error"));
|
|
assert!(err_str.contains("A suggestion"));
|
|
assert!(err_str.contains("A note"));
|
|
assert!(err_str.contains("Base Error"));
|
|
}
|