Skip to content
Merged
Show file tree
Hide file tree
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
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ expect(1_i == 2); // not executed
```
main.cpp:6:FAILED [1 == 2]
===============================================================================
tests: 1 | 1 failed
asserts: 2 | 0 passed | 2 failed
tests: 0 | 0 failed
asserts: 1 | 0 passed | 1 failed
```

> https://godbolt.org/z/WMe8Y1
Expand Down Expand Up @@ -364,8 +364,8 @@ in: main.cpp:6 - test condition: [1 == 2]

fatal assertion
===============================================================================
tests: 0 | 2 failed
asserts: 0 | 0 passed | 2 failed
tests: 0 | 0 failed
asserts: 1 | 0 passed | 1 failed
```

> I use `std::expected`, can I stream its `error()` upon failure?
Expand All @@ -387,8 +387,8 @@ in: main.cpp:12 - test condition: [false]

lazy evaluated
===============================================================================
tests: 1 | 2 failed
asserts: 0 | 0 passed | 2 failed
tests: 1 | 1 failed
asserts: 1 | 0 passed | 1 failed
```

> https://godbolt.org/z/v2PDuU
Expand Down Expand Up @@ -463,7 +463,7 @@ int main() {
v.resize(0);
expect(0_ul == std::size(v));
};
}
};
}
```

Expand Down Expand Up @@ -1041,9 +1041,9 @@ All tests passed (2 asserts in 2 tests)

```cpp
"logging"_test = [] {
log << "pre";
boost::ut::log << "pre";
expect(42_i == 43) << "message on failure";
log << "post";
boost::ut::log << "post";
};
```

Expand Down Expand Up @@ -1071,9 +1071,9 @@ This requires using C++20 with a standard library with std::format support.

```cpp
"logging"_test = [] {
log("\npre {} == {}\n", 42, 43);
boost::ut::log("\npre {} == {}\n", 42, 43);
expect(42_i == 43) << "message on failure";
log("\npost {} == {} -> {}\n", 42, 43, 42 == 43);
boost::ut::log("\npost {} == {} -> {}\n", 42, 43, 42 == 43);
};
```

Expand Down
22 changes: 13 additions & 9 deletions include/boost/ut.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,7 @@ class reporter_junit {
timePoint run_start = clock_ref::now();
timePoint run_stop = clock_ref::now();
std::size_t n_tests = 0LU;
std::size_t fail_tests = 0LU;
std::size_t assertions = 0LU;
std::size_t passed = 0LU;
std::size_t skipped = 0LU;
Expand Down Expand Up @@ -1652,9 +1653,6 @@ class reporter_junit {
} else {
active_scope_->status = active_scope_->fails > 0 ? "FAILED" : "PASSED";
}
active_scope_->assertions =
active_scope_->assertions + active_scope_->fails;

if (active_test_.top() == test_name) {
active_test_.pop();
auto old_scope = active_scope_;
Expand All @@ -1663,7 +1661,8 @@ class reporter_junit {
} else {
active_scope_ = &results_[std::string{"global"}];
}
active_scope_->n_tests += old_scope->n_tests + 1LU;
active_scope_->n_tests += old_scope->n_tests;
active_scope_->fail_tests += old_scope->fail_tests;
active_scope_->assertions += old_scope->assertions;
active_scope_->passed += old_scope->passed;
active_scope_->skipped += old_scope->skipped;
Expand Down Expand Up @@ -1741,7 +1740,6 @@ class reporter_junit {
reset_printer();
} else {
active_scope_->report_string = ss_out_.str();
active_scope_->passed += 1LU;
if (report_type_ == CONSOLE) {
if (detail::cfg::show_successful_tests) {
if (!active_scope_->nested_tests->empty()) {
Expand All @@ -1756,7 +1754,10 @@ class reporter_junit {
}
}
}

active_scope_->n_tests = 1LU;
if (active_scope_->fails > 0 || active_scope_->fail_tests > 0) {
active_scope_->fail_tests = 1LU;
}
pop_scope(test_event.name);
}

Expand Down Expand Up @@ -1819,6 +1820,7 @@ class reporter_junit {
template <class TExpr>
auto on(events::assertion_pass<TExpr>) -> void {
active_scope_->assertions++;
active_scope_->passed++;
}

template <class TExpr>
Expand All @@ -1836,6 +1838,7 @@ class reporter_junit {
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";
Expand All @@ -1848,7 +1851,7 @@ class reporter_junit {
}
}

auto on(const events::fatal_assertion&) -> void { active_scope_->fails++; }
auto on(const events::fatal_assertion&) -> void { /*active_scope_->fails++;*/ }

auto on(events::summary) -> void {
std::cout.flush();
Expand Down Expand Up @@ -1889,8 +1892,9 @@ class reporter_junit {
<< "\n========================================================"
"=======================\n"
<< "Suite " << suite_name << '\n' //
<< "tests: " << (suite_result.n_tests) << " | " << color_.fail
<< suite_result.fails << " failed" << color_.none << '\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"
Expand Down
Loading