From 861f8d309a90b74ea79a26c4e36afe648bdadd45 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Fri, 16 Feb 2024 08:50:51 -0800 Subject: [PATCH] Allow `traps.rs` tests to pass even when `RUST_BACKTRACE=1` on nightly Rust (#7950) * Allow `traps.rs` tests to pass even when `RUST_BACKTRACE=1` on nightly Rust Instead of asserting exact error messages, which `anyhow` auto adds Rust backtrace to on nightly, assert that the important bits are there. * Use `contains` on the whole error message when possible --- tests/all/traps.rs | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/tests/all/traps.rs b/tests/all/traps.rs index 1cfc97ae6a..e7f3596a20 100644 --- a/tests/all/traps.rs +++ b/tests/all/traps.rs @@ -307,8 +307,8 @@ fn trap_display_pretty() -> Result<()> { let run_func = instance.get_typed_func::<(), ()>(&mut store, "bar")?; let e = run_func.call(&mut store, ()).unwrap_err(); - assert_eq!( - format!("{:?}", e), + let e = format!("{e:?}"); + assert!(e.contains( "\ error while executing at wasm backtrace: 0: 0x23 - m!die @@ -319,7 +319,7 @@ error while executing at wasm backtrace: Caused by: wasm trap: wasm `unreachable` instruction executed\ " - ); + )); Ok(()) } @@ -351,8 +351,8 @@ fn trap_display_multi_module() -> Result<()> { let bar2 = instance.get_typed_func::<(), ()>(&mut store, "bar2")?; let e = bar2.call(&mut store, ()).unwrap_err(); - assert_eq!( - format!("{e:?}"), + let e = format!("{e:?}"); + assert!(e.contains( "\ error while executing at wasm backtrace: 0: 0x23 - a!die @@ -365,7 +365,7 @@ error while executing at wasm backtrace: Caused by: wasm trap: wasm `unreachable` instruction executed\ " - ); + )); Ok(()) } @@ -592,11 +592,10 @@ fn start_trap_pretty() -> Result<()> { let module = Module::new(store.engine(), wat)?; let e = match Instance::new(&mut store, &module, &[]) { Ok(_) => panic!("expected failure"), - Err(e) => e, + Err(e) => format!("{e:?}"), }; - assert_eq!( - format!("{e:?}"), + assert!(e.contains( "\ error while executing at wasm backtrace: 0: 0x1d - m!die @@ -607,7 +606,7 @@ error while executing at wasm backtrace: Caused by: wasm trap: wasm `unreachable` instruction executed\ " - ); + )); Ok(()) } @@ -800,8 +799,8 @@ fn no_hint_even_with_dwarf_info() -> Result<()> { "#, )?; let trap = Instance::new(&mut store, &module, &[]).unwrap_err(); - assert_eq!( - format!("{trap:?}"), + let trap = format!("{trap:?}"); + assert!(trap.contains( "\ error while executing at wasm backtrace: 0: 0x1a - !start @@ -809,7 +808,8 @@ error while executing at wasm backtrace: Caused by: wasm trap: wasm `unreachable` instruction executed\ " - ); + )); + assert!(!trap.contains("WASM_BACKTRACE_DETAILS")); Ok(()) } @@ -833,17 +833,16 @@ fn hint_with_dwarf_info() -> Result<()> { "#, )?; let trap = Instance::new(&mut store, &module, &[]).unwrap_err(); - assert_eq!( - format!("{trap:?}"), + let trap = format!("{trap:?}"); + assert!(trap.contains( "\ error while executing at wasm backtrace: 0: 0x1a - !start note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable may show more debugging information Caused by: - wasm trap: wasm `unreachable` instruction executed\ -" - ); + wasm trap: wasm `unreachable` instruction executed" + )); Ok(()) }