Skip to content

Commit 16e070b

Browse files
committed
Pass TestConfig to check_annotations
1 parent 103be80 commit 16e070b

File tree

2 files changed

+28
-141
lines changed

2 files changed

+28
-141
lines changed

src/lib.rs

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -842,20 +842,15 @@ fn check_test_result(
842842
) -> Result<(Command, Output), Errored> {
843843
let mut errors = vec![];
844844
errors.extend(mode.ok(output.status).err());
845-
let path = config.path;
846-
let comments = config.comments;
847-
let revision = config.revision;
848845
// Always remove annotation comments from stderr.
849-
let diagnostics = rustc_stderr::process(path, &output.stderr);
846+
let diagnostics = rustc_stderr::process(config.path, &output.stderr);
850847
check_test_output(&mut errors, config, &output.stdout, &diagnostics.rendered);
851848
// Check error annotations in the source against output
852849
check_annotations(
853850
diagnostics.messages,
854851
diagnostics.messages_from_unknown_file_or_line,
855-
path,
852+
config,
856853
&mut errors,
857-
revision,
858-
comments,
859854
)?;
860855
if errors.is_empty() {
861856
Ok((command, output))
@@ -879,13 +874,11 @@ fn check_test_output(errors: &mut Vec<Error>, config: &TestConfig, stdout: &[u8]
879874
fn check_annotations(
880875
mut messages: Vec<Vec<Message>>,
881876
mut messages_from_unknown_file_or_line: Vec<Message>,
882-
path: &Path,
877+
config: &TestConfig,
883878
errors: &mut Errors,
884-
revision: &str,
885-
comments: &Comments,
886879
) -> Result<(), Errored> {
887-
let error_patterns = comments
888-
.for_revision(revision)
880+
let error_patterns = config
881+
.comments()
889882
.flat_map(|r| r.error_in_other_files.iter());
890883

891884
let mut seen_error_match = None;
@@ -906,8 +899,8 @@ fn check_annotations(
906899
});
907900
}
908901
}
909-
let diagnostic_code_prefix = comments
910-
.find_one_for_revision(revision, "diagnostic_code_prefix", |r| {
902+
let diagnostic_code_prefix = config
903+
.find_one("diagnostic_code_prefix", |r| {
911904
r.diagnostic_code_prefix.clone()
912905
})?
913906
.into_inner()
@@ -918,9 +911,8 @@ fn check_annotations(
918911
// We will ensure that *all* diagnostics of level at least `lowest_annotation_level`
919912
// are matched.
920913
let mut lowest_annotation_level = Level::Error;
921-
'err: for &ErrorMatch { ref kind, line } in comments
922-
.for_revision(revision)
923-
.flat_map(|r| r.error_matches.iter())
914+
'err: for &ErrorMatch { ref kind, line } in
915+
config.comments().flat_map(|r| r.error_matches.iter())
924916
{
925917
match kind {
926918
ErrorMatchKind::Code(code) => {
@@ -978,11 +970,10 @@ fn check_annotations(
978970
});
979971
}
980972

981-
let required_annotation_level = comments.find_one_for_revision(
982-
revision,
983-
"`require_annotations_for_level` annotations",
984-
|r| r.require_annotations_for_level.clone(),
985-
)?;
973+
let required_annotation_level = config
974+
.find_one("`require_annotations_for_level` annotations", |r| {
975+
r.require_annotations_for_level.clone()
976+
})?;
986977

987978
let required_annotation_level = required_annotation_level
988979
.into_inner()
@@ -992,7 +983,7 @@ fn check_annotations(
992983
msgs
993984
};
994985

995-
let mode = comments.mode(revision)?;
986+
let mode = config.mode()?;
996987

997988
if !matches!(*mode, Mode::Yolo { .. }) {
998989
let messages_from_unknown_file_or_line = filter(messages_from_unknown_file_or_line);
@@ -1009,7 +1000,7 @@ fn check_annotations(
10091000
let line = NonZeroUsize::new(line).expect("line 0 is always empty");
10101001
errors.push(Error::ErrorsWithoutPattern {
10111002
path: Some(Spanned::new(
1012-
path.to_path_buf(),
1003+
config.path.to_path_buf(),
10131004
spanned::Span {
10141005
line_start: line,
10151006
..spanned::Span::default()

src/tests.rs

Lines changed: 13 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,7 @@ fn main() {
5050
}
5151
]
5252
];
53-
check_annotations(
54-
messages,
55-
vec![],
56-
Path::new("moobar"),
57-
&mut errors,
58-
"",
59-
config.comments,
60-
)
61-
.unwrap();
53+
check_annotations(messages, vec![], &config, &mut errors).unwrap();
6254
match &errors[..] {
6355
[Error::PatternNotFound { pattern, .. }, Error::ErrorsWithoutPattern { path, .. }]
6456
if path.as_ref().is_some_and(|p| p.line().get() == 5) && pattern.line().get() == 5 => {}
@@ -88,15 +80,7 @@ fn main() {
8880
]
8981
];
9082
let mut errors = vec![];
91-
check_annotations(
92-
messages,
93-
vec![],
94-
Path::new("moobar"),
95-
&mut errors,
96-
"",
97-
config.comments,
98-
)
99-
.unwrap();
83+
check_annotations(messages, vec![], &config, &mut errors).unwrap();
10084
match &errors[..] {
10185
[] => {}
10286
_ => panic!("{:#?}", errors),
@@ -115,15 +99,7 @@ fn main() {
11599
]
116100
];
117101
let mut errors = vec![];
118-
check_annotations(
119-
messages,
120-
vec![],
121-
Path::new("moobar"),
122-
&mut errors,
123-
"",
124-
config.comments,
125-
)
126-
.unwrap();
102+
check_annotations(messages, vec![], &config, &mut errors).unwrap();
127103
match &errors[..] {
128104
[Error::PatternNotFound { pattern, .. }, Error::ErrorsWithoutPattern { path, .. }]
129105
if path.as_ref().is_some_and(|p| p.line().get() == 4)
@@ -146,15 +122,7 @@ fn main() {
146122
]
147123
];
148124
let mut errors = vec![];
149-
check_annotations(
150-
messages,
151-
vec![],
152-
Path::new("moobar"),
153-
&mut errors,
154-
"",
155-
config.comments,
156-
)
157-
.unwrap();
125+
check_annotations(messages, vec![], &config, &mut errors).unwrap();
158126
match &errors[..] {
159127
// Note no `ErrorsWithoutPattern`, because there are no `//~NOTE` in the test file, so we ignore them
160128
[Error::PatternNotFound { pattern, .. }] if pattern.line().get() == 5 => {}
@@ -187,15 +155,7 @@ fn main() {
187155
]
188156
];
189157
let mut errors = vec![];
190-
check_annotations(
191-
messages,
192-
vec![],
193-
Path::new("moobar"),
194-
&mut errors,
195-
"",
196-
config.comments,
197-
)
198-
.unwrap();
158+
check_annotations(messages, vec![], &config, &mut errors).unwrap();
199159
match &errors[..] {
200160
[Error::PatternNotFound { pattern, .. }] if pattern.line().get() == 6 => {}
201161
_ => panic!("{:#?}", errors),
@@ -231,15 +191,7 @@ fn main() {
231191
]
232192
];
233193
let mut errors = vec![];
234-
check_annotations(
235-
messages,
236-
vec![],
237-
Path::new("moobar"),
238-
&mut errors,
239-
"",
240-
config.comments,
241-
)
242-
.unwrap();
194+
check_annotations(messages, vec![], &config, &mut errors).unwrap();
243195
match &errors[..] {
244196
[Error::ErrorsWithoutPattern { path, .. }]
245197
if path.as_ref().is_some_and(|p| p.line().get() == 5) => {}
@@ -287,15 +239,7 @@ fn main() {
287239
],
288240
];
289241
let mut errors = vec![];
290-
check_annotations(
291-
messages,
292-
vec![],
293-
Path::new("moobar"),
294-
&mut errors,
295-
"",
296-
config.comments,
297-
)
298-
.unwrap();
242+
check_annotations(messages, vec![], &config, &mut errors).unwrap();
299243
match &errors[..] {
300244
[Error::ErrorsWithoutPattern { path, msgs, .. }]
301245
if path.as_ref().is_some_and(|p| p.line().get() == 5) =>
@@ -354,15 +298,7 @@ fn main() {
354298
],
355299
];
356300
let mut errors = vec![];
357-
check_annotations(
358-
messages,
359-
vec![],
360-
Path::new("moobar"),
361-
&mut errors,
362-
"",
363-
config.comments,
364-
)
365-
.unwrap();
301+
check_annotations(messages, vec![], &config, &mut errors).unwrap();
366302
match &errors[..] {
367303
[] => {}
368304
_ => panic!("{:#?}", errors),
@@ -391,15 +327,7 @@ fn main() {
391327
}],
392328
];
393329
let mut errors = vec![];
394-
check_annotations(
395-
messages,
396-
vec![],
397-
Path::new("moobar"),
398-
&mut errors,
399-
"",
400-
config.comments,
401-
)
402-
.unwrap();
330+
check_annotations(messages, vec![], &config, &mut errors).unwrap();
403331
match &errors[..] {
404332
[] => {}
405333
_ => panic!("{:#?}", errors),
@@ -420,15 +348,7 @@ fn main() {
420348
}],
421349
];
422350
let mut errors = vec![];
423-
check_annotations(
424-
messages,
425-
vec![],
426-
Path::new("moobar"),
427-
&mut errors,
428-
"",
429-
config.comments,
430-
)
431-
.unwrap();
351+
check_annotations(messages, vec![], &config, &mut errors).unwrap();
432352
match &errors[..] {
433353
[Error::CodeNotFound { code, .. }, Error::ErrorsWithoutPattern { msgs, .. }]
434354
if **code == "E0308" && code.line().get() == 3 && msgs.len() == 1 => {}
@@ -450,15 +370,7 @@ fn main() {
450370
}],
451371
];
452372
let mut errors = vec![];
453-
check_annotations(
454-
messages,
455-
vec![],
456-
Path::new("moobar"),
457-
&mut errors,
458-
"",
459-
config.comments,
460-
)
461-
.unwrap();
373+
check_annotations(messages, vec![], &config, &mut errors).unwrap();
462374
match &errors[..] {
463375
[Error::CodeNotFound { code, .. }] if **code == "E0308" && code.line().get() == 3 => {}
464376
_ => panic!("{:#?}", errors),
@@ -490,15 +402,7 @@ fn main() {
490402
}],
491403
];
492404
let mut errors = vec![];
493-
check_annotations(
494-
messages,
495-
vec![],
496-
Path::new("moobar"),
497-
&mut errors,
498-
"",
499-
config.comments,
500-
)
501-
.unwrap();
405+
check_annotations(messages, vec![], &config, &mut errors).unwrap();
502406
match &errors[..] {
503407
[] => {}
504408
_ => panic!("{:#?}", errors),
@@ -519,15 +423,7 @@ fn main() {
519423
}],
520424
];
521425
let mut errors = vec![];
522-
check_annotations(
523-
messages,
524-
vec![],
525-
Path::new("moobar"),
526-
&mut errors,
527-
"",
528-
config.comments,
529-
)
530-
.unwrap();
426+
check_annotations(messages, vec![], &config, &mut errors).unwrap();
531427
match &errors[..] {
532428
[Error::CodeNotFound { code, .. }, Error::ErrorsWithoutPattern { msgs, .. }]
533429
if **code == "prefix::E0308" && code.line().get() == 3 && msgs.len() == 1 => {}

0 commit comments

Comments
 (0)