Unverified Commit dabbb358 authored by Shariar Azad Riday's avatar Shariar Azad Riday Committed by GitHub

Add option to disable colored test output

parent 95b45696
......@@ -113,15 +113,24 @@ struct colorizing_iterator {
out->put(c);
break;
case off_read_color:
out->flush();
switch (c) {
case '0':
mode = verbatim;
return;
default:
mode = off_escape;
return;
}
break;
case off_escape:
if (c != '(')
CAF_RAISE_ERROR("expected ( after color code");
mode = color;
mode = off_color;
break;
case off_color:
if (c == ')') {
out->flush();
mode = off;
break;
}
......@@ -171,7 +180,9 @@ public:
}
auto colored() {
return colorizing_iterator{colorizing_iterator::normal, &std::cout};
auto state = no_colors_ ? colorizing_iterator::off
: colorizing_iterator::normal;
return colorizing_iterator{state, &std::cout};
}
void stop() override {
......@@ -381,6 +392,10 @@ public:
level_ = level;
}
void no_colors(bool new_value) override {
no_colors_ = new_value;
}
stats test_stats() override {
return test_stats_;
}
......@@ -431,6 +446,9 @@ private:
/// Configures the verbosity of the reporter.
unsigned level_ = CAF_LOG_LEVEL_INFO;
/// Configures whether we render text without colors.
bool no_colors_ = false;
/// Stores the names of failed test suites.
std::vector<std::string_view> failed_suites_;
......
......@@ -77,6 +77,10 @@ public:
virtual void verbosity(unsigned level) = 0;
/// Sets whether the reporter disables colored output even when writing to a
/// TTY.
virtual void no_colors(bool new_value) = 0;
/// Returns statistics for the current test.
virtual stats test_stats() = 0;
......
......@@ -142,6 +142,7 @@ int runner::run(int argc, char** argv) {
if (!suite_regex || !test_regex) {
return EXIT_FAILURE;
}
default_reporter->no_colors(get_or(cfg_, "no-colors", false));
default_reporter->start();
auto enabled = [](const std::regex& selected,
std::string_view search_string) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment