@@ -137,6 +137,8 @@ TestSuite_Init (TestSuite *suite, const char *name, int argc, char **argv)
137
137
suite -> flags = 0 ;
138
138
suite -> prgname = bson_strdup (argv [0 ]);
139
139
suite -> silent = false;
140
+ _mongoc_array_init (& suite -> match_patterns , sizeof (char * ));
141
+ _mongoc_array_init (& suite -> skip_patterns , sizeof (char * ));
140
142
141
143
for (i = 1 ; i < argc ; i ++ ) {
142
144
if (0 == strcmp ("-d" , argv [i ])) {
@@ -177,10 +179,24 @@ TestSuite_Init (TestSuite *suite, const char *name, int argc, char **argv)
177
179
(0 == strcmp ("--silent" , argv [i ]))) {
178
180
suite -> silent = true;
179
181
} else if (0 == strcmp ("-l" , argv [i ])) {
182
+ char * val ;
180
183
if (argc - 1 == i ) {
181
184
test_error ("-l requires an argument." );
182
185
}
183
- suite -> testname = bson_strdup (argv [++ i ]);
186
+ val = bson_strdup (argv [++ i ]);
187
+ _mongoc_array_append_val (& suite -> match_patterns , val );
188
+ } else if (0 == strcmp ("--skip" , argv [i ])) {
189
+ char * val ;
190
+ if (argc - 1 == i ) {
191
+ test_error ("--skip requires an argument." );
192
+ }
193
+ val = bson_strdup (argv [++ i ]);
194
+ _mongoc_array_append_val (& suite -> skip_patterns , val );
195
+ } else if (0 == strcmp ("--after" , argv [i ])) {
196
+ if (argc - 1 == i ) {
197
+ test_error ("--after requires an argument." );
198
+ }
199
+ suite -> after = bson_strdup (argv [++ i ]);
184
200
} else {
185
201
test_error ("Unknown option: %s\n"
186
202
"Try using the --help option." ,
@@ -662,21 +678,24 @@ TestSuite_RunTest (TestSuite *suite, /* IN */
662
678
static void
663
679
TestSuite_PrintHelp (TestSuite * suite ) /* IN */
664
680
{
665
- printf ("usage: %s [OPTIONS]\n"
666
- "\n"
667
- "Options:\n"
668
- " -h, --help Show this help menu.\n"
669
- " --list-tests Print list of available tests.\n"
670
- " -f, --no-fork Do not spawn a process per test (abort on first "
671
- "error).\n"
672
- " -l NAME Run test by name, e.g. \"/Client/command\" or "
673
- "\"/Client/*\".\n"
674
- " -s, --silent Suppress all output.\n"
675
- " -F FILENAME Write test results (JSON) to FILENAME.\n"
676
- " -d Print debug output (useful if a test hangs).\n"
677
- " -t, --trace Enable mongoc tracing (useful to debug tests).\n"
678
- "\n" ,
679
- suite -> prgname );
681
+ printf (
682
+ "usage: %s [OPTIONS]\n"
683
+ "\n"
684
+ "Options:\n"
685
+ " -h, --help Show this help menu.\n"
686
+ " --list-tests Print list of available tests.\n"
687
+ " -f, --no-fork Do not spawn a process per test (abort on first "
688
+ "error).\n"
689
+ " -l PATTERN Run test by name, e.g. \"/Client/command\" or "
690
+ "\"/Client/*\". May be repeated.\n"
691
+ " -s, --silent Suppress all output.\n"
692
+ " -F FILENAME Write test results (JSON) to FILENAME.\n"
693
+ " -d Print debug output (useful if a test hangs).\n"
694
+ " -t, --trace Enable mongoc tracing (useful to debug tests).\n"
695
+ " --skip PATTERN Skip test by name or pattern. May be repeated.\n"
696
+ " --after NAME Start running tests after this test name.\n"
697
+ "\n" ,
698
+ suite -> prgname );
680
699
}
681
700
682
701
@@ -857,36 +876,6 @@ TestSuite_PrintJsonFooter (FILE *stream) /* IN */
857
876
fflush (stream );
858
877
}
859
878
860
-
861
- static int
862
- TestSuite_RunSerial (TestSuite * suite ) /* IN */
863
- {
864
- Test * test ;
865
- int count = 0 ;
866
- int status = 0 ;
867
-
868
- for (test = suite -> tests ; test ; test = test -> next ) {
869
- count ++ ;
870
- }
871
-
872
- for (test = suite -> tests ; test ; test = test -> next ) {
873
- status += TestSuite_RunTest (suite , test , & count );
874
- count -- ;
875
- }
876
-
877
- if (suite -> silent ) {
878
- return status ;
879
- }
880
-
881
- TestSuite_PrintJsonFooter (stdout );
882
- if (suite -> outfile ) {
883
- TestSuite_PrintJsonFooter (suite -> outfile );
884
- }
885
-
886
- return status ;
887
- }
888
-
889
-
890
879
static bool
891
880
TestSuite_TestMatchesName (const TestSuite * suite ,
892
881
const Test * test ,
@@ -906,26 +895,70 @@ TestSuite_TestMatchesName (const TestSuite *suite,
906
895
}
907
896
908
897
898
+ bool
899
+ test_matches (TestSuite * suite , Test * test )
900
+ {
901
+ int i ;
902
+ bool matches ;
903
+
904
+ /* If no match patterns were provided, then assume all match unless they are
905
+ * skipped. */
906
+ if (suite -> match_patterns .len == 0 ) {
907
+ matches = true;
908
+ } else {
909
+ matches = false;
910
+ for (i = 0 ; i < suite -> match_patterns .len ; i ++ ) {
911
+ char * pattern =
912
+ _mongoc_array_index (& suite -> match_patterns , char * , i );
913
+ if (TestSuite_TestMatchesName (suite , test , pattern )) {
914
+ matches = true;
915
+ break ;
916
+ }
917
+ }
918
+ }
919
+
920
+ /* Remove it if it matches anything in the skips. */
921
+ for (i = 0 ; i < suite -> skip_patterns .len ; i ++ ) {
922
+ char * pattern = _mongoc_array_index (& suite -> skip_patterns , char * , i );
923
+ if (TestSuite_TestMatchesName (suite , test , pattern )) {
924
+ return false;
925
+ }
926
+ }
927
+
928
+ return matches ;
929
+ }
930
+
909
931
static int
910
- TestSuite_RunNamed (TestSuite * suite , /* IN */
911
- const char * testname ) /* IN */
932
+ TestSuite_RunAll (TestSuite * suite /* IN */ )
912
933
{
913
934
Test * test ;
914
935
int count = 0 ;
915
936
int status = 0 ;
937
+ int num_to_skip = 0 ;
916
938
917
939
ASSERT (suite );
918
- ASSERT (testname );
919
940
920
941
/* initialize "count" so we can omit comma after last test output */
921
942
for (test = suite -> tests ; test ; test = test -> next ) {
922
- if (TestSuite_TestMatchesName (suite , test , testname )) {
943
+ if (test_matches (suite , test )) {
923
944
count ++ ;
924
945
}
946
+ if (suite -> after && 0 == strcmp (test -> name , suite -> after )) {
947
+ num_to_skip = count - 1 ;
948
+ }
949
+ }
950
+
951
+ if (suite -> after && num_to_skip == 0 ) {
952
+ test_error ("Error: specified --after \"%s\", but no tests matched" , suite -> after );
925
953
}
926
954
927
955
for (test = suite -> tests ; test ; test = test -> next ) {
928
- if (TestSuite_TestMatchesName (suite , test , testname )) {
956
+ if (num_to_skip > 0 ) {
957
+ num_to_skip -- ;
958
+ count -- ;
959
+ continue ;
960
+ }
961
+ if (test_matches (suite , test )) {
929
962
status += TestSuite_RunTest (suite , test , & count );
930
963
count -- ;
931
964
}
@@ -971,11 +1004,7 @@ TestSuite_Run (TestSuite *suite) /* IN */
971
1004
972
1005
start_us = bson_get_monotonic_time ();
973
1006
if (suite -> tests ) {
974
- if (suite -> testname ) {
975
- failures += TestSuite_RunNamed (suite , suite -> testname );
976
- } else {
977
- failures += TestSuite_RunSerial (suite );
978
- }
1007
+ failures += TestSuite_RunAll (suite );
979
1008
} else if (!suite -> silent ) {
980
1009
TestSuite_PrintJsonFooter (stdout );
981
1010
if (suite -> outfile ) {
@@ -994,6 +1023,7 @@ TestSuite_Destroy (TestSuite *suite)
994
1023
{
995
1024
Test * test ;
996
1025
Test * tmp ;
1026
+ int i ;
997
1027
998
1028
bson_mutex_lock (& gTestMutex );
999
1029
gTestSuite = NULL ;
@@ -1019,7 +1049,18 @@ TestSuite_Destroy (TestSuite *suite)
1019
1049
1020
1050
free (suite -> name );
1021
1051
free (suite -> prgname );
1022
- free (suite -> testname );
1052
+ for (i = 0 ; i < suite -> skip_patterns .len ; i ++ ) {
1053
+ char * val = _mongoc_array_index (& suite -> skip_patterns , char * , i );
1054
+ bson_free (val );
1055
+ }
1056
+ _mongoc_array_destroy (& suite -> skip_patterns );
1057
+ for (i = 0 ; i < suite -> match_patterns .len ; i ++ ) {
1058
+ char * val = _mongoc_array_index (& suite -> match_patterns , char * , i );
1059
+ bson_free (val );
1060
+ }
1061
+
1062
+ _mongoc_array_destroy (& suite -> match_patterns );
1063
+ free (suite -> after );
1023
1064
}
1024
1065
1025
1066
0 commit comments