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 { ...@@ -113,15 +113,24 @@ struct colorizing_iterator {
out->put(c); out->put(c);
break; break;
case off_read_color: case off_read_color:
out->flush();
switch (c) {
case '0':
mode = verbatim;
return;
default:
mode = off_escape; mode = off_escape;
return;
}
break; break;
case off_escape: case off_escape:
if (c != '(') if (c != '(')
CAF_RAISE_ERROR("expected ( after color code"); CAF_RAISE_ERROR("expected ( after color code");
mode = color; mode = off_color;
break; break;
case off_color: case off_color:
if (c == ')') { if (c == ')') {
out->flush();
mode = off; mode = off;
break; break;
} }
...@@ -171,7 +180,9 @@ public: ...@@ -171,7 +180,9 @@ public:
} }
auto colored() { 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 { void stop() override {
...@@ -381,6 +392,10 @@ public: ...@@ -381,6 +392,10 @@ public:
level_ = level; level_ = level;
} }
void no_colors(bool new_value) override {
no_colors_ = new_value;
}
stats test_stats() override { stats test_stats() override {
return test_stats_; return test_stats_;
} }
...@@ -431,6 +446,9 @@ private: ...@@ -431,6 +446,9 @@ private:
/// Configures the verbosity of the reporter. /// Configures the verbosity of the reporter.
unsigned level_ = CAF_LOG_LEVEL_INFO; unsigned level_ = CAF_LOG_LEVEL_INFO;
/// Configures whether we render text without colors.
bool no_colors_ = false;
/// Stores the names of failed test suites. /// Stores the names of failed test suites.
std::vector<std::string_view> failed_suites_; std::vector<std::string_view> failed_suites_;
......
...@@ -77,6 +77,10 @@ public: ...@@ -77,6 +77,10 @@ public:
virtual void verbosity(unsigned level) = 0; 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. /// Returns statistics for the current test.
virtual stats test_stats() = 0; virtual stats test_stats() = 0;
......
...@@ -142,6 +142,7 @@ int runner::run(int argc, char** argv) { ...@@ -142,6 +142,7 @@ int runner::run(int argc, char** argv) {
if (!suite_regex || !test_regex) { if (!suite_regex || !test_regex) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
default_reporter->no_colors(get_or(cfg_, "no-colors", false));
default_reporter->start(); default_reporter->start();
auto enabled = [](const std::regex& selected, auto enabled = [](const std::regex& selected,
std::string_view search_string) { 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