Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

be more specific about what the pattern expects #169

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ pub enum Error {
expected: i32,
},
/// A pattern was declared but had no matching error.
PatternNotFound(Spanned<Pattern>),
PatternNotFound {
/// The pattern that was not found, and the span of where that pattern was declared.
pattern: Spanned<Pattern>,
/// Can be `None` when it is expected outside the current file
expected_line: Option<NonZeroUsize>,
},
/// A ui test checking for failure does not have any failure patterns
NoPatternsFound,
/// A ui test checking for success has failure patterns
Expand Down
10 changes: 8 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,10 @@ fn check_annotations(
{
messages_from_unknown_file_or_line.remove(i);
} else {
errors.push(Error::PatternNotFound(error_pattern.clone()));
errors.push(Error::PatternNotFound {
pattern: error_pattern.clone(),
expected_line: None,
});
}
}

Expand Down Expand Up @@ -1115,7 +1118,10 @@ fn check_annotations(
}
}

errors.push(Error::PatternNotFound(pattern.clone()));
errors.push(Error::PatternNotFound {
pattern: pattern.clone(),
expected_line: Some(line),
});
}

let required_annotation_level = comments.find_one_for_revision(
Expand Down
15 changes: 11 additions & 4 deletions src/status_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,13 +416,20 @@ fn print_error(error: &Error, path: &Path) {
Error::Command { kind, status } => {
println!("{kind} failed with {status}");
}
Error::PatternNotFound(pattern) => {
Error::PatternNotFound {
pattern,
expected_line,
} => {
let line = match expected_line {
Some(line) => format!("on line {line}"),
None => format!("outside the testfile"),
};
let msg = match &**pattern {
Pattern::SubString(s) => {
format!("substring `{s}` {} in stderr output", "not found")
format!("`{s}` not found in diagnostics {line}")
}
Pattern::Regex(r) => {
format!("`/{r}/` does {} stderr output", "not match")
format!("`/{r}/` does not match diagnostics {line}",)
}
};
create_error(
Expand Down Expand Up @@ -616,7 +623,7 @@ fn gha_error(error: &Error, test_path: &str, revision: &str) {
Error::Command { kind, status } => {
github_actions::error(test_path, format!("{kind}{revision} failed with {status}"));
}
Error::PatternNotFound(pattern) => {
Error::PatternNotFound { pattern, .. } => {
github_actions::error(test_path, format!("Pattern not found{revision}"))
.line(pattern.line());
}
Expand Down
8 changes: 4 additions & 4 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn main() {
)
.unwrap();
match &errors[..] {
[Error::PatternNotFound(pattern), Error::ErrorsWithoutPattern { path, .. }]
[Error::PatternNotFound { pattern, .. }, Error::ErrorsWithoutPattern { path, .. }]
if path.as_ref().is_some_and(|p| p.line().get() == 5) && pattern.line().get() == 5 => {}
_ => panic!("{:#?}", errors),
}
Expand Down Expand Up @@ -111,7 +111,7 @@ fn main() {
)
.unwrap();
match &errors[..] {
[Error::PatternNotFound(pattern), Error::ErrorsWithoutPattern { path, .. }]
[Error::PatternNotFound { pattern, .. }, Error::ErrorsWithoutPattern { path, .. }]
if path.as_ref().is_some_and(|p| p.line().get() == 4)
&& pattern.line().get() == 5 => {}
_ => panic!("not the expected error: {:#?}", errors),
Expand Down Expand Up @@ -143,7 +143,7 @@ fn main() {
.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 => {}
[Error::PatternNotFound { pattern, .. }] if pattern.line().get() == 5 => {}
_ => panic!("not the expected error: {:#?}", errors),
}
}
Expand Down Expand Up @@ -183,7 +183,7 @@ fn main() {
)
.unwrap();
match &errors[..] {
[Error::PatternNotFound(pattern)] if pattern.line().get() == 6 => {}
[Error::PatternNotFound { pattern, .. }] if pattern.line().get() == 6 => {}
_ => panic!("{:#?}", errors),
}
}
Expand Down
10 changes: 5 additions & 5 deletions tests/integrations/basic-fail/Cargo.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tests/actual_tests/rustc_ice.rs ... FAILED
tests/actual_tests/bad_pattern.rs FAILED:
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"

error: substring `miesmätsched types` not found in stderr output
error: `miesmätsched types` not found in diagnostics on line 4
--> tests/actual_tests/bad_pattern.rs:5:17
|
5 | //~^ ERROR: miesmätsched types
Expand Down Expand Up @@ -234,7 +234,7 @@ command: "rustc" "--error-format=json" "--extern" "basic_fail=$DIR/$DIR/../../..

fail test got exit status: 101, but expected 1

error: substring `mismatched types` not found in stderr output
error: `mismatched types` not found in diagnostics on line 10
--> tests/actual_tests/rustc_ice.rs:11:17
|
11 | //~^ ERROR: mismatched types
Expand Down Expand Up @@ -539,7 +539,7 @@ full stdout:
tests/actual_tests_bless/pass_with_annotation.rs FAILED:
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"

error: substring `the cake is a lie` not found in stderr output
error: `the cake is a lie` not found in diagnostics on line 3
--> tests/actual_tests_bless/pass_with_annotation.rs:3:12
|
3 | //~ ERROR: the cake is a lie
Expand Down Expand Up @@ -605,7 +605,7 @@ full stdout:
tests/actual_tests_bless/revisions_bad.rs (revision `bar`) FAILED:
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"

error: substring ``main` function not found in crate `revisions_bad`` not found in stderr output
error: ``main` function not found in crate `revisions_bad`` not found in diagnostics outside the testfile
--> tests/actual_tests_bless/revisions_bad.rs:4:31
|
4 | //@[bar] error-in-other-file: `main` function not found in crate `revisions_bad`
Expand Down Expand Up @@ -787,7 +787,7 @@ tests/actual_tests_bless_yolo/rustfix-maybe-incorrect.rs ... ok
tests/actual_tests_bless_yolo/revisions_bad.rs (revision `bar`) FAILED:
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"

error: substring ``main` function not found in crate `revisions_bad`` not found in stderr output
error: ``main` function not found in crate `revisions_bad`` not found in diagnostics outside the testfile
--> tests/actual_tests_bless_yolo/revisions_bad.rs:4:31
|
4 | //@[bar] error-in-other-file: `main` function not found in crate `revisions_bad`
Expand Down