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

feat(profile): panic behavior can be specified for custom harness #11272

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
test(profile): show panic=abort doesnt work for custom harness
  • Loading branch information
weihanglo committed May 7, 2024
commit d013ac9a25672f1eb89c8a9fb07f08563f7b08d9
61 changes: 61 additions & 0 deletions tests/testsuite/profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,67 @@ fn profile_panic_test_bench() {
.run();
}

#[cargo_test]
fn profile_panic_test_with_custom_harness() {
// Custom harness can have `-C panic="…"` passed in.
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
[[test]]
name = "custom"
harness = false
[[test]]
name = "libtest"
[[bench]]
name = "custom"
harness = false
[[bench]]
name = "libtest"
[profile.test]
panic = "abort"
[profile.bench]
panic = "abort"
"#,
)
.file("src/lib.rs", "")
.file("tests/custom.rs", r#"fn main() { panic!("abort!"); }"#)
.file("tests/libtest.rs", "")
.file("benches/custom.rs", r#"fn main() { panic!("abort!"); }"#)
.file("benches/libtest.rs", "")
.build();

// panic abort on custom harness
p.cargo("test --test custom --verbose")
.with_stderr_does_not_contain("[..]panic=abort[..]")
.with_stderr_contains("[..]thread '[..]' panicked at [..]")
.with_stderr_does_not_contain(
"[..]process didn't exit successfully: `[..]/target/debug/deps/custom-[..]",
)
.with_status(101)
.run();
p.cargo("bench --bench custom --verbose")
.with_stderr_does_not_contain("[..]panic=abort[..]")
.with_stderr_contains("[..]thread '[..]' panicked at [..]")
.with_stderr_does_not_contain(
"[..]process didn't exit successfully: `[..]/target/release/deps/custom-[..]",
)
.with_status(101)
.run();

// panic behaviour of libtest cannot be set as `abort` as of now.
p.cargo("test --test libtest --verbose")
.with_stderr_does_not_contain("panic=abort")
.with_stdout_contains("running 0 tests")
.run();
p.cargo("bench --bench libtest --verbose")
.with_stderr_does_not_contain("panic=abort")
.with_stdout_contains("running 0 tests")
.run();
}

#[cargo_test]
fn profile_doc_deprecated() {
let p = project()
Expand Down