Skip to content

Commit e6a7095

Browse files
committed
print the proper line of where we expected the pattern
1 parent 7e4648e commit e6a7095

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-19
lines changed

src/error.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ pub enum Error {
1919
expected: i32,
2020
},
2121
/// A pattern was declared but had no matching error.
22-
PatternNotFound(Spanned<Pattern>),
22+
PatternNotFound {
23+
/// The pattern that was not found, and the span of where that pattern was declared.
24+
pattern: Spanned<Pattern>,
25+
/// Can be `None` when it is expected outside the current file
26+
expected_line: Option<NonZeroUsize>,
27+
},
2328
/// A ui test checking for failure does not have any failure patterns
2429
NoPatternsFound,
2530
/// A ui test checking for success has failure patterns

src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,10 @@ fn check_annotations(
10811081
{
10821082
messages_from_unknown_file_or_line.remove(i);
10831083
} else {
1084-
errors.push(Error::PatternNotFound(error_pattern.clone()));
1084+
errors.push(Error::PatternNotFound {
1085+
pattern: error_pattern.clone(),
1086+
expected_line: None,
1087+
});
10851088
}
10861089
}
10871090

@@ -1115,7 +1118,10 @@ fn check_annotations(
11151118
}
11161119
}
11171120

1118-
errors.push(Error::PatternNotFound(pattern.clone()));
1121+
errors.push(Error::PatternNotFound {
1122+
pattern: pattern.clone(),
1123+
expected_line: Some(line),
1124+
});
11191125
}
11201126

