summaryrefslogtreecommitdiffstats
path: root/src/ninja_test.cc
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2013-04-09 01:02:05 (GMT)
committerNico Weber <nicolasweber@gmx.de>2013-04-09 01:02:05 (GMT)
commit94f999b681ea4ced1cc27b29e0db77d72554ecf9 (patch)
treedbbb548a169566768a4d490a54742d4260f17db4 /src/ninja_test.cc
parent1baebab74d036f40eddf47a361145305038fa78d (diff)
downloadNinja-94f999b681ea4ced1cc27b29e0db77d72554ecf9.zip
Ninja-94f999b681ea4ced1cc27b29e0db77d72554ecf9.tar.gz
Ninja-94f999b681ea4ced1cc27b29e0db77d72554ecf9.tar.bz2
Make gtest output more silent, ninja issue #528.
This is just a proof-of-concept. The terminal printing logic should be extracted from src/build.cc and then reused here.
Diffstat (limited to 'src/ninja_test.cc')
-rw-r--r--src/ninja_test.cc54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/ninja_test.cc b/src/ninja_test.cc
new file mode 100644
index 0000000..0e0f882
--- /dev/null
+++ b/src/ninja_test.cc
@@ -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();
+}