@@ -752,24 +752,35 @@ mod tests {
752752
753753 #[ gtest]
754754 fn always_fails_test_respects_sharding ( ) -> Result < ( ) > {
755- fn execute_test ( shard : u64 , total_shards : u64 ) -> Result < bool > {
756- let status_file = tempfile:: tempdir ( ) ?. path ( ) . join ( "shard_status_file" ) ;
757- let gtest_total_shards = format ! ( "{total_shards}" ) ;
758- let gtest_shard_index = format ! ( "{shard}" ) ;
759-
760- let success = run_external_process ( "always_fails" )
761- . env ( "GTEST_TOTAL_SHARDS" , gtest_total_shards)
762- . env ( "GTEST_SHARD_INDEX" , gtest_shard_index)
763- . env ( "GTEST_SHARD_STATUS_FILE" , & status_file)
764- . status ( ) ?
765- . success ( ) ;
766-
767- verify_that ! ( status_file. exists( ) , eq( true ) ) ?;
768- Ok ( success)
769- }
755+ // The test case should only run and fail in one shard.
756+ let results = [
757+ execute_sharded_test ( "always_fails" , 0 , 3 ) ?,
758+ execute_sharded_test ( "always_fails" , 1 , 3 ) ?,
759+ execute_sharded_test ( "always_fails" , 2 , 3 ) ?,
760+ ] ;
761+ let successes = results. iter ( ) . filter ( |b| * * b) . count ( ) ;
762+ let failures = results. iter ( ) . filter ( |b| !* * b) . count ( ) ;
770763
771- // The test case should only run in one shard.
772- let results = [ execute_test ( 0 , 3 ) ?, execute_test ( 1 , 3 ) ?, execute_test ( 2 , 3 ) ?] ;
764+ expect_that ! ( successes, eq( 2 ) ) ;
765+ expect_that ! ( failures, eq( 1 ) ) ;
766+ Ok ( ( ) )
767+ }
768+
769+ #[ gtest]
770+ fn always_panics_test_always_fails ( ) -> Result < ( ) > {
771+ let status = run_external_process ( "always_panics" ) . status ( ) ?;
772+
773+ verify_that ! ( status. success( ) , eq( false ) )
774+ }
775+
776+ #[ gtest]
777+ fn always_panics_test_respects_sharding ( ) -> Result < ( ) > {
778+ // The test case should only run and fail in one shard.
779+ let results = [
780+ execute_sharded_test ( "always_panics" , 0 , 3 ) ?,
781+ execute_sharded_test ( "always_panics" , 1 , 3 ) ?,
782+ execute_sharded_test ( "always_panics" , 2 , 3 ) ?,
783+ ] ;
773784 let successes = results. iter ( ) . filter ( |b| * * b) . count ( ) ;
774785 let failures = results. iter ( ) . filter ( |b| !* * b) . count ( ) ;
775786
@@ -778,6 +789,41 @@ mod tests {
778789 Ok ( ( ) )
779790 }
780791
792+ #[ gtest]
793+ fn expect_panic_test_always_succeeds ( ) -> Result < ( ) > {
794+ let status = run_external_process ( "expect_panic" ) . status ( ) ?;
795+
796+ verify_that ! ( status. success( ) , is_true( ) )
797+ }
798+
799+ #[ gtest]
800+ fn expect_panic_test_respects_sharding ( ) -> Result < ( ) > {
801+ let results = [
802+ execute_sharded_test ( "expect_panic" , 0 , 3 ) ?,
803+ execute_sharded_test ( "expect_panic" , 1 , 3 ) ?,
804+ execute_sharded_test ( "expect_panic" , 2 , 3 ) ?,
805+ ] ;
806+ verify_that ! ( results. iter( ) . all( |b| * b) , is_true( ) )
807+ }
808+
809+ #[ gtest]
810+ fn expect_panic_with_expected_test_always_succeeds ( ) -> Result < ( ) > {
811+ let status = run_external_process ( "expect_panic_with_expected" ) . status ( ) ?;
812+
813+ verify_that ! ( status. success( ) , is_true( ) )
814+ }
815+
816+ #[ gtest]
817+ fn expect_panic_with_expected_test_respects_sharding ( ) -> Result < ( ) > {
818+ let results = [
819+ execute_sharded_test ( "expect_panic_with_expected" , 0 , 3 ) ?,
820+ execute_sharded_test ( "expect_panic_with_expected" , 1 , 3 ) ?,
821+ execute_sharded_test ( "expect_panic_with_expected" , 2 , 3 ) ?,
822+ ] ;
823+
824+ verify_that ! ( results. iter( ) . all( |b| * b) , is_true( ) )
825+ }
826+
781827 #[ gtest]
782828 fn verify_true_when_true_returns_ok ( ) {
783829 assert ! ( verify_true!( "test" == "test" ) . is_ok( ) )
@@ -1968,4 +2014,20 @@ mod tests {
19682014 ) ;
19692015 Command :: new ( command_path)
19702016 }
2017+
2018+ fn execute_sharded_test ( process : & ' static str , shard : u64 , total_shards : u64 ) -> Result < bool > {
2019+ let status_file = tempfile:: tempdir ( ) ?. path ( ) . join ( "shard_status_file" ) ;
2020+ let gtest_total_shards = format ! ( "{total_shards}" ) ;
2021+ let gtest_shard_index = format ! ( "{shard}" ) ;
2022+
2023+ let success = run_external_process ( process)
2024+ . env ( "GTEST_TOTAL_SHARDS" , gtest_total_shards)
2025+ . env ( "GTEST_SHARD_INDEX" , gtest_shard_index)
2026+ . env ( "GTEST_SHARD_STATUS_FILE" , & status_file)
2027+ . status ( ) ?
2028+ . success ( ) ;
2029+
2030+ verify_that ! ( status_file. exists( ) , eq( true ) ) ?;
2031+ Ok ( success)
2032+ }
19712033}
0 commit comments