Skip to content

Commit 1a276b9

Browse files
Merge pull request #2542 from Expensify/main
Update expensify_prod branch
2 parents f17ae81 + 65b62e6 commit 1a276b9

File tree

6 files changed

+66
-7
lines changed

6 files changed

+66
-7
lines changed

benchmarks/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ int main(int argc, char* argv[])
131131
exclude.insert(args["-except"]);
132132
}
133133

134+
if (args.contains("-v") || args.contains("--verbose")) {
135+
tpunit::_TestFixture::_verboseOutput = true;
136+
}
137+
134138
if (baselineRef.empty()) {
135139
// Normal benchmark run
136140
return runBenchmarks(include, exclude) ? 0 : 1;

test/clustertest/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ int main(int argc, char* argv[])
8686
if (args.isSet("-v")) {
8787
BedrockTester::VERBOSE_LOGGING = true;
8888
SLogLevel(LOG_DEBUG);
89+
tpunit::_TestFixture::_verboseOutput = true;
8990
}
9091
if (args.isSet("-q")) {
9192
BedrockTester::QUIET_LOGGING = true;

test/lib/PrintEquality.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
using namespace std;
1111

12+
namespace tpunit {void tpunit_break_check_line();}
13+
1214
template<typename T>
1315
ostream& operator<<(ostream& output, const list<T>& val)
1416
{
@@ -46,6 +48,7 @@ class PrintEquality {
4648
template<typename U, typename V>
4749
PrintEquality(const U& a, const V& b, bool isEqual)
4850
{
51+
tpunit::tpunit_break_check_line();
4952
cout << a << " " << (isEqual ? "=" : "!") << "= " << b << "\n";
5053
}
5154
};

test/lib/tpunit++.cpp

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
using namespace tpunit;
88

99
atomic<bool> tpunit::_TestFixture::exitFlag(false);
10+
bool tpunit::_TestFixture::_verboseOutput = false;
11+
atomic<int> tpunit::_TestFixture::_shortOutputColumn(0);
1012
thread_local string tpunit::currentTestName;
1113
thread_local tpunit::_TestFixture* tpunit::currentTestPtr = nullptr;
1214
thread_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+
432451
void 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

444464
void 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
}

test/lib/tpunit++.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ namespace tpunit {
204204
public:
205205

206206
static std::atomic<bool> exitFlag;
207+
static bool _verboseOutput;
208+
static std::atomic<int> _shortOutputColumn;
207209

208210
struct perFixtureStats {
209211
perFixtureStats();
@@ -439,6 +441,12 @@ namespace tpunit {
439441

440442
extern thread_local tpunit::_TestFixture* currentTestPtr;
441443

444+
/**
445+
* If short output mode is active and checks have been printed on the current
446+
* line, prints a newline and resets the column counter.
447+
*/
448+
void tpunit_break_check_line();
449+
442450
/**
443451
* Convenience class containing the entry point to run all registered tests.
444452
*/

test/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ int main(int argc, char* argv[])
9898
if (args.isSet("-v")) {
9999
BedrockTester::VERBOSE_LOGGING = true;
100100
SLogLevel(LOG_DEBUG);
101+
tpunit::_TestFixture::_verboseOutput = true;
101102
}
102103
if (args.isSet("-q")) {
103104
BedrockTester::QUIET_LOGGING = true;

0 commit comments

Comments
 (0)