From 27adb1fc44c1ac983d0f3b586e94134c1638cb77 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 19 Aug 2013 04:33:16 +0000 Subject: [PATCH] improve error reporting from unit tests --- test/main.cpp | 13 +++++++++++-- test/setup_transfer.cpp | 10 +++++++--- test/setup_transfer.hpp | 3 ++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/test/main.cpp b/test/main.cpp index 40fb89dca..150d7444b 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -158,12 +158,21 @@ int main() fflush(stdout); fflush(stderr); - if (!tests_failure) + if (tests_failure == 0) { remove_all(test_dir, ec); if (ec) fprintf(stderr, "failed to remove test dir: %s\n", ec.message().c_str()); } - return tests_failure ? 1 : 0; + else + { + for (std::vector::iterator i = failure_strings.begin() + , end(failure_strings.end()); i != end; ++i) + { + fputs(i->c_str(), stderr); + } + fprintf(stderr, "\n\n\x1b[41m == %d TEST(S) FAILED ==\x1b[0m\n\n\n", tests_failure); + } + return tests_failure; } diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index 6c6d87758..5188d312d 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -66,12 +66,16 @@ POSSIBILITY OF SUCH DAMAGE. using namespace libtorrent; -bool tests_failure = false; +int tests_failure = 0; +std::vector failure_strings; void report_failure(char const* err, char const* file, int line) { - fprintf(stderr, "\n***** %s:%d \"%s\" *****\n\n", file, line, err); - tests_failure = true; + char buf[500]; + snprintf(buf, sizeof(buf), "\x1b[41m***** %s:%d \"%s\" *****\x1b[0m\n", file, line, err); + fprintf(stderr, "\n%s\n", buf); + failure_strings.push_back(buf); + ++tests_failure; } std::auto_ptr wait_for_alert(session& ses, int type) diff --git a/test/setup_transfer.hpp b/test/setup_transfer.hpp index f95dd51bb..1f58d66c2 100644 --- a/test/setup_transfer.hpp +++ b/test/setup_transfer.hpp @@ -44,7 +44,8 @@ namespace libtorrent struct session_status; } -extern EXPORT bool tests_failure; +extern EXPORT int tests_failure; +extern EXPORT std::vector failure_strings; int EXPORT load_file(std::string const& filename, std::vector& v, libtorrent::error_code& ec, int limit = 8000000);