| 1 | #ifndef BANDIT_TEST_RUN_SUMMARY_H |
| 2 | #define BANDIT_TEST_RUN_SUMMARY_H |
| 3 | |
| 4 | #include <algorithm> |
| 5 | #include <list> |
| 6 | #include <iostream> |
| 7 | #include <bandit/reporters/colorizer.h> |
| 8 | |
| 9 | namespace bandit { |
| 10 | namespace detail { |
| 11 | struct test_run_summary { |
| 12 | test_run_summary(int specs_run, int specs_failed, int specs_succeeded, int specs_skipped, |
| 13 | const std::list<std::string>& failures, const std::list<std::string>& test_run_errors, |
| 14 | const detail::colorizer& colorizer) |
| 15 | : specs_run_(specs_run), specs_succeeded_(specs_succeeded), specs_failed_(specs_failed), |
| 16 | specs_skipped_(specs_skipped), failures_(failures), test_run_errors_(test_run_errors), |
| 17 | colorizer_(colorizer) {} |
| 18 | |
| 19 | test_run_summary& operator=(const test_run_summary&) { |
| 20 | return *this; |
| 21 | } |
| 22 | |
| 23 | void write(std::ostream& stm) { |
| 24 | if (specs_run_ == 0 && test_run_errors_.size() == 0) { |
| 25 | stm << colorizer_.red(); |
| 26 | stm << "Could not find any tests." ; |
| 27 | stm << colorizer_.reset(); |
| 28 | stm << std::endl; |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | if (specs_failed_ == 0 && test_run_errors_.size() == 0) { |
| 33 | stm << colorizer_.green(); |
| 34 | stm << "Success!" ; |
| 35 | stm << colorizer_.reset(); |
| 36 | stm << std::endl; |
| 37 | } |
| 38 | |
| 39 | if (test_run_errors_.size() > 0) { |
| 40 | for (const auto& error : test_run_errors_) { |
| 41 | stm << error << std::endl; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | if (specs_failed_ > 0) { |
| 46 | stm << colorizer_.red(); |
| 47 | stm << "There were failures!" ; |
| 48 | stm << colorizer_.reset() << std::endl; |
| 49 | for (const auto& failure : failures_) { |
| 50 | stm << failure << std::endl; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | stm << "Test run complete. " << specs_run_ << " tests run. " << specs_succeeded_ << " succeeded." ; |
| 55 | |
| 56 | if (specs_skipped_ > 0) { |
| 57 | stm << " " << specs_skipped_ << " skipped." ; |
| 58 | } |
| 59 | |
| 60 | if (specs_failed_ > 0) { |
| 61 | stm << " " << specs_failed_ << " failed." ; |
| 62 | } |
| 63 | |
| 64 | if (test_run_errors_.size() > 0) { |
| 65 | stm << " " << test_run_errors_.size() << " test run errors." ; |
| 66 | } |
| 67 | |
| 68 | stm << std::endl; |
| 69 | } |
| 70 | |
| 71 | private: |
| 72 | int specs_run_; |
| 73 | int specs_succeeded_; |
| 74 | int specs_failed_; |
| 75 | int specs_skipped_; |
| 76 | std::list<std::string> failures_; |
| 77 | std::list<std::string> test_run_errors_; |
| 78 | const detail::colorizer& colorizer_; |
| 79 | }; |
| 80 | } |
| 81 | } |
| 82 | #endif |
| 83 | |