Skip to content

Commit

Permalink
Make gtest output more silent, ninja issue #528.
Browse files Browse the repository at this point in the history
This is just a proof-of-concept. The terminal printing logic should be
extracted from src/build.cc and then reused here.
  • Loading branch information
nico committed Apr 9, 2013
1 parent 1baebab commit 94f999b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
4 changes: 1 addition & 3 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,6 @@ def has_re2c():
objs += n.build(built('gtest-all' + objext), 'cxx',
os.path.join(path, 'src', 'gtest-all.cc'),
variables=[('cflags', gtest_cflags)])
objs += n.build(built('gtest_main' + objext), 'cxx',
os.path.join(path, 'src', 'gtest_main.cc'),
variables=[('cflags', gtest_cflags)])

test_cflags.append('-I%s' % os.path.join(path, 'include'))
else:
Expand All @@ -353,6 +350,7 @@ def has_re2c():
'graph_test',
'lexer_test',
'manifest_parser_test',
'ninja_test',
'state_test',
'subprocess_test',
'test',
Expand Down
54 changes: 54 additions & 0 deletions src/ninja_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "gtest/gtest.h"

/// A test result printer that's less wordy than gtest's default.
class LaconicPrinter : public testing::EmptyTestEventListener {
public:
LaconicPrinter() : have_blank_line_(false), smart_terminal_(true) {}

virtual void OnTestStart(const testing::TestInfo& test_info) {
printf("\r%s.%s starting.", test_info.test_case_name(), test_info.name());
printf("\x1B[K"); // Clear to end of line.
fflush(stdout);
have_blank_line_ = false;
}

virtual void OnTestPartResult(
const testing::TestPartResult& test_part_result) {
if (!test_part_result.failed())
return;
if (!have_blank_line_ && smart_terminal_)
printf("\n");
printf("*** Failure in %s:%d\n%s\n",
test_part_result.file_name(),
test_part_result.line_number(),
test_part_result.summary());
have_blank_line_ = true;
}

virtual void OnTestEnd(const testing::TestInfo& test_info) {
printf("\r%s.%s ending.", test_info.test_case_name(), test_info.name());
printf("\x1B[K"); // Clear to end of line.
fflush(stdout);
have_blank_line_ = false;
}

virtual void OnTestProgramEnd(const testing::UnitTest& unit_test) {
if (!have_blank_line_ && smart_terminal_)
printf("\n");
}

private:
bool have_blank_line_;
bool smart_terminal_;
};

int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);

testing::TestEventListeners& listeners =
testing::UnitTest::GetInstance()->listeners();
delete listeners.Release(listeners.default_result_printer());
listeners.Append(new LaconicPrinter);

return RUN_ALL_TESTS();
}

0 comments on commit 94f999b

Please sign in to comment.