Skip to content

Conversation

@tobiasleibner
Copy link
Contributor

Problem:
Currently, when the test output is printed, it only uses the test name, but not the test type. For the BDD test example from the README (modified to make it fail: https://godbolt.org/z/1T6bnzcez):

int main() {
  using namespace boost::ut;
  using namespace boost::ut::bdd;

  "vector"_test = [] {
    given("I have a vector") = [] {
      std::vector<int> v(5);
      expect((5_ul == std::size(v)) >> fatal);

      when("I resize bigger") = [=] {
        mut(v).resize(10);

        then("The size should increase") = [=] {
          expect(9_ul == std::size(v));
        };
      };
    };
  };
}

the output looks like this:

Running test "vector"... 
  Running test "I have a vector"... 
    Running test "I resize bigger"... 
      Running test "The size should increase"... FAILED
in: /app/example.cpp:17 - test condition:  [9 == 10]

Not that though we used given, when, then, the output always is the same ("Running test 'test name'") and does not reflect the BDD test structure.

Solution:
Include the test type in the test output. With this PR, the output becomes

Running test "vector"... 
  Running given "I have a vector"... 
    Running when "I resize bigger"... 
      Running then "The size should increase"... FAILED

This PR is based on #656 (to include the CI fixes from that PR), the only actual change in this PR is 41013d8.

Without this change, there are lots of warnings about tests that have
already been registered. Also, counting the number of asserts does not
seem to work properly, see boost-ext#581.
@tobiasleibner tobiasleibner force-pushed the improve_bdd_test_output branch 2 times, most recently from c6b41f8 to 431ded5 Compare January 31, 2025 15:00
@tobiasleibner tobiasleibner force-pushed the improve_bdd_test_output branch from 431ded5 to 34da4a5 Compare February 3, 2025 10:15
@kris-jusiak kris-jusiak merged commit 7151a32 into boost-ext:master Feb 3, 2025
12 checks passed
@tobiasleibner tobiasleibner deleted the improve_bdd_test_output branch February 4, 2025 08:56
This was referenced Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants