catchorg / Catch2

A modern, C++-native, test framework for unit-tests, TDD and BDD - using C++14, C++17 and later (C++11 support is in v2.x branch, and C++03 on the Catch1.x branch)
https://discord.gg/4CWS9zD
Boost Software License 1.0
18.69k stars 3.05k forks source link

Running a specific BDD-style section does not work #1708

Closed mimon closed 5 years ago

mimon commented 5 years ago

Describe the bug Given the following example:

SCENARIO("pizza") {
  GIVEN("dough") {
    WHEN("applying") {
      THEN("cheese") {
        CHECK(false);
      }
    }
  }
}

Then running a specific section name $ test *pizza* -c "dough" does not run any assertions on my machine (when it should):

Filters: *pizza*
===============================================================================
test cases: 1 | 1 passed
assertions: - none -

Expected behavior The assertion should be executed and output something like:

Filters: *pizza*

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tests is a Catch v2.9.1 host application.
Run with -? for options

-------------------------------------------------------------------------------
Scenario: pizza
      Given: dough
       When: applying
       Then: cheese
-------------------------------------------------------------------------------
test.cpp:6
...............................................................................

test.cpp:7: FAILED:
  CHECK( false )

===============================================================================
test cases: 1 | 1 failed
assertions: 1 | 1 failed

Platform information:

horenmar commented 5 years ago

The problem here is that due to an implementation detail, the spaces before "given" are part of the section name when you need to filter. This is already being worked upon in the FilterWS branch, for now you can work around it by providing the name like this:

$ ./a.out *pizza* -c "    Given: dough"
Filters: *pizza*

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.out is a Catch v2.9.1 host application.
Run with -? for options

-------------------------------------------------------------------------------
Scenario: pizza
      Given: dough
       When: applying
       Then: cheese
-------------------------------------------------------------------------------
1708.cpp:7
...............................................................................

1708.cpp:8: FAILED:
  CHECK( false )

===============================================================================
test cases: 1 | 1 failed
assertions: 1 | 1 failed
mimon commented 5 years ago

Okey. Got it. It works when adding the spaces and the prefix. Thanks.

horenmar commented 5 years ago

I'll keep this open until we merge the fix into master.