diff options
author | Manoj Srivastava <srivasta@debian.org> | 2016-01-27 13:11:31 -0800 |
---|---|---|
committer | Manoj Srivastava <srivasta@debian.org> | 2016-01-27 13:11:31 -0800 |
commit | 02819db3483514d49df7ec3f7e372b5aeb831466 (patch) | |
tree | 6a86adac74beac293bc688dafcfa1709a6476901 /vendor/bandit/bandit/reporters/spec_reporter.h | |
parent | 2a61dffe127e22c1aaf955db6f085ac2eefbebba (diff) | |
parent | 6f6de67c70fd98815088ce49f046f48f88ea35bd (diff) |
Merge branch 'upstream'
Signed-off-by: Manoj Srivastava <srivasta@debian.org>
# Conflicts:
# src/CMakeLists.txt
# src/config.h
# src/lua/llimits.h
Diffstat (limited to 'vendor/bandit/bandit/reporters/spec_reporter.h')
-rw-r--r-- | vendor/bandit/bandit/reporters/spec_reporter.h | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/vendor/bandit/bandit/reporters/spec_reporter.h b/vendor/bandit/bandit/reporters/spec_reporter.h new file mode 100644 index 00000000..6d63bfb0 --- /dev/null +++ b/vendor/bandit/bandit/reporters/spec_reporter.h @@ -0,0 +1,126 @@ +#ifndef BANDIT_SPEC_REPORTER_H +#define BANDIT_SPEC_REPORTER_H + +namespace bandit { namespace detail { + + struct spec_reporter : public progress_reporter + { + spec_reporter(std::ostream& stm, const failure_formatter& failure_formatter, + const detail::colorizer& colorizer) + : progress_reporter(failure_formatter), stm_(stm), colorizer_(colorizer), indentation_(0) + {} + + spec_reporter(const failure_formatter& failure_formatter, const detail::colorizer& colorizer) + : progress_reporter(failure_formatter), stm_(std::cout), colorizer_(colorizer), indentation_(0) + {} + + spec_reporter& operator=(const spec_reporter&) { return *this; } + + void test_run_complete() + { + progress_reporter::test_run_complete(); + + stm_ << std::endl; + + test_run_summary summary(specs_run_, specs_failed_, specs_succeeded_, specs_skipped_, failures_, + test_run_errors_, colorizer_); + summary.write(stm_); + stm_.flush(); + } + + void test_run_error(const char* desc, const struct test_run_error& err) + { + progress_reporter::test_run_error(desc, err); + + std::stringstream ss; + ss << std::endl; + ss << "Failed to run \"" << current_context_name() << "\": error \"" << err.what() << "\"" << std::endl; + + test_run_errors_.push_back(ss.str()); + } + + virtual void context_starting(const char* desc) + { + progress_reporter::context_starting(desc); + + stm_ << indent(); + stm_ << "describe " << desc << std::endl; + increase_indent(); + stm_.flush(); + + } + + virtual void context_ended(const char* desc) + { + progress_reporter::context_ended(desc); + decrease_indent(); + } + + virtual void it_starting(const char* desc) + { + progress_reporter::it_starting(desc); + stm_ << indent() << "- it " << desc << " ... "; + stm_.flush(); + } + + virtual void it_succeeded(const char* desc) + { + progress_reporter::it_succeeded(desc); + stm_ << colorizer_.green(); + stm_ << "OK"; + stm_ << colorizer_.reset(); + stm_ << std::endl; + stm_.flush(); + } + + virtual void it_failed(const char* desc, const assertion_exception& ex) + { + progress_reporter::it_failed(desc, ex); + stm_ << colorizer_.red(); + stm_ << "FAILED"; + stm_ << colorizer_.reset(); + stm_ << std::endl; + stm_.flush(); + } + + virtual void it_unknown_error(const char* desc) + { + progress_reporter::it_unknown_error(desc); + stm_ << colorizer_.red(); + stm_ << "ERROR"; + stm_ << colorizer_.reset(); + stm_ << std::endl; + stm_.flush(); + } + + virtual void it_skip(const char* desc) + { + progress_reporter::it_skip(desc); + stm_ << indent() << "- it " << desc << " ... SKIPPED" << std::endl; + stm_.flush(); + } + + private: + void increase_indent() + { + indentation_++; + } + + void decrease_indent() + { + indentation_--; + } + + std::string indent() + { + return std::string(indentation_, '\t'); + } + + private: + std::ostream& stm_; + const detail::colorizer& colorizer_; + int indentation_; + }; +}} + +#endif |