From: Michael Wallner Date: Tue, 7 Jan 2020 21:13:42 +0000 (+0100) Subject: libtest: improve output format; makes eyes hurt less X-Git-Tag: pre_cmake~77 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=2eb14a59f3626073017de925929dcc7e3e9eb43d;p=m6w6%2Flibmemcached libtest: improve output format; makes eyes hurt less --- diff --git a/libtest/collection.cc b/libtest/collection.cc index 2f1cba31..0b2b3249 100644 --- a/libtest/collection.cc +++ b/libtest/collection.cc @@ -138,9 +138,9 @@ test_return_t Collection::exec() } catch (const libtest::fatal& e) { - stream::cerr(e.file(), e.line(), e.func()) << e.what(); _failed++; formatter()->failed(); + stream::make_cerr(e.file(), e.line(), e.func()) << e.what(); throw; } diff --git a/libtest/formatter.cc b/libtest/formatter.cc index 7cb3ea0a..443256b6 100644 --- a/libtest/formatter.cc +++ b/libtest/formatter.cc @@ -41,7 +41,8 @@ #include #include #include - +#include + namespace libtest { std::string& escape4XML(std::string const& arg, std::string& escaped_string) @@ -159,11 +160,14 @@ TestCase* Formatter::current() void Formatter::skipped() { + assert(current()); current()->result(TEST_SKIPPED); - Out << name() << "." - << current()->name() - << "\t\t\t\t\t" - << "[ " << test_strerror(current()->result()) << " ]"; + + Out + << "[ " << test_strerror(current()->result()) << " ]" + << "\t\t" + << name() << "." << current()->name() + ; reset(); } @@ -173,9 +177,11 @@ void Formatter::failed() assert(current()); current()->result(TEST_FAILURE); - Out << name() - << "." << current()->name() << "\t\t\t\t\t" - << "[ " << test_strerror(current()->result()) << " ]"; + Out + << "[ " << test_strerror(current()->result()) << " ]" + << "\t\t" + << name() << "." << current()->name() + ; reset(); } @@ -184,13 +190,14 @@ void Formatter::success(const libtest::Timer& timer_) { assert(current()); current()->result(TEST_SUCCESS, timer_); - std::string escaped_string; - Out << name() << "." - << current()->name() - << "\t\t\t\t\t" - << current()->timer() - << " [ " << test_strerror(current()->result()) << " ]"; + Out + << "[ " << test_strerror(current()->result()) << " ]" + << "\t" + << current()->timer() + << "\t" + << name() << "." << current()->name() + ; reset(); } @@ -252,6 +259,14 @@ void Formatter::push_testcase(const std::string& arg) assert(_suite_name.empty() == false); TestCase* _current_testcase= new TestCase(arg); _testcases.push_back(_current_testcase); + + assert(current()); + + Echo + << "\t\t\t" + << name() << "." << current()->name() + << "... \r" + ; } void Formatter::reset() diff --git a/libtest/stream.h b/libtest/stream.h index 081c2bf0..0124b9d2 100644 --- a/libtest/stream.h +++ b/libtest/stream.h @@ -111,6 +111,37 @@ template } }; +template + class channelfl { + private: + + public: + typedef std::basic_ostringstream stream_buffer; + + public: + void operator()(const stream_buffer& s, std::ostream& _out, + const char* filename, int line_number, const char* func) + { + if (filename) + { + _out + << filename + << ":" + << line_number + << ": in " + << func << "() " + << s.str() + << std::flush; + } + else + { + _out + << s.str() + << std::flush; + } + } + }; + template