@@ -13,6 +13,7 @@ use crate::{
13
13
DynTestName ,
14
14
MetricMap ,
15
15
RunIgnored ,
16
+ RunIntegration ,
16
17
RunStrategy ,
17
18
ShouldPanic ,
18
19
StaticTestName ,
@@ -39,6 +40,7 @@ impl TestOpts {
39
40
force_run_in_process : false ,
40
41
exclude_should_panic : false ,
41
42
run_ignored : RunIgnored :: No ,
43
+ run_integration : RunIntegration :: Yes ,
42
44
run_tests : false ,
43
45
bench_benchmarks : false ,
44
46
logfile : None ,
@@ -832,3 +834,146 @@ fn test_dyn_bench_returning_err_fails_when_run_as_test() {
832
834
let result = rx. recv ( ) . unwrap ( ) . result ;
833
835
assert_eq ! ( result, TrFailed ) ;
834
836
}
837
+
838
+ #[ test]
839
+ pub fn do_not_run_integration_test_if_excluded ( ) {
840
+ fn f ( ) -> Result < ( ) , String > {
841
+ panic ! ( ) ;
842
+ }
843
+ let desc = TestDescAndFn {
844
+ desc : TestDesc {
845
+ name : StaticTestName ( "whatever" ) ,
846
+ ignore : true ,
847
+ ignore_message : None ,
848
+ should_panic : ShouldPanic :: No ,
849
+ compile_fail : false ,
850
+ no_run : false ,
851
+ test_type : TestType :: IntegrationTest ,
852
+ } ,
853
+ testfn : DynTestFn ( Box :: new ( f) ) ,
854
+ } ;
855
+ let ( tx, rx) = channel ( ) ;
856
+ run_test ( & TestOpts :: new ( ) , false , TestId ( 0 ) , desc, RunStrategy :: InProcess , tx) ;
857
+ let result = rx. recv ( ) . unwrap ( ) . result ;
858
+ assert_ne ! ( result, TrOk ) ;
859
+ }
860
+
861
+
862
+
863
+ fn one_intregration_one_unit_test_one_unknown ( ) -> Vec < TestDescAndFn > {
864
+ vec ! [
865
+ TestDescAndFn {
866
+ desc: TestDesc {
867
+ name: StaticTestName ( "1" ) ,
868
+ ignore: false ,
869
+ ignore_message: None ,
870
+ should_panic: ShouldPanic :: No ,
871
+ compile_fail: false ,
872
+ no_run: false ,
873
+ test_type: TestType :: IntegrationTest ,
874
+ } ,
875
+ testfn: DynTestFn ( Box :: new( move || Ok ( ( ) ) ) ) ,
876
+ } ,
877
+ TestDescAndFn {
878
+ desc: TestDesc {
879
+ name: StaticTestName ( "2" ) ,
880
+ ignore: false ,
881
+ ignore_message: None ,
882
+ should_panic: ShouldPanic :: No ,
883
+ compile_fail: false ,
884
+ no_run: false ,
885
+ test_type: TestType :: UnitTest ,
886
+ } ,
887
+ testfn: DynTestFn ( Box :: new( move || Ok ( ( ) ) ) ) ,
888
+ } ,
889
+ TestDescAndFn {
890
+ desc: TestDesc {
891
+ name: StaticTestName ( "3" ) ,
892
+ ignore: false ,
893
+ ignore_message: None ,
894
+ should_panic: ShouldPanic :: No ,
895
+ compile_fail: false ,
896
+ no_run: false ,
897
+ test_type: TestType :: Unknown ,
898
+ } ,
899
+ testfn: DynTestFn ( Box :: new( move || Ok ( ( ) ) ) ) ,
900
+ } ,
901
+ ]
902
+ }
903
+
904
+ #[ test]
905
+ fn parse_exclude_integration_flag ( ) {
906
+ let args = vec ! [ "progname" . to_string( ) , "filter" . to_string( ) , "--exclude-integration" . to_string( ) ] ;
907
+ let opts = parse_opts ( & args) . unwrap ( ) . unwrap ( ) ;
908
+ assert_eq ! ( opts. run_integration, RunIntegration :: No ) ;
909
+ }
910
+
911
+ #[ test]
912
+ fn parse_integration_flag ( ) {
913
+ let args = vec ! [ "progname" . to_string( ) , "filter" . to_string( ) , "--integration" . to_string( ) ] ;
914
+ let opts = parse_opts ( & args) . unwrap ( ) . unwrap ( ) ;
915
+ assert_eq ! ( opts. run_integration, RunIntegration :: Only ) ;
916
+ }
917
+
918
+ #[ test]
919
+ fn parse_integration_flags_not_set ( ) {
920
+ let args = vec ! [ "progname" . to_string( ) , "filter" . to_string( ) ] ;
921
+ let opts = parse_opts ( & args) . unwrap ( ) . unwrap ( ) ;
922
+ assert_eq ! ( opts. run_integration, RunIntegration :: Yes ) ;
923
+ }
924
+
925
+ #[ test]
926
+ pub fn filter_for_exclude_integration_option ( ) {
927
+ // The filter should filter out all the integration tests
928
+
929
+ let mut opts = TestOpts :: new ( ) ;
930
+ opts. run_tests = true ;
931
+ opts. run_integration = RunIntegration :: No ;
932
+
933
+ let tests = one_intregration_one_unit_test_one_unknown ( ) ;
934
+ let filtered = filter_tests ( & opts, tests) ;
935
+
936
+ assert_eq ! ( filtered. len( ) , 2 ) ;
937
+ assert_eq ! ( filtered[ 0 ] . desc. name. to_string( ) , "2" ) ;
938
+ assert_eq ! ( filtered[ 0 ] . desc. test_type, TestType :: UnitTest ) ;
939
+ assert_eq ! ( filtered[ 1 ] . desc. name. to_string( ) , "3" ) ;
940
+ assert_eq ! ( filtered[ 1 ] . desc. test_type, TestType :: Unknown ) ;
941
+ }
942
+
943
+ #[ test]
944
+ pub fn filter_for_integration_option ( ) {
945
+ // When we run integrations tests the test filter should filter out all the
946
+ // non-integration tests
947
+
948
+ let mut opts = TestOpts :: new ( ) ;
949
+ opts. run_tests = true ;
950
+ opts. run_integration = RunIntegration :: Only ;
951
+
952
+ let tests = one_intregration_one_unit_test_one_unknown ( ) ;
953
+ let filtered = filter_tests ( & opts, tests) ;
954
+
955
+ assert_eq ! ( filtered. len( ) , 1 ) ;
956
+ assert_eq ! ( filtered[ 0 ] . desc. name. to_string( ) , "1" ) ;
957
+ assert_eq ! ( filtered[ 0 ] . desc. test_type, TestType :: IntegrationTest ) ;
958
+ }
959
+
960
+ #[ test]
961
+ pub fn filter_for_integration_yes_option ( ) {
962
+ // When we run integrations tests the test filter should filter out all the
963
+ // non-integration tests
964
+
965
+ let mut opts = TestOpts :: new ( ) ;
966
+ opts. run_tests = true ;
967
+ opts. run_integration = RunIntegration :: Yes ;
968
+
969
+ let tests = one_intregration_one_unit_test_one_unknown ( ) ;
970
+ let filtered = filter_tests ( & opts, tests) ;
971
+
972
+ assert_eq ! ( filtered. len( ) , 3 ) ;
973
+ assert_eq ! ( filtered[ 0 ] . desc. name. to_string( ) , "1" ) ;
974
+ assert_eq ! ( filtered[ 0 ] . desc. test_type, TestType :: IntegrationTest ) ;
975
+ assert_eq ! ( filtered[ 1 ] . desc. name. to_string( ) , "2" ) ;
976
+ assert_eq ! ( filtered[ 1 ] . desc. test_type, TestType :: UnitTest ) ;
977
+ assert_eq ! ( filtered[ 2 ] . desc. name. to_string( ) , "3" ) ;
978
+ assert_eq ! ( filtered[ 2 ] . desc. test_type, TestType :: Unknown ) ;
979
+ }
0 commit comments