From 16e070bbc90a6beec6b89c04ffc7689d836a0073 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 28 Mar 2024 09:44:44 +0000 Subject: [PATCH] Pass `TestConfig` to `check_annotations` --- src/lib.rs | 39 ++++++---------- src/tests.rs | 130 ++++++--------------------------------------------- 2 files changed, 28 insertions(+), 141 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fbdeca67..df76b2a1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -842,20 +842,15 @@ fn check_test_result( ) -> Result<(Command, Output), Errored> { let mut errors = vec![]; errors.extend(mode.ok(output.status).err()); - let path = config.path; - let comments = config.comments; - let revision = config.revision; // Always remove annotation comments from stderr. - let diagnostics = rustc_stderr::process(path, &output.stderr); + let diagnostics = rustc_stderr::process(config.path, &output.stderr); check_test_output(&mut errors, config, &output.stdout, &diagnostics.rendered); // Check error annotations in the source against output check_annotations( diagnostics.messages, diagnostics.messages_from_unknown_file_or_line, - path, + config, &mut errors, - revision, - comments, )?; if errors.is_empty() { Ok((command, output)) @@ -879,13 +874,11 @@ fn check_test_output(errors: &mut Vec, config: &TestConfig, stdout: &[u8] fn check_annotations( mut messages: Vec>, mut messages_from_unknown_file_or_line: Vec, - path: &Path, + config: &TestConfig, errors: &mut Errors, - revision: &str, - comments: &Comments, ) -> Result<(), Errored> { - let error_patterns = comments - .for_revision(revision) + let error_patterns = config + .comments() .flat_map(|r| r.error_in_other_files.iter()); let mut seen_error_match = None; @@ -906,8 +899,8 @@ fn check_annotations( }); } } - let diagnostic_code_prefix = comments - .find_one_for_revision(revision, "diagnostic_code_prefix", |r| { + let diagnostic_code_prefix = config + .find_one("diagnostic_code_prefix", |r| { r.diagnostic_code_prefix.clone() })? .into_inner() @@ -918,9 +911,8 @@ fn check_annotations( // We will ensure that *all* diagnostics of level at least `lowest_annotation_level` // are matched. let mut lowest_annotation_level = Level::Error; - 'err: for &ErrorMatch { ref kind, line } in comments - .for_revision(revision) - .flat_map(|r| r.error_matches.iter()) + 'err: for &ErrorMatch { ref kind, line } in + config.comments().flat_map(|r| r.error_matches.iter()) { match kind { ErrorMatchKind::Code(code) => { @@ -978,11 +970,10 @@ fn check_annotations( }); } - let required_annotation_level = comments.find_one_for_revision( - revision, - "`require_annotations_for_level` annotations", - |r| r.require_annotations_for_level.clone(), - )?; + let required_annotation_level = config + .find_one("`require_annotations_for_level` annotations", |r| { + r.require_annotations_for_level.clone() + })?; let required_annotation_level = required_annotation_level .into_inner() @@ -992,7 +983,7 @@ fn check_annotations( msgs }; - let mode = comments.mode(revision)?; + let mode = config.mode()?; if !matches!(*mode, Mode::Yolo { .. }) { let messages_from_unknown_file_or_line = filter(messages_from_unknown_file_or_line); @@ -1009,7 +1000,7 @@ fn check_annotations( let line = NonZeroUsize::new(line).expect("line 0 is always empty"); errors.push(Error::ErrorsWithoutPattern { path: Some(Spanned::new( - path.to_path_buf(), + config.path.to_path_buf(), spanned::Span { line_start: line, ..spanned::Span::default() diff --git a/src/tests.rs b/src/tests.rs index 3a69f846..9ea7435d 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -50,15 +50,7 @@ fn main() { } ] ]; - check_annotations( - messages, - vec![], - Path::new("moobar"), - &mut errors, - "", - config.comments, - ) - .unwrap(); + check_annotations(messages, vec![], &config, &mut errors).unwrap(); match &errors[..] { [Error::PatternNotFound { pattern, .. }, Error::ErrorsWithoutPattern { path, .. }] if path.as_ref().is_some_and(|p| p.line().get() == 5) && pattern.line().get() == 5 => {} @@ -88,15 +80,7 @@ fn main() { ] ]; let mut errors = vec![]; - check_annotations( - messages, - vec![], - Path::new("moobar"), - &mut errors, - "", - config.comments, - ) - .unwrap(); + check_annotations(messages, vec![], &config, &mut errors).unwrap(); match &errors[..] { [] => {} _ => panic!("{:#?}", errors), @@ -115,15 +99,7 @@ fn main() { ] ]; let mut errors = vec![]; - check_annotations( - messages, - vec![], - Path::new("moobar"), - &mut errors, - "", - config.comments, - ) - .unwrap(); + check_annotations(messages, vec![], &config, &mut errors).unwrap(); match &errors[..] { [Error::PatternNotFound { pattern, .. }, Error::ErrorsWithoutPattern { path, .. }] if path.as_ref().is_some_and(|p| p.line().get() == 4) @@ -146,15 +122,7 @@ fn main() { ] ]; let mut errors = vec![]; - check_annotations( - messages, - vec![], - Path::new("moobar"), - &mut errors, - "", - config.comments, - ) - .unwrap(); + check_annotations(messages, vec![], &config, &mut errors).unwrap(); match &errors[..] { // Note no `ErrorsWithoutPattern`, because there are no `//~NOTE` in the test file, so we ignore them [Error::PatternNotFound { pattern, .. }] if pattern.line().get() == 5 => {} @@ -187,15 +155,7 @@ fn main() { ] ]; let mut errors = vec![]; - check_annotations( - messages, - vec![], - Path::new("moobar"), - &mut errors, - "", - config.comments, - ) - .unwrap(); + check_annotations(messages, vec![], &config, &mut errors).unwrap(); match &errors[..] { [Error::PatternNotFound { pattern, .. }] if pattern.line().get() == 6 => {} _ => panic!("{:#?}", errors), @@ -231,15 +191,7 @@ fn main() { ] ]; let mut errors = vec![]; - check_annotations( - messages, - vec![], - Path::new("moobar"), - &mut errors, - "", - config.comments, - ) - .unwrap(); + check_annotations(messages, vec![], &config, &mut errors).unwrap(); match &errors[..] { [Error::ErrorsWithoutPattern { path, .. }] if path.as_ref().is_some_and(|p| p.line().get() == 5) => {} @@ -287,15 +239,7 @@ fn main() { ], ]; let mut errors = vec![]; - check_annotations( - messages, - vec![], - Path::new("moobar"), - &mut errors, - "", - config.comments, - ) - .unwrap(); + check_annotations(messages, vec![], &config, &mut errors).unwrap(); match &errors[..] { [Error::ErrorsWithoutPattern { path, msgs, .. }] if path.as_ref().is_some_and(|p| p.line().get() == 5) => @@ -354,15 +298,7 @@ fn main() { ], ]; let mut errors = vec![]; - check_annotations( - messages, - vec![], - Path::new("moobar"), - &mut errors, - "", - config.comments, - ) - .unwrap(); + check_annotations(messages, vec![], &config, &mut errors).unwrap(); match &errors[..] { [] => {} _ => panic!("{:#?}", errors), @@ -391,15 +327,7 @@ fn main() { }], ]; let mut errors = vec![]; - check_annotations( - messages, - vec![], - Path::new("moobar"), - &mut errors, - "", - config.comments, - ) - .unwrap(); + check_annotations(messages, vec![], &config, &mut errors).unwrap(); match &errors[..] { [] => {} _ => panic!("{:#?}", errors), @@ -420,15 +348,7 @@ fn main() { }], ]; let mut errors = vec![]; - check_annotations( - messages, - vec![], - Path::new("moobar"), - &mut errors, - "", - config.comments, - ) - .unwrap(); + check_annotations(messages, vec![], &config, &mut errors).unwrap(); match &errors[..] { [Error::CodeNotFound { code, .. }, Error::ErrorsWithoutPattern { msgs, .. }] if **code == "E0308" && code.line().get() == 3 && msgs.len() == 1 => {} @@ -450,15 +370,7 @@ fn main() { }], ]; let mut errors = vec![]; - check_annotations( - messages, - vec![], - Path::new("moobar"), - &mut errors, - "", - config.comments, - ) - .unwrap(); + check_annotations(messages, vec![], &config, &mut errors).unwrap(); match &errors[..] { [Error::CodeNotFound { code, .. }] if **code == "E0308" && code.line().get() == 3 => {} _ => panic!("{:#?}", errors), @@ -490,15 +402,7 @@ fn main() { }], ]; let mut errors = vec![]; - check_annotations( - messages, - vec![], - Path::new("moobar"), - &mut errors, - "", - config.comments, - ) - .unwrap(); + check_annotations(messages, vec![], &config, &mut errors).unwrap(); match &errors[..] { [] => {} _ => panic!("{:#?}", errors), @@ -519,15 +423,7 @@ fn main() { }], ]; let mut errors = vec![]; - check_annotations( - messages, - vec![], - Path::new("moobar"), - &mut errors, - "", - config.comments, - ) - .unwrap(); + check_annotations(messages, vec![], &config, &mut errors).unwrap(); match &errors[..] { [Error::CodeNotFound { code, .. }, Error::ErrorsWithoutPattern { msgs, .. }] if **code == "prefix::E0308" && code.line().get() == 3 && msgs.len() == 1 => {}