77using namespace tpunit ;
88
99atomic<bool > tpunit::_TestFixture::exitFlag (false );
10+ bool tpunit::_TestFixture::_verboseOutput = false ;
11+ atomic<int > tpunit::_TestFixture::_shortOutputColumn (0 );
1012thread_local string tpunit::currentTestName;
1113thread_local tpunit::_TestFixture* tpunit::currentTestPtr = nullptr ;
1214thread_local mutex tpunit::currentTestNameMutex;
@@ -429,7 +431,25 @@ bool tpunit::_TestFixture::tpunit_detail_fp_equal(double lhs, double rhs, unsign
429431 ((lhs_u.c [lsb] > rhs_u.c [lsb]) ? lhs_u.c [lsb] - rhs_u.c [lsb] : rhs_u.c [lsb] - lhs_u.c [lsb]) <= ulps;
430432}
431433
434+ namespace tpunit {
435+ void tpunit_break_check_line () {
436+ if (!_TestFixture::_verboseOutput) {
437+ if (currentTestPtr) {
438+ currentTestPtr->_mutex ->lock ();
439+ }
440+ if (_TestFixture::_shortOutputColumn > 0 ) {
441+ printf (" \n " );
442+ _TestFixture::_shortOutputColumn = 0 ;
443+ }
444+ if (currentTestPtr) {
445+ currentTestPtr->_mutex ->unlock ();
446+ }
447+ }
448+ }
449+ }
450+
432451void tpunit::_TestFixture::tpunit_detail_assert (_TestFixture* f, const char * _file, int _line) {
452+ tpunit_break_check_line ();
433453 lock_guard<recursive_mutex> lock (*(f->_mutex ));
434454 printf (" assertion #%i at %s:%i\n " , ++f->_stats ._assertions , _file, _line);
435455 f->printTestBuffer ();
@@ -442,6 +462,7 @@ void tpunit::_TestFixture::tpunit_detail_exception(_TestFixture* f, method* _met
442462}
443463
444464void tpunit::_TestFixture::tpunit_detail_trace (_TestFixture* f, const char * _file, int _line, const char * _message) {
465+ tpunit_break_check_line ();
445466 lock_guard<recursive_mutex> lock (*(f->_mutex ));
446467 printf (" trace #%i at %s:%i: %s\n " , ++f->_stats ._traces , _file, _line, _message);
447468 f->printTestBuffer ();
@@ -455,15 +476,18 @@ void tpunit::_TestFixture::tpunit_detail_do_method(tpunit::_TestFixture::method*
455476 }
456477 (*m->_this .*m->_addr )();
457478 } catch (const std::exception& e) {
479+ tpunit_break_check_line ();
458480 lock_guard<recursive_mutex> lock (*(m->_this ->_mutex ));
459481 tpunit_detail_exception (m->_this , m, e.what ());
460482 } catch (const char * e) {
483+ tpunit_break_check_line ();
461484 lock_guard<recursive_mutex> lock (*(m->_this ->_mutex ));
462485 tpunit_detail_exception (m->_this , m, e);
463486 } catch (ShutdownException se) {
464487 // Just re-throw, this exception is special and indicates that a test wants its thread to quit.
465488 throw ;
466489 } catch (...) {
490+ tpunit_break_check_line ();
467491 lock_guard<recursive_mutex> lock (*(m->_this ->_mutex ));
468492 tpunit_detail_exception (m->_this , m, " caught unknown exception type" );
469493 }
@@ -504,16 +528,34 @@ void tpunit::_TestFixture::tpunit_detail_do_tests(_TestFixture* f) {
504528 // No new assertions or exceptions. This not currently synchronized correctly. They can cause tests that
505529 // passed to appear failed when another test failed while this test was running. They cannot cause failed
506530 // tests to appear to have passed.
531+ lock_guard<recursive_mutex> lock (m);
507532 if (!f->_stats ._assertions && !f->_stats ._exceptions ) {
508- lock_guard<recursive_mutex> lock (m);
509- printf (" \xE2\x9C\x85 %s %s\n " , t->_name , time);
533+ if (_verboseOutput) {
534+ printf (" \xE2\x9C\x85 %s %s\n " , t->_name , time);
535+ } else {
536+ if (_shortOutputColumn >= 80 ) {
537+ printf (" \n " );
538+ _shortOutputColumn = 0 ;
539+ }
540+ printf (" \033 [32m\xE2\x9C\x93\033 [0m" );
541+ fflush (stdout);
542+ _shortOutputColumn++;
543+ }
510544 tpunit_detail_stats ()._passes ++;
511545 } else {
512- lock_guard<recursive_mutex> lock (m);
513-
514- // Dump the test buffer if the test included any log lines.
515- f->printTestBuffer ();
516- printf (" \xE2\x9D\x8C !FAILED! \xE2\x9D\x8C %s %s\n " , t->_name , time);
546+ if (_verboseOutput) {
547+ // Dump the test buffer if the test included any log lines.
548+ f->printTestBuffer ();
549+ printf (" \xE2\x9D\x8C !FAILED! \xE2\x9D\x8C %s %s\n " , t->_name , time);
550+ } else {
551+ if (_shortOutputColumn > 0 ) {
552+ printf (" \n " );
553+ _shortOutputColumn = 0 ;
554+ }
555+ // Dump the test buffer if the test included any log lines.
556+ f->printTestBuffer ();
557+ printf (" \xE2\x9D\x8C !FAILED! \xE2\x9D\x8C %s %s\n\n " , t->_name , time);
558+ }
517559 tpunit_detail_stats ()._failures ++;
518560 tpunit_detail_stats ()._failureNames .emplace (t->_name );
519561 }
0 commit comments