Reproduce #2156
This commit is contained in:
parent
e7c2ab6d5b
commit
23bbe2bce7
1
ui_test/.gitignore
vendored
Normal file
1
ui_test/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
Cargo.lock
|
@ -5,7 +5,7 @@ use regex::Regex;
|
|||||||
/// This crate supports various magic comments that get parsed as file-specific
|
/// This crate supports various magic comments that get parsed as file-specific
|
||||||
/// configuration values. This struct parses them all in one go and then they
|
/// configuration values. This struct parses them all in one go and then they
|
||||||
/// get processed by their respective use sites.
|
/// get processed by their respective use sites.
|
||||||
#[derive(Default)]
|
#[derive(Default, Debug)]
|
||||||
pub struct Comments {
|
pub struct Comments {
|
||||||
/// List of revision names to execute. Can only be speicified once
|
/// List of revision names to execute. Can only be speicified once
|
||||||
pub revisions: Option<Vec<String>>,
|
pub revisions: Option<Vec<String>>,
|
||||||
@ -26,6 +26,7 @@ pub struct Comments {
|
|||||||
pub error_matches: Vec<ErrorMatch>,
|
pub error_matches: Vec<ErrorMatch>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct ErrorMatch {
|
pub struct ErrorMatch {
|
||||||
pub matched: String,
|
pub matched: String,
|
||||||
pub revision: Option<String>,
|
pub revision: Option<String>,
|
||||||
@ -33,9 +34,13 @@ pub struct ErrorMatch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Comments {
|
impl Comments {
|
||||||
pub fn parse(path: &Path) -> Self {
|
pub fn parse_file(path: &Path) -> Self {
|
||||||
let mut this = Self::default();
|
|
||||||
let content = std::fs::read_to_string(path).unwrap();
|
let content = std::fs::read_to_string(path).unwrap();
|
||||||
|
Self::parse(path, &content)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse(path: &Path, content: &str) -> Self {
|
||||||
|
let mut this = Self::default();
|
||||||
let error_pattern_regex =
|
let error_pattern_regex =
|
||||||
Regex::new(r"//(\[(?P<revision>[^\]]+)\])?~[|^]*\s*(ERROR|HELP|WARN)?:?(?P<text>.*)")
|
Regex::new(r"//(\[(?P<revision>[^\]]+)\])?~[|^]*\s*(ERROR|HELP|WARN)?:?(?P<text>.*)")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -9,7 +9,7 @@ use comments::ErrorMatch;
|
|||||||
use crossbeam::queue::SegQueue;
|
use crossbeam::queue::SegQueue;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
use crate::comments::Comments;
|
pub use crate::comments::Comments;
|
||||||
|
|
||||||
mod comments;
|
mod comments;
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ pub fn run_tests(config: Config) {
|
|||||||
if !path.extension().map(|ext| ext == "rs").unwrap_or(false) {
|
if !path.extension().map(|ext| ext == "rs").unwrap_or(false) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let comments = Comments::parse(&path);
|
let comments = Comments::parse_file(&path);
|
||||||
// Ignore file if only/ignore rules do (not) apply
|
// Ignore file if only/ignore rules do (not) apply
|
||||||
if ignore_file(&comments, &target) {
|
if ignore_file(&comments, &target) {
|
||||||
ignored.fetch_add(1, Ordering::Relaxed);
|
ignored.fetch_add(1, Ordering::Relaxed);
|
||||||
@ -171,7 +171,7 @@ pub fn run_tests(config: Config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum Error {
|
pub enum Error {
|
||||||
/// Got an invalid exit status for the given mode.
|
/// Got an invalid exit status for the given mode.
|
||||||
ExitStatus(Mode, ExitStatus),
|
ExitStatus(Mode, ExitStatus),
|
||||||
PatternNotFound {
|
PatternNotFound {
|
||||||
@ -191,7 +191,7 @@ enum Error {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
type Errors = Vec<Error>;
|
pub type Errors = Vec<Error>;
|
||||||
|
|
||||||
fn run_test(
|
fn run_test(
|
||||||
path: &Path,
|
path: &Path,
|
||||||
@ -249,7 +249,7 @@ fn run_test(
|
|||||||
(miri, errors)
|
(miri, errors)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_annotations(
|
pub fn check_annotations(
|
||||||
unnormalized_stderr: &[u8],
|
unnormalized_stderr: &[u8],
|
||||||
errors: &mut Errors,
|
errors: &mut Errors,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
|
49
ui_test/tests/check_annotations.rs
Normal file
49
ui_test/tests/check_annotations.rs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
use ui_test::{check_annotations, Comments, Config, Error, Mode, OutputConflictHandling};
|
||||||
|
|
||||||
|
fn config() -> Config {
|
||||||
|
Config {
|
||||||
|
args: vec![],
|
||||||
|
target: None,
|
||||||
|
stderr_filters: vec![],
|
||||||
|
stdout_filters: vec![],
|
||||||
|
root_dir: PathBuf::from("."),
|
||||||
|
mode: Mode::Fail,
|
||||||
|
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 comments = Comments::parse(Path::new("<dummy>"), s);
|
||||||
|
let mut errors = vec![];
|
||||||
|
let config = config();
|
||||||
|
let unnormalized_stderr = r"
|
||||||
|
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_annotations(unnormalized_stderr.as_bytes(), &mut errors, &config, "", &comments);
|
||||||
|
match &errors[..] {
|
||||||
|
[Error::PatternNotFound { .. }] => {}
|
||||||
|
_ => panic!("{:#?}", errors),
|
||||||
|
}
|
||||||
|
}
|
22
ui_test/tests/comment_parser.rs
Normal file
22
ui_test/tests/comment_parser.rs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use ui_test::Comments;
|
||||||
|
|
||||||
|
#[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 comments = Comments::parse(Path::new("<dummy>"), s);
|
||||||
|
println!("{:#?}", comments);
|
||||||
|
assert_eq!(comments.error_matches[0].definition_line, 4);
|
||||||
|
assert_eq!(comments.error_matches[0].revision, None);
|
||||||
|
assert_eq!(
|
||||||
|
comments.error_matches[0].matched,
|
||||||
|
"encountered a dangling reference (address $HEX is unallocated)"
|
||||||
|
);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user