1717
1818// Add Tests to runner that match user-provided regex.
1919int add_matching_tests_to_runner (CppUnit ::Test * test ,
20- const std ::string & r_str ,
21- const std ::regex & r ,
20+ const std ::string & allow_r_str ,
21+ const std ::regex & allow_r ,
22+ const std ::string & deny_r_str ,
23+ const std ::regex & deny_r ,
2224 CppUnit ::TextUi ::TestRunner & runner ,
2325 CppUnit ::TestSuite & rejects )
2426{
2527 int n_tests_added = 0 ;
2628
27- // If we running all tests we just add the "All Tests" test and then return
28- if (test -> getName () == "All Tests" && r_str == "All Tests" )
29+ // If running all tests, just add the "All Tests" test and return
30+ if (test -> getName () == "All Tests" && allow_r_str == "All Tests" &&
31+ deny_r_str == "^$" )
2932 {
3033 libMesh ::out << test -> getName () << std ::endl ;
3134 runner .addTest (test );
@@ -35,7 +38,9 @@ int add_matching_tests_to_runner(CppUnit::Test * test,
3538 if (test -> getChildTestCount () == 0 )
3639 {
3740 // Add the test to the runner
38- if (std ::regex_search (test -> getName (), r ))
41+ if ((allow_r_str == "All Tests" ||
42+ std ::regex_search (test -> getName (), allow_r )) &&
43+ !std ::regex_search (test -> getName (), deny_r ))
3944 {
4045 libMesh ::out << test -> getName () << std ::endl ;
4146 n_tests_added ++ ;
@@ -49,8 +54,8 @@ int add_matching_tests_to_runner(CppUnit::Test * test,
4954 // Call this recursively on each of our children, if any.
5055 for (int i = 0 ; i < test -> getChildTestCount (); i ++ )
5156 n_tests_added +=
52- add_matching_tests_to_runner (test -> getChildTestAt (i ), r_str , r ,
53- runner , rejects );
57+ add_matching_tests_to_runner (test -> getChildTestAt (i ), allow_r_str , allow_r ,
58+ deny_r_str , deny_r , runner , rejects );
5459
5560 return n_tests_added ;
5661}
@@ -97,9 +102,17 @@ int main(int argc, char ** argv)
97102 // If the user does not provide a a regex, the default re is "All Tests",
98103 // which runs all the unit tests.
99104
100- // Read command line argument specifying the regular expression.
101- std ::string regex_string = "All Tests" ;
102- regex_string = libMesh ::command_line_next ("--re" , regex_string );
105+ // We can also skip tests that match a regular expression, with e.g.
106+ // "--deny_re PartitionerTest" to skip all the Partitioner unit
107+ // tests (even if a "--re" option would have included them.)
108+
109+ // Read command line argument specifying the allowlist regular expression.
110+ std ::string allow_regex_string = "All Tests" ;
111+ allow_regex_string = libMesh ::command_line_next ("--re" , allow_regex_string );
112+
113+ // Read command line argument specifying the allowlist regular expression.
114+ std ::string deny_regex_string = "^$" ;
115+ deny_regex_string = libMesh ::command_line_next ("--deny_re" , deny_regex_string );
103116
104117 // Recursively add tests matching the regex tothe runner object.
105118 CppUnit ::TextUi ::TestRunner runner ;
@@ -112,14 +125,17 @@ int main(int argc, char ** argv)
112125 CppUnit ::TestSuite rejects ("rejects" );
113126
114127#ifdef LIBMESH_HAVE_CXX11_REGEX
115- // Make regex object from user's input.
116- std ::regex the_regex (regex_string );
128+ // Make regex objects from user's input.
129+ const std ::regex allow_regex (allow_regex_string );
130+ const std ::regex deny_regex (deny_regex_string );
117131
118132 // Add all tests which match the re to the runner object.
119133 libMesh ::out << "Will run the following tests:" << std ::endl ;
120134 const int n_tests_added =
121- add_matching_tests_to_runner (registry .makeTest (), regex_string ,
122- the_regex , runner , rejects );
135+ add_matching_tests_to_runner (registry .makeTest (),
136+ allow_regex_string , allow_regex ,
137+ deny_regex_string , deny_regex ,
138+ runner , rejects );
123139 if (n_tests_added >= 0 )
124140 libMesh ::out << "--- Running " << n_tests_added << " tests in total." << std ::endl ;
125141#else
0 commit comments