Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 29 additions & 23 deletions include/boost/ut.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1736,10 +1736,12 @@ class reporter_junit {
}

auto on(events::test_end test_event) -> void {
active_scope_->report_string += ss_out_.str();
if (active_scope_->fails > 0) {
reset_printer();
if (report_type_ == CONSOLE) {
lcout_ << ss_out_.str();
}
} else {
active_scope_->report_string = ss_out_.str();
if (report_type_ == CONSOLE) {
if (detail::cfg::show_successful_tests) {
if (!active_scope_->nested_tests->empty()) {
Expand All @@ -1750,10 +1752,10 @@ class reporter_junit {
ss_out_ << color_.pass << "PASSED" << color_.none;
print_duration(ss_out_);
lcout_ << ss_out_.str();
reset_printer();
}
}
}
reset_printer();
active_scope_->n_tests = 1LU;
if (active_scope_->fails > 0 || active_scope_->fail_tests > 0) {
active_scope_->fail_tests = 1LU;
Expand All @@ -1778,7 +1780,7 @@ class reporter_junit {
if (report_type_ == CONSOLE) {
lcout_ << '\n' << std::string((2 * active_test_.size()) - 2, ' ');
lcout_ << "Running \"" << test_event.name << "\"... ";
lcout_ << color_.skip << "SKIPPED" << color_.none << '\n';
lcout_ << color_.skip << "SKIPPED" << color_.none;
}
reset_printer();
pop_scope(test_event.name);
Expand All @@ -1788,9 +1790,6 @@ class reporter_junit {
template <class TMsg>
auto on(events::log<TMsg> log) -> void {
ss_out_ << log.msg;
if (report_type_ == CONSOLE) {
lcout_ << log.msg;
}
}

auto on(events::exception exception) -> void {
Expand Down Expand Up @@ -1828,23 +1827,27 @@ class reporter_junit {
TPrinter ss{};
ss << ss_out_.str();
if (report_type_ == CONSOLE) {
ss << color_.fail << "FAILED\n" << color_.none;
ss << "\n";
if (active_test_.size()) {
ss << std::string((2 * active_test_.size()) - 2, ' ');
}
ss << color_.fail << "FAILED " << color_.none;
print_duration(ss);
}
ss << "in: " << assertion.location.file_name() << ':'
<< assertion.location.line();
ss << color_.fail << " - test condition: ";
ss << " [" << std::boolalpha << assertion.expr;
ss << '[' << std::boolalpha << assertion.expr;
ss << color_.fail << ']' << color_.none;
active_scope_->report_string += ss.str();
active_scope_->fails++;
active_scope_->assertions++;
reset_printer();
if (report_type_ == CONSOLE) {
lcout_ << active_scope_->report_string << "\n\n";
lcout_ << ss.str();
}
if (detail::cfg::abort_early ||
active_scope_->fails >= detail::cfg::abort_after_n_failures) {
active_scope_->fails >= detail::cfg::abort_after_n_failures) {
std::cerr << "early abort for test : " << active_test_.top() << "after ";
std::cerr << active_scope_->fails << " failures total." << std::endl;
std::exit(-1);
Expand All @@ -1866,6 +1869,7 @@ class reporter_junit {
: std::cout);
return;
}
lcout_ << ss_out_.str();
print_console_summary(
detail::cfg::output_filename != "" ? maybe_of : std::cout,
detail::cfg::output_filename != "" ? maybe_of : std::cerr);
Expand All @@ -1886,30 +1890,29 @@ class reporter_junit {

void print_console_summary(std::ostream& out_stream,
std::ostream& err_stream) {

for (const auto& [suite_name, suite_result] : results_) {
if (suite_result.fails) {
err_stream
<< "\n========================================================"
"=======================\n"
<< "Suite " << suite_name << '\n' //
<< "Suite " << suite_name << '\n'
<< "tests: " << (suite_result.n_tests) << " | "
<< (suite_result.fail_tests > 0 ? color_.fail : color_.none)
<< suite_result.fail_tests << " failed" << color_.none << '\n'
<< "asserts: " << (suite_result.assertions) << " | "
<< suite_result.passed << " passed"
<< " | " << color_.fail << suite_result.fails << " failed"
<< color_.none << '\n';
std::cerr << std::endl;
} else {
out_stream << color_.pass << "Suite '" << suite_name
<< color_.none;
//std::cerr << std::endl;
} else if (suite_result.assertions || suite_result.n_tests || suite_result.skipped) {
out_stream << color_.pass << "\nSuite '" << suite_name
<< "': all tests passed" << color_.none << " ("
<< suite_result.assertions << " asserts in "
<< suite_result.n_tests << " tests)\n";

<< suite_result.n_tests << " tests)";
if (suite_result.skipped) {
std::cout << suite_result.skipped << " tests skipped\n";
std::cout << "; " << suite_result.skipped << " tests skipped";
}

std::cout.flush();
}
}
Expand Down Expand Up @@ -2029,21 +2032,24 @@ class runner {
};

public:
constexpr runner() = default;
constexpr runner() {
std::cout << "UT starts ========================================================"
"=============";
};
constexpr runner(TReporter reporter, std::size_t suites_size)
: reporter_{std::move(reporter)}, suites_(suites_size) {}

~runner() {
const auto should_run = not run_;

if (should_run) {
static_cast<void>(run());
}

if (not dry_run_) {
report_summary();
}

std::cout << "\nCompleted =============================================="
"=======================\n";
if (should_run and fails_) {
std::exit(-1);
}
Expand Down
Loading