rust/ui_test/src/tests.rs

54 lines
2.1 KiB
Rust
Raw Normal View History

2022-05-25 11:08:41 -05:00
use std::path::{Path, PathBuf};
use super::*;
2022-05-25 11:08:41 -05:00
fn config() -> Config {
Config {
args: vec![],
target: None,
stderr_filters: vec![],
stdout_filters: vec![],
root_dir: PathBuf::from("$RUSTROOT"),
2022-05-25 11:08:41 -05:00
mode: Mode::Fail,
2022-05-30 03:27:41 -05:00
path_filter: vec![],
2022-05-25 11:08:41 -05:00
program: PathBuf::from("cake"),
output_conflict_handling: OutputConflictHandling::Error,
}
}
#[test]
fn issue_2156() {
let s = r"
use std::mem;
fn main() {
let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR encountered a dangling reference (address $HEX is unallocated)
}
";
let path = Path::new("$DIR/<dummy>");
let comments = Comments::parse(&path, s);
2022-05-25 11:08:41 -05:00
let mut errors = vec![];
let config = config();
// Crucially, the intended error string *does* appear in this output, as a quote of the comment itself.
let stderr = br"
2022-05-25 11:08:41 -05:00
error: Undefined Behavior: type validation failed: encountered a dangling reference (address 0x10 is unallocated)
--> tests/compile-fail/validity/dangling_ref1.rs:6:29
|
LL | let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR encountered a dangling reference (address $HEX is unallocated)
| ^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a dangling reference (address 0x10 is unallocated)
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: inside `main` at tests/compile-fail/validity/dangling_ref1.rs:6:29
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
error: aborting due to previous error
";
check_test_result(&path, &config, "", "", &comments, &mut errors, /*stdout*/ br"", stderr);
// The "OutputDiffers" is because we cannot open the .rs file
2022-05-25 11:08:41 -05:00
match &errors[..] {
[Error::OutputDiffers { .. }, Error::PatternNotFound { .. }] => {}
2022-05-30 05:28:13 -05:00
_ => panic!("not the expected error: {:#?}", errors),
2022-05-25 11:08:41 -05:00
}
}