Browse Source

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
pull/7953/head
Nick Fitzgerald 9 months ago
committed by GitHub
parent
commit
861f8d309a
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 35
      tests/all/traps.rs

35
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 - <unknown>!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 - <unknown>!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(())
}

Loading…
Cancel
Save