@@ -190,6 +190,18 @@ int TestRegistry::runAllTests(int argc, char* argv[]) {
190190 utils::initializeMPI (argc, argv);
191191 }
192192
193+ // Parse command line arguments for test filter
194+ std::string filter = " " ;
195+ for (int i = 1 ; i < argc; ++i) {
196+ std::string arg = argv[i];
197+ if (arg.find (" --gtest_filter=" ) == 0 ) {
198+ filter = arg.substr (15 ); // Length of "--gtest_filter="
199+ } else if (arg == " --gtest_filter" && i + 1 < argc) {
200+ filter = argv[i + 1 ];
201+ ++i;
202+ }
203+ }
204+
193205 // Set up global test environments
194206 for (auto * env : environments_) {
195207 try {
@@ -204,17 +216,40 @@ int TestRegistry::runAllTests(int argc, char* argv[]) {
204216
205217 int passed = 0 ;
206218 int failed = 0 ;
219+ int skipped = 0 ;
220+
221+ // Count tests to run
222+ int total_to_run = 0 ;
223+ for (const auto & test_info : tests_) {
224+ std::string full_name = test_info.suite_name + " ." + test_info.test_name ;
225+ if (!filter.empty () && full_name.find (filter) == std::string::npos) {
226+ skipped++;
227+ continue ;
228+ }
229+ total_to_run++;
230+ }
207231
208232 if (g_mpi_rank == 0 ) {
209- std::cout << " [==========] Running " << tests_.size () << " tests.\n " ;
233+ std::cout << " [==========] Running " << total_to_run << " tests" ;
234+ if (skipped > 0 ) {
235+ std::cout << " (" << skipped << " skipped by filter)" ;
236+ }
237+ std::cout << " .\n " ;
210238 }
211239
212240 for (const auto & test_info : tests_) {
241+ std::string full_name = test_info.suite_name + " ." + test_info.test_name ;
242+
243+ // Apply filter
244+ if (!filter.empty () && full_name.find (filter) == std::string::npos) {
245+ continue ;
246+ }
247+
213248 g_current_test_passed = true ;
214249 g_current_test_failure_message.clear ();
215250
216251 if (g_mpi_rank == 0 ) {
217- std::cout << " [ RUN ] " << test_info. suite_name << " . " << test_info. test_name << std::endl;
252+ std::cout << " [ RUN ] " << full_name << std::endl;
218253 }
219254
220255 // Set current test info for UnitTest::GetInstance()->current_test_info()
@@ -255,17 +290,17 @@ int TestRegistry::runAllTests(int argc, char* argv[]) {
255290
256291 if (g_mpi_rank == 0 ) {
257292 if (global_passed) {
258- std::cout << " [ OK ] " << test_info. suite_name << " . " << test_info. test_name << std::endl;
293+ std::cout << " [ OK ] " << full_name << std::endl;
259294 passed++;
260295 } else {
261- std::cout << " [ FAILED ] " << test_info. suite_name << " . " << test_info. test_name << std::endl;
296+ std::cout << " [ FAILED ] " << full_name << std::endl;
262297 failed++;
263298 }
264299 }
265300 }
266301
267302 if (g_mpi_rank == 0 ) {
268- std::cout << " [==========] " << tests_. size () << " tests ran.\n " ;
303+ std::cout << " [==========] " << total_to_run << " tests ran.\n " ;
269304 if (passed > 0 ) {
270305 std::cout << " [ PASSED ] " << passed << " tests.\n " ;
271306 }
0 commit comments