11211127
let required_annotation_level = comments.find_one_for_revision(

src/status_emitter.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -416,16 +416,20 @@ fn print_error(error: &Error, path: &Path) {
416416
Error::Command { kind, status } => {
417417
println!("{kind} failed with {status}");
418418
}
419-
Error::PatternNotFound(pattern) => {
419+
Error::PatternNotFound {
420+
pattern,
421+
expected_line,
422+
} => {
423+
let line = match expected_line {
424+
Some(line) => format!("on line {line}"),
425+
None => format!("outside the testfile"),
426+
};
420427
let msg = match &**pattern {
421428
Pattern::SubString(s) => {
422-
format!("`{s}` not found in diagnostics for line {}", pattern.line())
429+
format!("`{s}` not found in diagnostics {line}")
423430
}
424431
Pattern::Regex(r) => {
425-
format!(
426-
"`/{r}/` does not match diagnostics for line {}",
427-
pattern.line()
428-
)
432+
format!("`/{r}/` does not match diagnostics {line}",)
429433
}
430434
};
431435
create_error(
@@ -619,7 +623,7 @@ fn gha_error(error: &Error, test_path: &str, revision: &str) {
619623
Error::Command { kind, status } => {
620624
github_actions::error(test_path, format!("{kind}{revision} failed with {status}"));
621625
}
622-
Error::PatternNotFound(pattern) => {
626+
Error::PatternNotFound { pattern, .. } => {
623627
github_actions::error(test_path, format!("Pattern not found{revision}"))
624628
.line(pattern.line());
625629
}

src/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn main() {
4646
)
4747
.unwrap();
4848
match &errors[..] {
49-
[Error::PatternNotFound(pattern), Error::ErrorsWithoutPattern { path, .. }]
49+
[Error::PatternNotFound { pattern, .. }, Error::ErrorsWithoutPattern { path, .. }]
5050
if path.as_ref().is_some_and(|p| p.line().get() == 5) && pattern.line().get() == 5 => {}
5151
_ => panic!("{:#?}", errors),
5252
}
@@ -111,7 +111,7 @@ fn main() {
111111
)
112112
.unwrap();
113113
match &errors[..] {
114-
[Error::PatternNotFound(pattern), Error::ErrorsWithoutPattern { path, .. }]
114+
[Error::PatternNotFound { pattern, .. }, Error::ErrorsWithoutPattern { path, .. }]
115115
if path.as_ref().is_some_and(|p| p.line().get() == 4)
116116
&& pattern.line().get() == 5 => {}
117117
_ => panic!("not the expected error: {:#?}", errors),
@@ -143,7 +143,7 @@ fn main() {
143143
.unwrap();
144144
match &errors[..] {
145145
// Note no `ErrorsWithoutPattern`, because there are no `//~NOTE` in the test file, so we ignore them
146-
[Error::PatternNotFound(pattern)] if pattern.line().get() == 5 => {}
146+
[Error::PatternNotFound { pattern, .. }] if pattern.line().get() == 5 => {}
147147
_ => panic!("not the expected error: {:#?}", errors),
148148
}
149149
}
@@ -183,7 +183,7 @@ fn main() {
183183
)
184184
.unwrap();
185185
match &errors[..] {
186-
[Error::PatternNotFound(pattern)] if pattern.line().get() == 6 => {}
186+
[Error::PatternNotFound { pattern, .. }] if pattern.line().get() == 6 => {}
187187
_ => panic!("{:#?}", errors),
188188
}
189189
}

tests/integrations/basic-fail/Cargo.stdout

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ tests/actual_tests/rustc_ice.rs ... FAILED
1717
tests/actual_tests/bad_pattern.rs FAILED:
1818
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/bad_pattern.rs" "--edition" "2021"
1919

20-
error: `miesmätsched types` not found in diagnostics for line 5
20+
error: `miesmätsched types` not found in diagnostics on line 4
2121
--> tests/actual_tests/bad_pattern.rs:5:17
2222
|
2323
5 | //~^ ERROR: miesmätsched types
@@ -234,7 +234,7 @@ command: "rustc" "--error-format=json" "--extern" "basic_fail=$DIR/$DIR/../../..
234234

235235
fail test got exit status: 101, but expected 1
236236

237-
error: `mismatched types` not found in diagnostics for line 11
237+
error: `mismatched types` not found in diagnostics on line 10
238238
--> tests/actual_tests/rustc_ice.rs:11:17
239239
|
240240
11 | //~^ ERROR: mismatched types
@@ -539,7 +539,7 @@ full stdout:
539539
tests/actual_tests_bless/pass_with_annotation.rs FAILED:
540540
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/pass_with_annotation.rs" "--edition" "2021"
541541

542-
error: `the cake is a lie` not found in diagnostics for line 3
542+
error: `the cake is a lie` not found in diagnostics on line 3
543543
--> tests/actual_tests_bless/pass_with_annotation.rs:3:12
544544
|
545545
3 | //~ ERROR: the cake is a lie
@@ -605,7 +605,7 @@ full stdout:
605605
tests/actual_tests_bless/revisions_bad.rs (revision `bar`) FAILED:
606606
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/revisions_bad.rs" "--cfg=bar" "--edition" "2021"
607607

608-
error: ``main` function not found in crate `revisions_bad`` not found in diagnostics for line 4
608+
error: ``main` function not found in crate `revisions_bad`` not found in diagnostics outside the testfile
609609
--> tests/actual_tests_bless/revisions_bad.rs:4:31
610610
|
611611
4 | //@[bar] error-in-other-file: `main` function not found in crate `revisions_bad`
@@ -787,7 +787,7 @@ tests/actual_tests_bless_yolo/rustfix-maybe-incorrect.rs ... ok
787787
tests/actual_tests_bless_yolo/revisions_bad.rs (revision `bar`) FAILED:
788788
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_yolo/revisions_bad.rs" "--cfg=bar" "--edition" "2021"
789789

790-
error: ``main` function not found in crate `revisions_bad`` not found in diagnostics for line 4
790+
error: ``main` function not found in crate `revisions_bad`` not found in diagnostics outside the testfile
791791
--> tests/actual_tests_bless_yolo/revisions_bad.rs:4:31
792792
|
793793
4 | //@[bar] error-in-other-file: `main` function not found in crate `revisions_bad`

0 commit comments

Comments
 (0)