diff options
author | Nico Weber <nicolasweber@gmx.de> | 2013-04-09 04:28:12 (GMT) |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2013-04-09 04:28:12 (GMT) |
commit | 6c274da149719fd13150ab0f1f853c524e128f1e (patch) | |
tree | 15c0477e04d4c4a0595f01784c13d67ee1ececfd /src | |
parent | a95b0819703aefc6a4f74004d6639f2cebd1e5d2 (diff) | |
download | Ninja-6c274da149719fd13150ab0f1f853c524e128f1e.zip Ninja-6c274da149719fd13150ab0f1f853c524e128f1e.tar.gz Ninja-6c274da149719fd13150ab0f1f853c524e128f1e.tar.bz2 |
Use LinePrinter in test runner.
Diffstat (limited to 'src')
-rw-r--r-- | src/ninja_test.cc | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/src/ninja_test.cc b/src/ninja_test.cc index f257ee3..5808e39 100644 --- a/src/ninja_test.cc +++ b/src/ninja_test.cc @@ -14,46 +14,48 @@ #include "gtest/gtest.h" +#include "line_printer.h" + +std::string StringPrintf(const char* format, ...) { + const int N = 1024; + char buf[N]; + + va_list ap; + va_start(ap, format); + vsnprintf(buf, N, format, ap); + va_end(ap); + + return buf; +} + /// 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; + printer_.Print(StringPrintf("%s.%s starting", test_info.test_case_name(), + test_info.name()), LinePrinter::SHORT); } 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; + printer_.PrintOnNewLine(StringPrintf( + "*** Failure in %s:%d\n%s\n", test_part_result.file_name(), + test_part_result.line_number(), test_part_result.summary())); } 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; + printer_.Print(StringPrintf("%s.%s ending", test_info.test_case_name(), + test_info.name()), LinePrinter::SHORT); } virtual void OnTestProgramEnd(const testing::UnitTest& unit_test) { - if (!have_blank_line_ && smart_terminal_) - printf("\n"); + printer_.PrintOnNewLine(""); } private: - bool have_blank_line_; - bool smart_terminal_; + LinePrinter printer_; }; int main(int argc, char **argv) { |