Skip to content

Commit

Permalink
chore: move tests of default behavior of 'wasm_error!()' into common …
Browse files Browse the repository at this point in the history
…crate where it is defined
  • Loading branch information
mattyg committed Dec 20, 2024
1 parent d2d18c7 commit abcdab4
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 23 deletions.
44 changes: 44 additions & 0 deletions crates/common/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,47 @@ impl From<&str> for WasmErrorInner {
s.to_string().into()
}
}


#[cfg(test)]
mod tests {
use super::*;

#[test]
#[cfg(not(feature = "error_as_host"))]
fn wasm_error_macro_guest() {
assert_eq!(
wasm_error!("foo").error,
WasmErrorInner::Guest("foo".into()),
);

assert_eq!(
wasm_error!("{} {}", "foo", "bar").error,
WasmErrorInner::Guest("foo bar".into())
);

assert_eq!(
wasm_error!(WasmErrorInner::Host("foo".into())).error,
WasmErrorInner::Host("foo".into()),
);
}

#[test]
#[cfg(feature = "error_as_host")]
fn wasm_error_macro_host() {
assert_eq!(
wasm_error!("foo").error,
WasmErrorInner::Host("foo".into()),
);

assert_eq!(
wasm_error!("{} {}", "foo", "bar").error,
WasmErrorInner::Host("foo bar".into())
);

assert_eq!(
wasm_error!(WasmErrorInner::Guest("foo".into())).error,
WasmErrorInner::Guest("foo".into()),
);
}
}
23 changes: 0 additions & 23 deletions crates/host/src/guest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,26 +261,3 @@ where

return_value.map_err(|e| WasmHostError(e).into())
}

#[cfg(test)]
pub mod tests {
use super::*;

#[test]
fn wasm_error_macro_host() {
assert_eq!(
wasm_error!("foo").0.error,
WasmErrorInner::Host("foo".into()),
);

assert_eq!(
wasm_error!("{} {}", "foo", "bar").0.error,
WasmErrorInner::Host("foo bar".into())
);

assert_eq!(
wasm_error!(WasmErrorInner::Host("foo".into())).0.error,
WasmErrorInner::Host("foo".into()),
);
}
}
3 changes: 3 additions & 0 deletions scripts/test-wasmer_sys_dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ cargo clippy -- --deny warnings
cargo build --release -p test_wasm_core --target wasm32-unknown-unknown

# tests the root workspace
cargo test --no-default-features --features wasmer_sys_dev ${1-} -- --nocapture

# tests the root workspace, error_as_host
cargo test --no-default-features --features error_as_host,wasmer_sys_dev ${1-} -- --nocapture

# build wasm and run the "full" tests for wasmer_sys_dev
Expand Down
3 changes: 3 additions & 0 deletions scripts/test-wasmer_sys_prod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export RUST_BACKTRACE=full
export WASMER_BACKTRACE=1

# tests the root workspace
cargo test --no-default-features --features wasmer_sys_prod ${1-} -- --nocapture

# tests the root workspace, error_as_host
cargo test --no-default-features --features error_as_host,wasmer_sys_prod ${1-} -- --nocapture

# build wasm and run the "full" tests for wasmer_sys_prod
Expand Down
3 changes: 3 additions & 0 deletions scripts/test-wasmer_wamr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export WASMER_BACKTRACE=1


# tests the root workspace
cargo test --no-default-features --features wasmer_wamr ${1-} -- --nocapture

# tests the root workspace, error_as_host
cargo test --no-default-features --features error_as_host,wasmer_wamr ${1-} -- --nocapture

# build wasm and run the "full" tests for wasmer_wamr
Expand Down

0 comments on commit abcdab4

Please sign in to comment.