Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New reporter "info" #28

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion bandit/options.h
Expand Up @@ -83,7 +83,7 @@ namespace bandit { namespace detail {
"Options:" },
{VERSION, 0, "", "version", option::Arg::None, " --version, \tPrint version of bandit"},
{HELP, 0, "", "help", option::Arg::None, " --help, \tPrint usage and exit."},
{REPORTER, 0, "", "reporter", option::Arg::Optional, " --reporter=<reporter>, \tSelect reporter (dots, singleline, xunit, spec)"},
{REPORTER, 0, "", "reporter", option::Arg::Optional, " --reporter=<reporter>, \tSelect reporter (dots, singleline, xunit, info, spec)"},
{NO_COLOR, 0, "", "no-color", option::Arg::None, " --no-color, \tSuppress colors in output"},
{FORMATTER, 0, "", "formatter", option::Arg::Optional, " --formatter=<formatter>, \tSelect formatting of errors (default, vs)"},
{SKIP, 0, "", "skip", option::Arg::Optional, " --skip=<substring>, \tskip all 'describe' and 'it' containing substring"},
Expand Down
42 changes: 42 additions & 0 deletions bandit/reporters/colorizer.h
Expand Up @@ -31,6 +31,24 @@ namespace bandit { namespace detail {
return "";
}

const char* yellow() const
{
if(colors_enabled_)
{
set_console_color(FOREGROUND_YELLOW);
}
return "";
}

const char* blue() const
{
if(colors_enabled_)
{
set_console_color(FOREGROUND_BLUE);
}
return "";
}

const char* red() const
{
if(colors_enabled_)
Expand All @@ -40,6 +58,15 @@ namespace bandit { namespace detail {
return "";
}

const char* white() const
{
if(colors_enabled_)
{
set_console_color(FOREGROUND_WHITE);
}
return "";
}

const char* reset() const
{
if(colors_enabled_)
Expand Down Expand Up @@ -80,11 +107,26 @@ namespace bandit { namespace detail {
return colors_enabled_ ? "\033[1;32m" : "";
}

const char* yellow() const
{
return colors_enabled_ ? "\033[1;33m" : "";
}

const char* blue() const
{
return colors_enabled_ ? "\033[1;34m" : "";
}

const char* red() const
{
return colors_enabled_ ? "\033[1;31m" : "";
}

const char* white() const
{
return colors_enabled_ ? "\033[1;37m" : "";
}

const char* reset() const
{
return colors_enabled_ ? "\033[0m" : "";
Expand Down
149 changes: 149 additions & 0 deletions bandit/reporters/info_reporter.h
@@ -0,0 +1,149 @@
#ifndef BANDIT_INFO_REPORTER_H
#define BANDIT_INFO_REPORTER_H

namespace bandit {
namespace detail {

struct info_reporter : public progress_reporter
{
info_reporter(std::ostream &stm, const failure_formatter &failure_formatter,
const detail::colorizer &colorizer)
: progress_reporter(failure_formatter)
, stm_(stm)
, colorizer_(colorizer)
, indentation_(0)
{}

info_reporter(const failure_formatter &failure_formatter, const detail::colorizer &colorizer)
: progress_reporter(failure_formatter)
, stm_(std::cout)
, colorizer_(colorizer)
, indentation_(0)
{}

info_reporter &operator=(const info_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()
<< colorizer_.blue()
<< "begin "
<< colorizer_.white()
<< desc
<< colorizer_.reset()
<< std::endl;
++indentation_;
stm_.flush();

}

virtual void context_ended(const char *desc)
{
progress_reporter::context_ended(desc);
--indentation_;
stm_
<< indent()
<< colorizer_.blue()
<< "end "
<< colorizer_.reset()
<< desc << std::endl;
}

virtual void it_starting(const char *desc)
{
progress_reporter::it_starting(desc);
stm_
<< indent()
<< colorizer_.yellow()
<< "[ TEST ]"
<< colorizer_.reset()
<< " it " << desc;
++indentation_;
stm_.flush();
}

virtual void it_succeeded(const char *desc)
{
progress_reporter::it_succeeded(desc);
--indentation_;
stm_
<< "\r" << indent()
<< colorizer_.green()
<< "[ PASS ]"
<< colorizer_.reset()
<< " it " << desc
<< std::endl;
stm_.flush();
}

virtual void it_failed(const char *desc, const assertion_exception &ex)
{
progress_reporter::it_failed(desc, ex);
--indentation_;
stm_
<< "\r" << indent()
<< colorizer_.red()
<< "[ FAIL ]"
<< colorizer_.reset()
<< " it " << desc
<< std::endl;
stm_.flush();
}

virtual void it_unknown_error(const char *desc)
{
progress_reporter::it_unknown_error(desc);
--indentation_;
stm_
<< "\r" << indent()
<< colorizer_.red()
<< "-ERROR->"
<< colorizer_.reset()
<< " it " << desc
<< std::endl;
stm_.flush();
}

private:
std::string indent()
{
return std::string(2*indentation_, ' ');
}

std::ostream &stm_;
const detail::colorizer &colorizer_;
int indentation_;
};
}
}

#endif
1 change: 1 addition & 0 deletions bandit/reporters/reporters.h
Expand Up @@ -7,6 +7,7 @@
#include <bandit/reporters/dots_reporter.h>
#include <bandit/reporters/single_line_reporter.h>
#include <bandit/reporters/xunit_reporter.h>
#include <bandit/reporters/info_reporter.h>
#include <bandit/reporters/spec_reporter.h>

namespace bandit { namespace detail {
Expand Down
5 changes: 5 additions & 0 deletions bandit/runner.h
Expand Up @@ -25,6 +25,11 @@ namespace bandit {
return std::unique_ptr<detail::listener>(new xunit_reporter(*formatter));
}

if(name == "info")
{
return std::unique_ptr<detail::listener>(new info_reporter(*formatter, colorizer));
}

if(name == "spec")
{
return std::unique_ptr<detail::listener>(new spec_reporter(*formatter, colorizer));
Expand Down