-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Report line number of test when should_panic test failed #138603
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//@ compile-flags: --test | ||
//@ run-flags: --test-threads=1 --nocapture | ||
//@ run-fail | ||
//@ check-run-results | ||
//@ exec-env:RUST_BACKTRACE=0 | ||
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" | ||
//@ normalize-stdout: "TypeId\(0x[0-9a-f]+\)" -> "TypeId($$HEX)" | ||
//@ needs-threads | ||
xizheyin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//@ needs-unwind (panic) | ||
|
||
#[test] | ||
#[should_panic] | ||
fn should_panic_with_any_message() { | ||
panic!("Panic!"); | ||
} | ||
|
||
#[test] | ||
#[should_panic = "message"] | ||
fn should_panic_with_message() { | ||
panic!("message"); | ||
} | ||
|
||
#[test] | ||
#[should_panic] | ||
fn should_panic_with_any_message_does_not_panic() { | ||
// DON'T PANIC | ||
} | ||
|
||
#[test] | ||
#[should_panic = "message"] | ||
fn should_panic_with_message_does_not_panic() { | ||
// DON'T PANIC | ||
} | ||
|
||
#[test] | ||
#[should_panic = "message"] | ||
fn should_panic_with_substring_panics_with_incorrect_string() { | ||
panic!("ZOMGWTFBBQ"); | ||
} | ||
|
||
#[test] | ||
#[should_panic = "message"] | ||
#[expect(non_fmt_panics)] | ||
fn should_panic_with_substring_panics_with_non_string_value() { | ||
panic!(123); | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/ui/test-attrs/test-should-panic-failed-show-span.run.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
thread 'should_panic_with_any_message' panicked at $DIR/test-should-panic-failed-show-span.rs:14:5: | ||
Panic! | ||
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace | ||
|
||
thread 'should_panic_with_message' panicked at $DIR/test-should-panic-failed-show-span.rs:20:5: | ||
message | ||
|
||
thread 'should_panic_with_substring_panics_with_incorrect_string' panicked at $DIR/test-should-panic-failed-show-span.rs:38:5: | ||
ZOMGWTFBBQ | ||
|
||
thread 'should_panic_with_substring_panics_with_non_string_value' panicked at $DIR/test-should-panic-failed-show-span.rs:45:5: | ||
Box<dyn Any> |
32 changes: 32 additions & 0 deletions
32
tests/ui/test-attrs/test-should-panic-failed-show-span.run.stdout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
running 6 tests | ||
test should_panic_with_any_message - should panic ... ok | ||
test should_panic_with_any_message_does_not_panic - should panic ... FAILED | ||
test should_panic_with_message - should panic ... ok | ||
test should_panic_with_message_does_not_panic - should panic ... FAILED | ||
test should_panic_with_substring_panics_with_incorrect_string - should panic ... FAILED | ||
test should_panic_with_substring_panics_with_non_string_value - should panic ... FAILED | ||
|
||
failures: | ||
|
||
---- should_panic_with_any_message_does_not_panic stdout ---- | ||
note: test did not panic as expected at $DIR/test-should-panic-failed-show-span.rs:25:4 | ||
---- should_panic_with_message_does_not_panic stdout ---- | ||
note: test did not panic as expected at $DIR/test-should-panic-failed-show-span.rs:31:4 | ||
---- should_panic_with_substring_panics_with_incorrect_string stdout ---- | ||
note: panic did not contain expected string | ||
panic message: `"ZOMGWTFBBQ"`, | ||
expected substring: `"message"` | ||
---- should_panic_with_substring_panics_with_non_string_value stdout ---- | ||
note: expected panic with string value, | ||
found non-string value: `TypeId($HEX)` | ||
expected substring: `"message"` | ||
|
||
failures: | ||
should_panic_with_any_message_does_not_panic | ||
should_panic_with_message_does_not_panic | ||
should_panic_with_substring_panics_with_incorrect_string | ||
should_panic_with_substring_panics_with_non_string_value | ||
|
||
test result: FAILED. 2 passed; 4 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.