Skip to content

Commit aa60061

Browse files
authored
Merge pull request #90 from oli-obk/unknown_revision
Check for unknown revisions.
2 parents 5f391d3 + 571e0a7 commit aa60061

File tree

5 files changed

+70
-4
lines changed

5 files changed

+70
-4
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ fn run_rustfix(
696696
revisioned: std::iter::once((
697697
vec![],
698698
Revisioned {
699+
line: 0,
699700
ignore: vec![],
700701
only: vec![],
701702
stderr_per_bitwidth: false,

src/parser.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ mod tests;
1818
/// get processed by their respective use sites.
1919
#[derive(Default, Debug)]
2020
pub(crate) struct Comments {
21-
/// List of revision names to execute. Can only be speicified once
21+
/// List of revision names to execute. Can only be specified once
2222
pub revisions: Option<Vec<String>>,
2323
/// Comments that are only available under specific revisions.
2424
/// The defaults are in key `vec![]`
@@ -78,6 +78,9 @@ impl Comments {
7878
#[derive(Default, Debug)]
7979
/// Comments that can be filtered for specific revisions.
8080
pub(crate) struct Revisioned {
81+
/// The line in which this revisioned item was first added.
82+
/// Used for reporting errors on unknown revisions.
83+
pub line: usize,
8184
/// Don't run this test if any of these filters apply
8285
pub ignore: Vec<Condition>,
8386
/// Only run this test if all of these filters apply
@@ -210,6 +213,27 @@ impl Comments {
210213
}),
211214
}
212215
}
216+
if let Some(revisions) = &parser.comments.revisions {
217+
for (key, revisioned) in &parser.comments.revisioned {
218+
for rev in key {
219+
if !revisions.contains(rev) {
220+
parser.errors.push(Error::InvalidComment {
221+
msg: format!("the revision `{rev}` is not known"),
222+
line: revisioned.line,
223+
})
224+
}
225+
}
226+
}
227+
} else {
228+
for (key, revisioned) in &parser.comments.revisioned {
229+
if !key.is_empty() {
230+
parser.errors.push(Error::InvalidComment {
231+
msg: "there are no revisions in this test".into(),
232+
line: revisioned.line,
233+
})
234+
}
235+
}
236+
}
213237
if parser.errors.is_empty() {
214238
Ok(parser.comments)
215239
} else {
@@ -332,10 +356,17 @@ impl CommentParser<Comments> {
332356
revisions: Vec<String>,
333357
f: impl FnOnce(&mut CommentParser<&mut Revisioned>),
334358
) {
359+
let line = self.line;
335360
let mut this = CommentParser {
336361
errors: std::mem::take(&mut self.errors),
337-
line: self.line,
338-
comments: self.revisioned.entry(revisions).or_default(),
362+
line,
363+
comments: self
364+
.revisioned
365+
.entry(revisions)
366+
.or_insert_with(|| Revisioned {
367+
line,
368+
..Default::default()
369+
}),
339370
};
340371
f(&mut this);
341372
self.errors = this.errors;

tests/integrations/basic-fail/Cargo.stderr

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ tests/actual_tests_bless/revisions_multiple_per_annotation.rs (foo) ... ok
207207
tests/actual_tests_bless/revisions_multiple_per_annotation.rs (bar) ... ok
208208
tests/actual_tests_bless/revisions_same_everywhere.rs (foo) ... ok
209209
tests/actual_tests_bless/revisions_same_everywhere.rs (bar) ... ok
210+
tests/actual_tests_bless/unknown_revision.rs ... FAILED
211+
tests/actual_tests_bless/unknown_revision2.rs ... FAILED
210212

211213
tests/actual_tests_bless/aux_proc_macro_misuse.rs FAILED:
212214
command: "rustc" "--error-format=json" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TMP/$TRIPLE/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TMP/$TRIPLE/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/$DIR/../../../target/$TMP/$TRIPLE/debug" "-L" "$DIR/$DIR/../../../target/$TMP/$TRIPLE/debug" "--out-dir" "$TMP "tests/actual_tests_bless/auxiliary/the_proc_macro.rs" "--edition" "2021" "--crate-type" "lib" "--emit=link"
@@ -464,6 +466,26 @@ error: aborting due to previous error
464466
For more information about this error, try `rustc --explain E0601`.
465467

466468

469+
470+
tests/actual_tests_bless/unknown_revision.rs FAILED:
471+
command: "parse comments"
472+
473+
Could not parse comment in tests/actual_tests_bless/unknown_revision.rs:3 because
474+
there are no revisions in this test
475+
476+
full stderr:
477+
478+
479+
480+
tests/actual_tests_bless/unknown_revision2.rs FAILED:
481+
command: "parse comments"
482+
483+
Could not parse comment in tests/actual_tests_bless/unknown_revision2.rs:5 because
484+
the revision `cake` is not known
485+
486+
full stderr:
487+
488+
467489
FAILURES:
468490
tests/actual_tests_bless/aux_proc_macro_misuse.rs
469491
tests/actual_tests_bless/aux_proc_macro_no_main.rs
@@ -481,8 +503,10 @@ FAILURES:
481503
tests/actual_tests_bless/revisioned_executable_panic.rs (revision run)
482504
tests/actual_tests_bless/revisioned_executable_panic.rs (revision panic)
483505
tests/actual_tests_bless/revisions_bad.rs (revision bar)
506+
tests/actual_tests_bless/unknown_revision.rs
507+
tests/actual_tests_bless/unknown_revision2.rs
484508

485-
test result: FAIL. 16 tests failed, 12 tests passed, 3 ignored, 0 filtered out
509+
test result: FAIL. 18 tests failed, 12 tests passed, 3 ignored, 0 filtered out
486510
Building test dependencies...
487511
tests/actual_tests_bless_yolo/foomp-rustfix-fail.rs ... ok
488512
tests/actual_tests_bless_yolo/revisions_bad.rs (foo) ... ok
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
assert_eq!(5, 6);
3+
//~[cake, lie] ERROR: kawoom
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//@ revisions: cheese lie
2+
3+
fn main() {
4+
assert_eq!(5, 6);
5+
//~[cake, lie] ERROR: kawoom
6+
}

0 commit comments

Comments
 (0)