@@ -259,119 +259,154 @@ void tests_run(Gamep g)
259259 term_log (" Running tests\n " );
260260 term_log (" -------------\n " );
261261
262- for (auto &test : test_name_map) {
263-
264- bool result = false ;
265- bool skipped = false ;
266-
267- //
268- // Test name
269- //
270- auto name = " test_" + test.first ;
271- auto *t = test.second ;
272- auto pre = std::format (" Running {:<70s}" , name);
273-
274- //
275- // Skip the test if needed
276- //
277- if (! g_opt_test_name_filter.empty ()) {
278- if (g_opt_test_name_filter == " all" ) {
279- //
280- // All tests or "--tests"
281- //
282- } else if (name.find (g_opt_test_name_filter) != std::string::npos) {
283- //
284- // Partial match e.g. "monst" for all monst tests
285- //
286- } else if (name != g_opt_test_name_filter) {
287- //
288- // Failed to match
289- //
290- skipped = true ;
291- continue ;
262+ bool found_match = {};
263+ bool exact_match_found = {};
264+
265+ if (! g_opt_test_name_filter.empty ()) {
266+ for (auto &test : test_name_map) {
267+ auto name = " test_" + test.first ;
268+ if (g_opt_test_name_filter == name) {
269+ exact_match_found = true ;
292270 }
293271 }
272+ }
294273
295- g_opt_test_current = name;
274+ if (! g_opt_test_repeat) {
275+ g_opt_test_repeat = 1 ;
276+ }
296277
297- //
298- // Preamble
299- //
300- if (! skipped) {
301- log (" running test: %s" , name.c_str ());
302- log (" -------------------------------------------" );
303- }
278+ for (auto repeat = 0 ; repeat < g_opt_test_repeat; repeat++) {
279+ for (auto &test : test_name_map) {
280+
281+ bool result = false ;
282+ bool skipped = false ;
283+
284+ //
285+ // Test name
286+ //
287+ auto name = " test_" + test.first ;
288+ auto *t = test.second ;
289+ auto pre = std::format (" Running {:<70s}" , name);
290+
291+ //
292+ // Skip the test if needed
293+ //
294+ if (! g_opt_test_name_filter.empty ()) {
295+ if (g_opt_test_name_filter == " all" ) {
296+ //
297+ // All tests or "--tests"
298+ //
299+ found_match = true ;
300+ } else if (exact_match_found) {
301+ //
302+ // Exact match
303+ //
304+ if (g_opt_test_name_filter == name) {
305+ found_match = true ;
306+ } else {
307+ continue ;
308+ }
309+ } else if (name.find (g_opt_test_name_filter) != std::string::npos) {
310+ //
311+ // Partial match e.g. "monst" for all monst tests
312+ //
313+ found_match = true ;
314+ } else if (name != g_opt_test_name_filter) {
315+ //
316+ // Failed to match
317+ //
318+ skipped = true ;
319+ continue ;
320+ }
321+ }
304322
305- //
306- // Run the test
307- //
308- auto started = time_ms ();
309- if (! skipped) {
310- result = t->callback (g, t);
311- }
312- auto elapsed = time_ms () - started;
313- auto how_long = std::format (" (took {:.2f} secs, {} ms)" , static_cast < float >(elapsed) / 1000.0 , elapsed);
323+ g_opt_test_current = name;
314324
315- //
316- // Print the timestamp
317- //
318- char buf[ MAXLONGSTR ];
319- buf[ 0 ] = ' \0 ' ;
320- get_timestamp (buf, MAXLONGSTR );
325+ //
326+ // Preamble
327+ //
328+ if (! skipped) {
329+ log (" running test: %s" , name.c_str ());
330+ log (" -------------------------------------------" );
331+ }
332+
333+ //
334+ // Run the test
335+ //
336+ auto started = time_ms ();
337+ if (! skipped) {
338+ result = t->callback (g, t);
339+ }
340+ auto elapsed = time_ms () - started;
341+ auto how_long = std::format (" (took {:.2f} secs, {} ms)" , static_cast < float >(elapsed) / 1000.0 , elapsed);
342+
343+ //
344+ // Print the timestamp
345+ //
346+ char buf[ MAXLONGSTR ];
347+ buf[ 0 ] = ' \0 ' ;
348+ get_timestamp (buf, MAXLONGSTR );
321349
322350#ifdef GITHUB_BUILD
323- std::string out (buf);
324-
325- //
326- // Test preamble. We print this after the test has ran to avoid messing up the output.
327- //
328- out += pre ;
329-
330- if (skipped) {
331- out += " skipped" ;
332- } else if (result) {
333- passed++;
334- out += " OK " ;
335- out += how_long;
336-
337- log (" passed %s" , how_long.c_str ());
338- } else {
339- failed++;
340- out += " FAILED" ;
341- log (" failed" );
342- }
343- std::println (" {}" , out);
351+ std::string out (buf);
352+
353+ //
354+ // Test preamble. We print this after the test has ran to avoid messing up the output.
355+ //
356+ out += pre ;
357+
358+ if (skipped) {
359+ out += " skipped" ;
360+ } else if (result) {
361+ passed++;
362+ out += " OK " ;
363+ out += how_long;
364+
365+ log (" passed %s" , how_long.c_str ());
366+ } else {
367+ failed++;
368+ out += " FAILED" ;
369+ log (" failed" );
370+ }
371+ std::println (" {}" , out);
344372#else
345- term_log (buf);
346- //
347- // Test preamble. We print this after the test has ran to avoid messing up the output.
348- //
349- term_log (pre .c_str ());
350-
351- if (skipped) {
352- term_log (" %%fg=yellow$skipped%%fg=reset$\n " );
353- } else if (result) {
354- passed++;
355- term_log (" %%fg=green$OK%%fg=reset$ " );
356- term_log (how_long.c_str ());
357- term_log (" \n " );
358- log (" passed %s" , how_long.c_str ());
359- } else {
360- failed++;
361- term_log (" %%fg=red$FAILED%%fg=reset$\n " );
362- log (" failed" );
363- }
373+ term_log (buf);
374+ //
375+ // Test preamble. We print this after the test has ran to avoid messing up the output.
376+ //
377+ term_log (pre .c_str ());
378+
379+ if (skipped) {
380+ term_log (" %%fg=yellow$skipped%%fg=reset$\n " );
381+ } else if (result) {
382+ passed++;
383+ term_log (" %%fg=green$OK%%fg=reset$ " );
384+ term_log (how_long.c_str ());
385+ term_log (" \n " );
386+ log (" passed %s" , how_long.c_str ());
387+ } else {
388+ failed++;
389+ term_log (" %%fg=red$FAILED%%fg=reset$\n " );
390+ log (" failed" );
391+ }
364392#endif
365393
366- if (! skipped) {
367- log (" -" );
394+ if (! skipped) {
395+ log (" -" );
396+ }
397+
398+ //
399+ // github output seems to be buffered.
400+ //
401+ fflush (stdout);
402+ fflush (stderr);
368403 }
404+ }
369405
370- //
371- // github output seems to be buffered.
372- //
373- fflush (stdout);
374- fflush (stderr);
406+ if (! g_opt_test_name_filter.empty ()) {
407+ if (! found_match) {
408+ CROAK (" found no test matching filter: %s" , g_opt_test_name_filter.c_str ());
409+ }
375410 }
376411
377412 test_fini ();
0 commit comments