diff --git a/test/main.cpp b/test/main.cpp index 150d7444b..1208c79a8 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -138,13 +138,13 @@ int main() } catch (std::exception const& e) { - std::cerr << "Terminated with exception: \"" << e.what() << "\"\n"; - tests_failure = true; + char buf[200]; + snprintf(buf, sizeof(buf), "Terminated with exception: \"%s\"", e.what()); + report_failure(buf, __FILE__, __LINE__); } catch (...) { - std::cerr << "Terminated with unknown exception\n"; - tests_failure = true; + report_failure("Terminated with unknown exception", __FILE__, __LINE__); } #endif @@ -158,21 +158,11 @@ int main() fflush(stdout); fflush(stderr); - if (tests_failure == 0) - { - remove_all(test_dir, ec); - if (ec) - fprintf(stderr, "failed to remove test dir: %s\n", ec.message().c_str()); - } - 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; + + remove_all(test_dir, ec); + if (ec) + fprintf(stderr, "failed to remove test dir: %s\n", ec.message().c_str()); + + return print_failures(); } diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index 5188d312d..a3f065dd0 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -66,8 +66,8 @@ POSSIBILITY OF SUCH DAMAGE. using namespace libtorrent; -int tests_failure = 0; -std::vector failure_strings; +static int tests_failure = 0; +static std::vector failure_strings; void report_failure(char const* err, char const* file, int line) { @@ -78,6 +78,17 @@ void report_failure(char const* err, char const* file, int line) ++tests_failure; } +int print_failures() +{ + 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; +} + std::auto_ptr wait_for_alert(session& ses, int type) { std::auto_ptr ret; diff --git a/test/setup_transfer.hpp b/test/setup_transfer.hpp index 1f58d66c2..2d891dc1e 100644 --- a/test/setup_transfer.hpp +++ b/test/setup_transfer.hpp @@ -44,8 +44,7 @@ namespace libtorrent struct session_status; } -extern EXPORT int tests_failure; -extern EXPORT std::vector failure_strings; +int EXPORT print_failures(); int EXPORT load_file(std::string const& filename, std::vector& v, libtorrent::error_code& ec, int limit = 8000000);