@@ -383,6 +383,79 @@ 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+ #[ cfg( not( windows) ) ]
426+ let exit_code = 101 ;
427+ #[ cfg( windows) ]
428+ let exit_code = winapi:: shared:: ntstatus:: STATUS_STACK_BUFFER_OVERRUN ;
429+
430+ // panic abort on custom harness
431+ p. cargo ( "test --test custom --verbose" )
432+ . with_stderr_contains ( "[RUNNING] `rustc --crate-name custom [..]-C panic=abort [..]" )
433+ . with_stderr_contains ( "[..]panicked at 'abort!', [..]" )
434+ . with_stderr_contains (
435+ "[..]process didn't exit successfully: `[..]/target/debug/deps/custom-[..]" ,
436+ )
437+ . with_status ( exit_code)
438+ . run ( ) ;
439+ p. cargo ( "bench --bench custom --verbose" )
440+ . with_stderr_contains ( "[RUNNING] `rustc --crate-name custom [..]-C panic=abort [..]" )
441+ . with_stderr_contains ( "[..]panicked at 'abort!', [..]" )
442+ . with_stderr_contains (
443+ "[..]process didn't exit successfully: `[..]/target/release/deps/custom-[..]" ,
444+ )
445+ . with_status ( exit_code)
446+ . run ( ) ;
447+
448+ // panic behaviour of libtest cannot be set as `abort` as of now.
449+ p. cargo ( "test --test libtest --verbose" )
450+ . with_stderr_does_not_contain ( "panic=abort" )
451+ . with_stdout_contains ( "running 0 tests" )
452+ . run ( ) ;
453+ p. cargo ( "bench --bench libtest --verbose" )
454+ . with_stderr_does_not_contain ( "panic=abort" )
455+ . with_stdout_contains ( "running 0 tests" )
456+ . run ( ) ;
457+ }
458+
386459#[ cargo_test]
387460fn profile_doc_deprecated ( ) {
388461 let p = project ( )
0 commit comments