From c24229f5c81847e72a57bced3192c79e05376ba5 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 23 Jun 2015 21:54:24 -0700 Subject: [PATCH] visual tests: still generate error report on ctrl-c --- test/visual/config.hpp | 23 +++++++++++++++++++++++ test/visual/run.cpp | 30 +++++++++++++++++++++--------- test/visual/runner.cpp | 4 ++++ 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/test/visual/config.hpp b/test/visual/config.hpp index 8353d4b2e..90727dd76 100644 --- a/test/visual/config.hpp +++ b/test/visual/config.hpp @@ -26,6 +26,7 @@ // stl #include #include +#include // boost #include @@ -33,6 +34,28 @@ namespace visual_tests { +class early_exit_error : public std::exception +{ +public: + early_exit_error() : + what_() {} + + early_exit_error( std::string const& what ) : + what_( what ) + { + } + + virtual ~early_exit_error() throw() {} + + virtual const char * what() const throw() + { + return what_.c_str(); + } + +protected: + mutable std::string what_; +}; + struct map_size { map_size(int _width, int _height) : width(_width), height(_height) { } diff --git a/test/visual/run.cpp b/test/visual/run.cpp index 1353bcc42..aedc65010 100644 --- a/test/visual/run.cpp +++ b/test/visual/run.cpp @@ -22,6 +22,8 @@ #include "runner.hpp" #include "config.hpp" +#include +#include #include #include @@ -31,6 +33,12 @@ #include "cleanup.hpp" // run_cleanup() +void signal_handler(int /*signal*/) +{ + throw visual_tests::early_exit_error("SIGINT"); +} + + int main(int argc, char** argv) { using namespace visual_tests; @@ -81,6 +89,10 @@ int main(int argc, char** argv) report_type report = vm.count("verbose") ? report_type((console_report())) : report_type((console_short_report())); result_list results; + std::signal(SIGINT,signal_handler); + + unsigned failed_count = 0; + try { if (vm.count("styles")) @@ -91,20 +103,20 @@ int main(int argc, char** argv) { results = run.test_all(report); } + + failed_count = mapnik::util::apply_visitor(summary_visitor(results), report); + + if (failed_count) + { + html_summary(results, output_dir); + } } - catch (std::exception & e) + catch (std::exception const& e) { - std::cerr << "Error runnig tests: " << e.what() << std::endl; + std::cerr << "Error running tests: " << e.what() << std::endl; return 1; } - unsigned failed_count = mapnik::util::apply_visitor(summary_visitor(results), report); - - if (failed_count) - { - html_summary(results, output_dir); - } - testing::run_cleanup(); return failed_count; diff --git a/test/visual/runner.cpp b/test/visual/runner.cpp index f2562c197..2274774ec 100644 --- a/test/visual/runner.cpp +++ b/test/visual/runner.cpp @@ -156,6 +156,10 @@ result_list runner::test_range(files_iterator begin, files_iterator end, std::re result_list r = test_one(file, defaults, report); std::move(r.begin(), r.end(), std::back_inserter(results)); } + catch (visual_tests::early_exit_error const&) + { + break; + } catch (std::exception const& ex) { result r;