Skip to content

Commit 646975d

Browse files
committed
test(profile): set panic behaviour with custom harness
1 parent 1e065f2 commit 646975d

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

tests/testsuite/profiles.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,74 @@ fn profile_panic_test_bench() {
383383
.run();
384384
}
385385

386+
/// Custom harness can have `-C panic="…"` passed in.
387+
#[cargo_test]
388+
fn profile_panic_test_with_custom_harness() {
389+
let p = project()
390+
.file(
391+
"Cargo.toml",
392+
r#"
393+
[package]
394+
name = "foo"
395+
version = "0.0.1"
396+
397+
[[test]]
398+
name = "custom"
399+
harness = false
400+
401+
[[test]]
402+
name = "libtest"
403+
404+
[[bench]]
405+
name = "custom"
406+
harness = false
407+
408+
[[bench]]
409+
name = "libtest"
410+
411+
[profile.test]
412+
panic = "abort"
413+
414+
[profile.bench]
415+
panic = "abort"
416+
"#,
417+
)
418+
.file("src/lib.rs", "")
419+
.file("tests/custom.rs", r#"fn main() { panic!("abort!"); }"#)
420+
.file("tests/libtest.rs", "")
421+
.file("benches/custom.rs", r#"fn main() { panic!("abort!"); }"#)
422+
.file("benches/libtest.rs", "")
423+
.build();
424+
425+
// panic abort on custom harness
426+
p.cargo("test --test custom --verbose")
427+
.with_stderr_contains("[RUNNING] `rustc --crate-name custom [..]-C panic=abort [..]")
428+
.with_stderr_contains("[..]panicked at 'abort!', [..]")
429+
.with_stderr_contains(
430+
"[..]process didn't exit successfully[..]target/debug/deps/custom-[..][EXE]",
431+
)
432+
.with_status(101)
433+
.run();
434+
p.cargo("bench --bench custom --verbose")
435+
.with_stderr_contains("[RUNNING] `rustc --crate-name custom [..]-C panic=abort [..]")
436+
.with_stderr_contains("[..]panicked at 'abort!', [..]")
437+
.with_stderr_contains(
438+
"[..]process didn't exit successfully[..]target/release/deps/custom-[..][EXE]",
439+
)
440+
.with_status(101)
441+
.run();
442+
443+
// panic behaviour of libtest cannot be set as `abort` as of now.
444+
p.cargo("test --test libtest --verbose")
445+
.with_stderr_does_not_contain("panic=abort")
446+
.with_stdout_contains("running 0 tests")
447+
.run();
448+
p.cargo("bench --bench libtest --verbose")
449+
.with_stderr_does_not_contain("panic=abort")
450+
.with_stdout_contains("running 0 tests")
451+
.run();
452+
}
453+
386454
#[cargo_test]
387455
fn profile_doc_deprecated() {
388456
let p = project()

0 commit comments

Comments
 (0)