add testing for wasm (#38)

* 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>
This commit is contained in:
Cynthia Coan 2020-07-23 17:23:08 -06:00 committed by GitHub
parent 9e6a349c8e
commit 1df9ec5f44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 2 deletions

View File

@ -50,6 +50,9 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
target:
- x86_64-unknown-linux-gnu
- wasm32-unknown-unknown
rust:
- stable
- beta
@ -58,11 +61,21 @@ jobs:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
target: ${{ matrix.target }}
toolchain: ${{ matrix.rust }}
override: true
- name: install test runner for wasm
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
if: ${{ matrix.target == 'wasm32-unknown-unknown' }}
- uses: actions-rs/cargo@v1
with:
command: test
target: ${{ matrix.target }}
toolchain: ${{ matrix.rust }}
if: ${{ matrix.target != 'wasm32-unknown-unknown' }}
- name: run wasm tests
run: wasm-pack test --node
if: ${{ matrix.target == 'wasm32-unknown-unknown' }}
test-os:
name: Test Suite

View File

@ -30,6 +30,9 @@ tracing = "0.1.13"
pretty_assertions = "0.6.1"
thiserror = "1.0.19"
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-test = "0.3.15"
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

View File

@ -18,6 +18,7 @@ impl std::error::Error for InstallError {}
/// A representation of a Frame from a Backtrace or a SpanTrace
#[derive(Debug)]
#[non_exhaustive]
pub struct Frame {
/// Frame index
pub n: usize,
@ -27,7 +28,6 @@ pub struct Frame {
pub lineno: Option<u32>,
/// source file path
pub filename: Option<PathBuf>,
_private_ctor: (),
}
impl fmt::Display for Frame {
@ -535,7 +535,6 @@ impl fmt::Display for BacktraceFormatter<'_> {
lineno: sym.lineno(),
filename: sym.filename().map(|x| x.into()),
n,
_private_ctor: (),
})
.collect();

23
tests/wasm.rs Normal file
View File

@ -0,0 +1,23 @@
#[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"));
}