From 23bbe2bce72c4674ef46507a2db1e4e5e55ff3ff Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 25 May 2022 16:08:41 +0000 Subject: [PATCH 01/13] Reproduce #2156 --- ui_test/.gitignore | 1 + ui_test/src/comments.rs | 11 +++++-- ui_test/src/lib.rs | 10 +++--- ui_test/tests/check_annotations.rs | 49 ++++++++++++++++++++++++++++++ ui_test/tests/comment_parser.rs | 22 ++++++++++++++ 5 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 ui_test/.gitignore create mode 100644 ui_test/tests/check_annotations.rs create mode 100644 ui_test/tests/comment_parser.rs diff --git a/ui_test/.gitignore b/ui_test/.gitignore new file mode 100644 index 0000000000..03314f77b5 --- /dev/null +++ b/ui_test/.gitignore @@ -0,0 +1 @@ +Cargo.lock diff --git a/ui_test/src/comments.rs b/ui_test/src/comments.rs index 14566d2fec..193cda68b9 100644 --- a/ui_test/src/comments.rs +++ b/ui_test/src/comments.rs @@ -5,7 +5,7 @@ use regex::Regex; /// 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 /// get processed by their respective use sites. -#[derive(Default)] +#[derive(Default, Debug)] pub struct Comments { /// List of revision names to execute. Can only be speicified once pub revisions: Option>, @@ -26,6 +26,7 @@ pub struct Comments { pub error_matches: Vec, } +#[derive(Debug)] pub struct ErrorMatch { pub matched: String, pub revision: Option, @@ -33,9 +34,13 @@ pub struct ErrorMatch { } impl Comments { - pub fn parse(path: &Path) -> Self { - let mut this = Self::default(); + pub fn parse_file(path: &Path) -> Self { 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 = Regex::new(r"//(\[(?P[^\]]+)\])?~[|^]*\s*(ERROR|HELP|WARN)?:?(?P.*)") .unwrap(); diff --git a/ui_test/src/lib.rs b/ui_test/src/lib.rs index b779d6844a..4f7e55fdce 100644 --- a/ui_test/src/lib.rs +++ b/ui_test/src/lib.rs @@ -9,7 +9,7 @@ use comments::ErrorMatch; use crossbeam::queue::SegQueue; use regex::Regex; -use crate::comments::Comments; +pub use crate::comments::Comments; mod comments; @@ -73,7 +73,7 @@ pub fn run_tests(config: Config) { if !path.extension().map(|ext| ext == "rs").unwrap_or(false) { continue; } - let comments = Comments::parse(&path); + let comments = Comments::parse_file(&path); // Ignore file if only/ignore rules do (not) apply if ignore_file(&comments, &target) { ignored.fetch_add(1, Ordering::Relaxed); @@ -171,7 +171,7 @@ pub fn run_tests(config: Config) { } #[derive(Debug)] -enum Error { +pub enum Error { /// Got an invalid exit status for the given mode. ExitStatus(Mode, ExitStatus), PatternNotFound { @@ -191,7 +191,7 @@ enum Error { }, } -type Errors = Vec; +pub type Errors = Vec; fn run_test( path: &Path, @@ -249,7 +249,7 @@ fn run_test( (miri, errors) } -fn check_annotations( +pub fn check_annotations( unnormalized_stderr: &[u8], errors: &mut Errors, config: &Config, diff --git a/ui_test/tests/check_annotations.rs b/ui_test/tests/check_annotations.rs new file mode 100644 index 0000000000..4735fe1fa0 --- /dev/null +++ b/ui_test/tests/check_annotations.rs @@ -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(""), 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), + } +} diff --git a/ui_test/tests/comment_parser.rs b/ui_test/tests/comment_parser.rs new file mode 100644 index 0000000000..ee1382a6c7 --- /dev/null +++ b/ui_test/tests/comment_parser.rs @@ -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(""), 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)" + ); +} From 21795f3ce4eabfce2fd5d36e0d9852bde9d52158 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 25 May 2022 16:11:37 +0000 Subject: [PATCH 02/13] Fix annotations matching themselves --- ui_test/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ui_test/src/lib.rs b/ui_test/src/lib.rs index 4f7e55fdce..f657be4ea6 100644 --- a/ui_test/src/lib.rs +++ b/ui_test/src/lib.rs @@ -257,6 +257,9 @@ pub fn check_annotations( comments: &Comments, ) { let unnormalized_stderr = std::str::from_utf8(unnormalized_stderr).unwrap(); + // erase annotations from the stderr so they don't match themselves + let annotations = Regex::new(r"\s*//~.*").unwrap(); + let unnormalized_stderr = annotations.replace(unnormalized_stderr, ""); let mut found_annotation = false; if let Some((ref error_pattern, definition_line)) = comments.error_pattern { if !unnormalized_stderr.contains(error_pattern) { From b64a1c46c67c58e2da05c67ef1b2d73dd756549c Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 25 May 2022 16:15:31 +0000 Subject: [PATCH 03/13] Make the file path of the failure more visible to be able to click it faster --- ui_test/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui_test/src/lib.rs b/ui_test/src/lib.rs index f657be4ea6..ba1f874413 100644 --- a/ui_test/src/lib.rs +++ b/ui_test/src/lib.rs @@ -129,7 +129,7 @@ pub fn run_tests(config: Config) { eprintln!("`{pattern}` {} in stderr output", "not found".red()); eprintln!( "expected because of pattern here: {}:{definition_line}", - path.display() + path.display().to_string().bold() ); dump_stderr = Some(stderr.clone()) } From 8acfbc3b3332ed7f5364bc38c947c6c083ef99df Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 25 May 2022 16:15:37 +0000 Subject: [PATCH 04/13] Update all tests --- tests/compile-fail/intrinsics/copy_unaligned.rs | 2 +- .../compile-fail/stacked_borrows/static_memory_modification.rs | 2 +- tests/compile-fail/unaligned_pointers/dyn_alignment.rs | 2 +- .../unaligned_pointers/intptrcast_alignment_check.rs | 2 +- tests/compile-fail/unaligned_pointers/reference_to_packed.rs | 2 +- tests/compile-fail/unaligned_pointers/unaligned_ptr1.rs | 2 +- tests/compile-fail/unaligned_pointers/unaligned_ptr2.rs | 2 +- tests/compile-fail/unaligned_pointers/unaligned_ptr_addr_of.rs | 2 +- tests/compile-fail/unaligned_pointers/unaligned_ptr_zst.rs | 2 +- tests/compile-fail/validity/dangling_ref1.rs | 2 +- tests/compile-fail/validity/invalid_char.rs | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/compile-fail/intrinsics/copy_unaligned.rs b/tests/compile-fail/intrinsics/copy_unaligned.rs index 7aff0adc40..84f4de9346 100644 --- a/tests/compile-fail/intrinsics/copy_unaligned.rs +++ b/tests/compile-fail/intrinsics/copy_unaligned.rs @@ -9,5 +9,5 @@ fn main() { let mut data = [0u16; 8]; let ptr = (&mut data[0] as *mut u16 as *mut u8).wrapping_add(1) as *mut u16; // Even copying 0 elements to something unaligned should error - unsafe { copy_nonoverlapping(&data[5], ptr, 0); } //~ ERROR accessing memory with alignment ALIGN, but alignment ALIGN is required + unsafe { copy_nonoverlapping(&data[5], ptr, 0); } //~ ERROR accessing memory with alignment 1, but alignment 2 is required } diff --git a/tests/compile-fail/stacked_borrows/static_memory_modification.rs b/tests/compile-fail/stacked_borrows/static_memory_modification.rs index 72e2ed9381..417a03bb03 100644 --- a/tests/compile-fail/stacked_borrows/static_memory_modification.rs +++ b/tests/compile-fail/stacked_borrows/static_memory_modification.rs @@ -3,6 +3,6 @@ static X: usize = 5; #[allow(mutable_transmutes)] fn main() { let _x = unsafe { - std::mem::transmute::<&usize, &mut usize>(&X) //~ ERROR writing to ALLOC which is read-only + std::mem::transmute::<&usize, &mut usize>(&X) //~ ERROR writing to alloc1 which is read-only }; } diff --git a/tests/compile-fail/unaligned_pointers/dyn_alignment.rs b/tests/compile-fail/unaligned_pointers/dyn_alignment.rs index 9d8829fe1e..91d9ec475b 100644 --- a/tests/compile-fail/unaligned_pointers/dyn_alignment.rs +++ b/tests/compile-fail/unaligned_pointers/dyn_alignment.rs @@ -16,6 +16,6 @@ fn main() { // Overwrite the data part of `ptr` so it points to `buf`. unsafe { (&mut ptr as *mut _ as *mut *const u8).write(&buf as *const _ as *const u8); } // Re-borrow that. This should be UB. - let _ptr = &*ptr; //~ERROR alignment ALIGN is required + let _ptr = &*ptr; //~ERROR alignment 256 is required } } diff --git a/tests/compile-fail/unaligned_pointers/intptrcast_alignment_check.rs b/tests/compile-fail/unaligned_pointers/intptrcast_alignment_check.rs index a8d0b5afbb..9872a493c0 100644 --- a/tests/compile-fail/unaligned_pointers/intptrcast_alignment_check.rs +++ b/tests/compile-fail/unaligned_pointers/intptrcast_alignment_check.rs @@ -12,6 +12,6 @@ fn main() { // Manually make sure the pointer is properly aligned. let base_addr_aligned = if base_addr % 2 == 0 { base_addr } else { base_addr+1 }; let u16_ptr = base_addr_aligned as *mut u16; - unsafe { *u16_ptr = 2; } //~ERROR memory with alignment ALIGN, but alignment ALIGN is required + unsafe { *u16_ptr = 2; } //~ERROR memory with alignment 1, but alignment 2 is required println!("{:?}", x); } diff --git a/tests/compile-fail/unaligned_pointers/reference_to_packed.rs b/tests/compile-fail/unaligned_pointers/reference_to_packed.rs index 60d2524040..b376859d22 100644 --- a/tests/compile-fail/unaligned_pointers/reference_to_packed.rs +++ b/tests/compile-fail/unaligned_pointers/reference_to_packed.rs @@ -16,6 +16,6 @@ fn main() { y: 99, }; let p = &foo.x; - let i = *p; //~ERROR alignment ALIGN is required + let i = *p; //~ERROR alignment 4 is required } } diff --git a/tests/compile-fail/unaligned_pointers/unaligned_ptr1.rs b/tests/compile-fail/unaligned_pointers/unaligned_ptr1.rs index fe46e7b8ad..1d72e5170b 100644 --- a/tests/compile-fail/unaligned_pointers/unaligned_ptr1.rs +++ b/tests/compile-fail/unaligned_pointers/unaligned_ptr1.rs @@ -6,6 +6,6 @@ fn main() { let x = [2u16, 3, 4]; // Make it big enough so we don't get an out-of-bounds error. let x = &x[0] as *const _ as *const u32; // This must fail because alignment is violated: the allocation's base is not sufficiently aligned. - let _x = unsafe { *x }; //~ERROR memory with alignment ALIGN, but alignment ALIGN is required + let _x = unsafe { *x }; //~ERROR memory with alignment 2, but alignment 4 is required } } diff --git a/tests/compile-fail/unaligned_pointers/unaligned_ptr2.rs b/tests/compile-fail/unaligned_pointers/unaligned_ptr2.rs index 1d1e7fad05..49612e2b8a 100644 --- a/tests/compile-fail/unaligned_pointers/unaligned_ptr2.rs +++ b/tests/compile-fail/unaligned_pointers/unaligned_ptr2.rs @@ -8,5 +8,5 @@ fn main() { let x = (x.as_ptr() as *const u8).wrapping_offset(3) as *const u32; // This must fail because alignment is violated: the offset is not sufficiently aligned. // Also make the offset not a power of 2, that used to ICE. - let _x = unsafe { *x }; //~ERROR memory with alignment ALIGN, but alignment ALIGN is required + let _x = unsafe { *x }; //~ERROR memory with alignment 1, but alignment 4 is required } diff --git a/tests/compile-fail/unaligned_pointers/unaligned_ptr_addr_of.rs b/tests/compile-fail/unaligned_pointers/unaligned_ptr_addr_of.rs index d97306b3cb..e33f3c8598 100644 --- a/tests/compile-fail/unaligned_pointers/unaligned_ptr_addr_of.rs +++ b/tests/compile-fail/unaligned_pointers/unaligned_ptr_addr_of.rs @@ -8,6 +8,6 @@ fn main() { let x = &x[0] as *const _ as *const u32; // This must fail because alignment is violated: the allocation's base is not sufficiently aligned. // The deref is UB even if we just put the result into a raw pointer. - let _x = unsafe { ptr::addr_of!(*x) }; //~ ERROR memory with alignment ALIGN, but alignment ALIGN is required + let _x = unsafe { ptr::addr_of!(*x) }; //~ ERROR memory with alignment 2, but alignment 4 is required } } diff --git a/tests/compile-fail/unaligned_pointers/unaligned_ptr_zst.rs b/tests/compile-fail/unaligned_pointers/unaligned_ptr_zst.rs index c549688c26..27403c11ab 100644 --- a/tests/compile-fail/unaligned_pointers/unaligned_ptr_zst.rs +++ b/tests/compile-fail/unaligned_pointers/unaligned_ptr_zst.rs @@ -7,6 +7,6 @@ fn main() { let x = i as u8; let x = &x as *const _ as *const [u32; 0]; // This must fail because alignment is violated. Test specifically for loading ZST. - let _x = unsafe { *x }; //~ERROR alignment ALIGN is required + let _x = unsafe { *x }; //~ERROR alignment 4 is required } } diff --git a/tests/compile-fail/validity/dangling_ref1.rs b/tests/compile-fail/validity/dangling_ref1.rs index 3243eee06e..78425cde4a 100644 --- a/tests/compile-fail/validity/dangling_ref1.rs +++ b/tests/compile-fail/validity/dangling_ref1.rs @@ -3,5 +3,5 @@ use std::mem; fn main() { - let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR encountered a dangling reference (address $HEX is unallocated) + let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR encountered a dangling reference (address 0x10 is unallocated) } diff --git a/tests/compile-fail/validity/invalid_char.rs b/tests/compile-fail/validity/invalid_char.rs index d9a55f241c..079823f894 100644 --- a/tests/compile-fail/validity/invalid_char.rs +++ b/tests/compile-fail/validity/invalid_char.rs @@ -1,6 +1,6 @@ fn main() { assert!(std::char::from_u32(-1_i32 as u32).is_none()); - let _val = match unsafe { std::mem::transmute::(-1) } { //~ ERROR encountered $HEX, but expected a valid unicode scalar value + let _val = match unsafe { std::mem::transmute::(-1) } { //~ ERROR encountered 0xffffffff, but expected a valid unicode scalar value 'a' => {true}, 'b' => {false}, _ => {true}, From e4d6c00aa2cc1ad794f57cdae4eeee9878f14f0a Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 25 May 2022 17:48:03 +0000 Subject: [PATCH 05/13] Run tests for ui_test together with miri test --- miri | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/miri b/miri index 6a809b7435..3846eb795a 100755 --- a/miri +++ b/miri @@ -134,7 +134,8 @@ test|test-debug|bless|bless-debug) esac # Then test, and let caller control flags. # Only in root project as `cargo-miri` has no tests. - exec cargo test $CARGO_BUILD_FLAGS "$@" + cargo test $CARGO_BUILD_FLAGS "$@" + cargo test --manifest-path ui_test/Cargo.toml ;; run|run-debug) # Scan for "--target" to set the "MIRI_TEST_TARGET" env var so From d466eb8f664a4436e5913a387fc26446f161c22a Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 25 May 2022 17:53:39 +0000 Subject: [PATCH 06/13] Explain `Comments::parse` arguments --- ui_test/src/comments.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ui_test/src/comments.rs b/ui_test/src/comments.rs index 193cda68b9..64f999f541 100644 --- a/ui_test/src/comments.rs +++ b/ui_test/src/comments.rs @@ -39,6 +39,8 @@ impl Comments { Self::parse(path, &content) } + /// Parse comments in `content`. + /// `path` is only used to emit diagnostics if parsing fails. pub fn parse(path: &Path, content: &str) -> Self { let mut this = Self::default(); let error_pattern_regex = From 25b7a12625f65229b924adb9f4a9b431da873ed1 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 25 May 2022 17:58:45 +0000 Subject: [PATCH 07/13] Properly name a test --- ui_test/tests/comment_parser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui_test/tests/comment_parser.rs b/ui_test/tests/comment_parser.rs index ee1382a6c7..a9e19cbb9c 100644 --- a/ui_test/tests/comment_parser.rs +++ b/ui_test/tests/comment_parser.rs @@ -3,7 +3,7 @@ use std::path::Path; use ui_test::Comments; #[test] -fn issue_2156() { +fn parse_simple_comment() { let s = r" use std::mem; From a51ae9fb2c9bbfa6abb5eafb66d393afd00933e7 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 25 May 2022 18:24:55 +0000 Subject: [PATCH 08/13] Use unit tests to keep private things private --- ui_test/src/comments.rs | 3 +++ .../{tests/comment_parser.rs => src/comments/tests.rs} | 2 +- ui_test/src/lib.rs | 8 +++++--- ui_test/{tests/check_annotations.rs => src/tests.rs} | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) rename ui_test/{tests/comment_parser.rs => src/comments/tests.rs} (96%) rename ui_test/{tests/check_annotations.rs => src/tests.rs} (95%) diff --git a/ui_test/src/comments.rs b/ui_test/src/comments.rs index 64f999f541..e83e84b22a 100644 --- a/ui_test/src/comments.rs +++ b/ui_test/src/comments.rs @@ -2,6 +2,9 @@ use std::path::Path; use regex::Regex; +#[cfg(test)] +mod tests; + /// 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 /// get processed by their respective use sites. diff --git a/ui_test/tests/comment_parser.rs b/ui_test/src/comments/tests.rs similarity index 96% rename from ui_test/tests/comment_parser.rs rename to ui_test/src/comments/tests.rs index a9e19cbb9c..2bcaaa70a4 100644 --- a/ui_test/tests/comment_parser.rs +++ b/ui_test/src/comments/tests.rs @@ -1,6 +1,6 @@ use std::path::Path; -use ui_test::Comments; +use super::Comments; #[test] fn parse_simple_comment() { diff --git a/ui_test/src/lib.rs b/ui_test/src/lib.rs index ba1f874413..4a3014713b 100644 --- a/ui_test/src/lib.rs +++ b/ui_test/src/lib.rs @@ -12,6 +12,8 @@ use regex::Regex; pub use crate::comments::Comments; mod comments; +#[cfg(test)] +mod tests; #[derive(Debug)] pub struct Config { @@ -171,7 +173,7 @@ pub fn run_tests(config: Config) { } #[derive(Debug)] -pub enum Error { +enum Error { /// Got an invalid exit status for the given mode. ExitStatus(Mode, ExitStatus), PatternNotFound { @@ -191,7 +193,7 @@ pub enum Error { }, } -pub type Errors = Vec; +type Errors = Vec; fn run_test( path: &Path, @@ -249,7 +251,7 @@ fn run_test( (miri, errors) } -pub fn check_annotations( +fn check_annotations( unnormalized_stderr: &[u8], errors: &mut Errors, config: &Config, diff --git a/ui_test/tests/check_annotations.rs b/ui_test/src/tests.rs similarity index 95% rename from ui_test/tests/check_annotations.rs rename to ui_test/src/tests.rs index 4735fe1fa0..841f790b95 100644 --- a/ui_test/tests/check_annotations.rs +++ b/ui_test/src/tests.rs @@ -1,6 +1,6 @@ use std::path::{Path, PathBuf}; -use ui_test::{check_annotations, Comments, Config, Error, Mode, OutputConflictHandling}; +use super::{check_annotations, Comments, Config, Error, Mode, OutputConflictHandling}; fn config() -> Config { Config { From 6b18cf0e20607cda3716be299965f202898d1437 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 25 May 2022 18:25:45 +0000 Subject: [PATCH 09/13] Self-descriptive verbosity --- ui_test/src/comments/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui_test/src/comments/tests.rs b/ui_test/src/comments/tests.rs index 2bcaaa70a4..0140fdf4a9 100644 --- a/ui_test/src/comments/tests.rs +++ b/ui_test/src/comments/tests.rs @@ -12,7 +12,7 @@ fn main() { } "; let comments = Comments::parse(Path::new(""), s); - println!("{:#?}", comments); + println!("parsed comments: {:#?}", comments); assert_eq!(comments.error_matches[0].definition_line, 4); assert_eq!(comments.error_matches[0].revision, None); assert_eq!( From 10e06be15a3524e30eb1b8c896b748c0e94b74ff Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 27 May 2022 11:35:26 +0000 Subject: [PATCH 10/13] Don't export private things --- ui_test/src/comments.rs | 8 ++++---- ui_test/src/lib.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ui_test/src/comments.rs b/ui_test/src/comments.rs index e83e84b22a..e6e45de416 100644 --- a/ui_test/src/comments.rs +++ b/ui_test/src/comments.rs @@ -9,7 +9,7 @@ mod tests; /// configuration values. This struct parses them all in one go and then they /// get processed by their respective use sites. #[derive(Default, Debug)] -pub struct Comments { +pub(crate) struct Comments { /// List of revision names to execute. Can only be speicified once pub revisions: Option>, /// Don't run this test if any of these filters apply @@ -30,21 +30,21 @@ pub struct Comments { } #[derive(Debug)] -pub struct ErrorMatch { +pub(crate) struct ErrorMatch { pub matched: String, pub revision: Option, pub definition_line: usize, } impl Comments { - pub fn parse_file(path: &Path) -> Self { + pub(crate) fn parse_file(path: &Path) -> Self { let content = std::fs::read_to_string(path).unwrap(); Self::parse(path, &content) } /// Parse comments in `content`. /// `path` is only used to emit diagnostics if parsing fails. - pub fn parse(path: &Path, content: &str) -> Self { + pub(crate) fn parse(path: &Path, content: &str) -> Self { let mut this = Self::default(); let error_pattern_regex = Regex::new(r"//(\[(?P[^\]]+)\])?~[|^]*\s*(ERROR|HELP|WARN)?:?(?P.*)") diff --git a/ui_test/src/lib.rs b/ui_test/src/lib.rs index 4a3014713b..dd5a1d0624 100644 --- a/ui_test/src/lib.rs +++ b/ui_test/src/lib.rs @@ -9,7 +9,7 @@ use comments::ErrorMatch; use crossbeam::queue::SegQueue; use regex::Regex; -pub use crate::comments::Comments; +use crate::comments::Comments; mod comments; #[cfg(test)] From 1b7e278922267792a8a99067e7e9d387f45c0e3f Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 27 May 2022 11:43:14 +0000 Subject: [PATCH 11/13] Reintroduce path filters --- miri | 4 ++-- tests/compiletest.rs | 3 +++ ui_test/src/lib.rs | 13 +++++++++++++ ui_test/src/tests.rs | 1 + 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/miri b/miri index 3846eb795a..9c4eeb5275 100755 --- a/miri +++ b/miri @@ -133,9 +133,9 @@ test|test-debug|bless|bless-debug) ;; esac # Then test, and let caller control flags. - # Only in root project as `cargo-miri` has no tests. + # Only in root project and ui_test as `cargo-miri` has no tests. cargo test $CARGO_BUILD_FLAGS "$@" - cargo test --manifest-path ui_test/Cargo.toml + cargo test --manifest-path ui_test/Cargo.toml "$@" ;; run|run-debug) # Scan for "--target" to set the "MIRI_TEST_TARGET" env var so diff --git a/tests/compiletest.rs b/tests/compiletest.rs index 9ffc4744eb..4be658e86c 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -47,6 +47,8 @@ fn run_tests(mode: Mode, path: &str, target: Option) { (true, true) => panic!("cannot use MIRI_BLESS and MIRI_SKIP_UI_CHECKS at the same time"), }; + let path_filter = std::env::args().skip(1).next(); + let config = Config { args: flags, target, @@ -54,6 +56,7 @@ fn run_tests(mode: Mode, path: &str, target: Option) { stdout_filters: STDOUT.clone(), root_dir: PathBuf::from(path), mode, + path_filter, program: miri_path(), output_conflict_handling, }; diff --git a/ui_test/src/lib.rs b/ui_test/src/lib.rs index dd5a1d0624..81560db6df 100644 --- a/ui_test/src/lib.rs +++ b/ui_test/src/lib.rs @@ -30,6 +30,8 @@ pub struct Config { pub mode: Mode, pub program: PathBuf, pub output_conflict_handling: OutputConflictHandling, + /// Only run tests with this string in their path/name + pub path_filter: Option, } #[derive(Debug)] @@ -75,6 +77,17 @@ pub fn run_tests(config: Config) { if !path.extension().map(|ext| ext == "rs").unwrap_or(false) { continue; } + if let Some(path_filter) = &config.path_filter { + if !path.display().to_string().contains(path_filter) { + ignored.fetch_add(1, Ordering::Relaxed); + eprintln!( + "{} .. {}", + path.display(), + "ignored (command line filter)".yellow() + ); + continue; + } + } let comments = Comments::parse_file(&path); // Ignore file if only/ignore rules do (not) apply if ignore_file(&comments, &target) { diff --git a/ui_test/src/tests.rs b/ui_test/src/tests.rs index 841f790b95..5485e6b4f2 100644 --- a/ui_test/src/tests.rs +++ b/ui_test/src/tests.rs @@ -10,6 +10,7 @@ fn config() -> Config { stdout_filters: vec![], root_dir: PathBuf::from("."), mode: Mode::Fail, + path_filter: None, program: PathBuf::from("cake"), output_conflict_handling: OutputConflictHandling::Error, } From 740574206b1a9d494ec8cff4fc37621944e472f5 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 27 May 2022 14:24:38 +0000 Subject: [PATCH 12/13] Commit our ui test crate's cargo lockfile --- ui_test/.gitignore | 1 - ui_test/Cargo.lock | 304 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 304 insertions(+), 1 deletion(-) delete mode 100644 ui_test/.gitignore create mode 100644 ui_test/Cargo.lock diff --git a/ui_test/.gitignore b/ui_test/.gitignore deleted file mode 100644 index 03314f77b5..0000000000 --- a/ui_test/.gitignore +++ /dev/null @@ -1 +0,0 @@ -Cargo.lock diff --git a/ui_test/Cargo.lock b/ui_test/Cargo.lock new file mode 100644 index 0000000000..185af43ac0 --- /dev/null +++ b/ui_test/Cargo.lock @@ -0,0 +1,304 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "colored" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd" +dependencies = [ + "atty", + "lazy_static", + "winapi", +] + +[[package]] +name = "crossbeam" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae5588f6b3c3cb05239e90bd110f257254aecd01e4635400391aeae07497845" +dependencies = [ + "cfg-if", + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-epoch", + "crossbeam-queue", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "lazy_static", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-queue" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f25d8400f4a7a5778f0e4e52384a48cbd9b5c495d110786187fc750075277a2" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" +dependencies = [ + "cfg-if", + "lazy_static", +] + +[[package]] +name = "ctor" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f877be4f7c9f246b183111634f75baa039715e3f46ce860677d3b19a69fb229c" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "diff" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499" + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + +[[package]] +name = "output_vt100" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66" +dependencies = [ + "winapi", +] + +[[package]] +name = "pretty_assertions" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c89f989ac94207d048d92db058e4f6ec7342b0971fc58d1271ca148b799b3563" +dependencies = [ + "ansi_term", + "ctor", + "diff", + "output_vt100", +] + +[[package]] +name = "proc-macro2" +version = "1.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "semver" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cb243bdfdb5936c8dc3c45762a19d12ab4550cdc753bc247637d4ec35a040fd" + +[[package]] +name = "syn" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbaf6116ab8924f39d52792136fb74fd60a80194cf1b1c6ffa6453eef1c3f942" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "ui_test" +version = "0.1.0" +dependencies = [ + "colored", + "crossbeam", + "lazy_static", + "pretty_assertions", + "regex", + "rustc_version", +] + +[[package]] +name = "unicode-ident" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" From 3832227734d2ac87254a7cd057f4280f443563e5 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 30 May 2022 07:26:47 +0000 Subject: [PATCH 13/13] Forward CARGO_BUILD_FLAGS to ui_test test suite --- miri | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miri b/miri index 9c4eeb5275..352aed530b 100755 --- a/miri +++ b/miri @@ -135,7 +135,7 @@ test|test-debug|bless|bless-debug) # Then test, and let caller control flags. # Only in root project and ui_test as `cargo-miri` has no tests. cargo test $CARGO_BUILD_FLAGS "$@" - cargo test --manifest-path ui_test/Cargo.toml "$@" + cargo test $CARGO_BUILD_FLAGS --manifest-path ui_test/Cargo.toml "$@" ;; run|run-debug) # Scan for "--target" to set the "MIRI_TEST_TARGET" env var so