Skip to content

Commit

Permalink
Pass TestConfig to check_annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Mar 28, 2024
1 parent 103be80 commit 16e070b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 141 deletions.
39 changes: 15 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -879,13 +874,11 @@ fn check_test_output(errors: &mut Vec<Error>, config: &TestConfig, stdout: &[u8]
fn check_annotations(
mut messages: Vec<Vec<Message>>,
mut messages_from_unknown_file_or_line: Vec<Message>,
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;
Expand All @@ -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()
Expand All @@ -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) => {
Expand Down Expand Up @@ -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()
Expand All @@ -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);
Expand All @@ -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()
Expand Down
130 changes: 13 additions & 117 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {}
Expand Down Expand Up @@ -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),
Expand All @@ -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)
Expand All @@ -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 => {}
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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) => {}
Expand Down Expand Up @@ -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) =>
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -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 => {}
Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -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 => {}
Expand Down

0 comments on commit 16e070b

Please sign in to comment.