A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Make some error message assertions more-precisely test what we care about (#12305)
Nick Fitzgerald09cc97e8b28b
diff --git a/crates/wasmtime/src/engine/serialization.rs b/crates/wasmtime/src/engine/serialization.rsindex aeb962d853..3584e07b06 100644--- a/crates/wasmtime/src/engine/serialization.rs+++ b/crates/wasmtime/src/engine/serialization.rs@@ -479,6 +479,15 @@ mod test {Ok(())}+ fn assert_contains(error: &Error, msg: &str) {+ let msg = msg.trim();+ if error.chain().any(|e| e.to_string().contains(msg)) {+ return;+ }++ panic!("failed to find:\n\n'''{msg}\n'''\n\nwithin error message:\n\n'''{error:?}'''")+ }+#[test]fn test_cranelift_flags_mismatch() -> Result<()> {let engine = Engine::default();@@ -490,13 +499,16 @@ mod test {match metadata.check_compatible(&engine) {Ok(_) => unreachable!(),- Err(e) => assert!(format!("{e:?}").starts_with(- "\-compilation settings of module incompatible with native host--Caused by:- setting \"preserve_frame_pointers\" is configured to Bool(false) which is not supported"- )),+ Err(e) => {+ assert_contains(+ &e,+ "compilation settings of module incompatible with native host",+ );+ assert_contains(+ &e,+ "setting \"preserve_frame_pointers\" is configured to Bool(false) which is not supported",+ );+ }}Ok(())@@ -513,16 +525,16 @@ Caused by:match metadata.check_compatible(&engine) {Ok(_) => unreachable!(),- Err(e) => assert!(- format!("{e:?}").starts_with(- "\-compilation settings of module incompatible with native host--Caused by:- don't know how to test for target-specific flag \"not_a_flag\" at runtime",- ),- "bad error {e:?}",- ),+ Err(e) => {+ assert_contains(+ &e,+ "compilation settings of module incompatible with native host",+ );+ assert_contains(+ &e,+ "don't know how to test for target-specific flag \"not_a_flag\" at runtime",+ );+ }}Ok(())