Skip to content

Commit

Permalink
test(profile): set panic behaviour with custom harness
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Oct 22, 2022
1 parent 1e065f2 commit 7c8c55e
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions tests/testsuite/profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,74 @@ fn profile_panic_test_bench() {
.run();
}

/// Custom harness can have `-C panic="…"` passed in.
#[cargo_test]
fn profile_panic_test_with_custom_harness() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
[[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_contains("[RUNNING] `rustc --crate-name custom [..]-C panic=abort [..]")
.with_stderr_contains("[..]panicked at 'abort!', [..]")
.with_stderr_contains(
"[..]process didn't exit successfully[..]target/debug/deps/custom-[..][EXE]",
)
.with_status(101)
.run();
p.cargo("bench --bench custom --verbose")
.with_stderr_contains("[RUNNING] `rustc --crate-name custom [..]-C panic=abort [..]")
.with_stderr_contains("[..]panicked at 'abort!', [..]")
.with_stderr_contains(
"[..]process didn't exit successfully[..]target/debug/deps/custom-[..][EXE]",
)
.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

0 comments on commit 7c8c55e

Please sign in to comment.