Skip to content

Commit

Permalink
minimal emulation of Catch2 test listing
Browse files Browse the repository at this point in the history
This is the minimal emulation of the list-tests command line option that
CLion needs to discover and list tests. CLion calls the test binary with
the command line `--list-tests --order lex ~[.]` before running tests.
It doesn't seem to mind that the tests aren't actually ordered, but it
does break it's parsing if:
  - there is no leading "Matching test cases:"
  - tags aren't listed with an indent
  - tests are listed without tags
  • Loading branch information
CrustyAuklet committed May 11, 2024
1 parent 86d18cb commit ade8932
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 45 deletions.
9 changes: 7 additions & 2 deletions src/snitch_reporter_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,19 @@ struct default_reporter_functor {
print_message(r, e.data);
}

void operator()(const snitch::event::list_test_run_started&) const noexcept {}
void operator()(const snitch::event::list_test_run_started&) const noexcept {
r.print("Matching test cases:\n");
}

void operator()(const snitch::event::list_test_run_ended&) const noexcept {}

void operator()(const snitch::event::test_case_listed& e) {
small_string<max_test_name_length> full_name;
make_full_name(full_name, e.id);
r.print(full_name, "\n");
r.print(" ", full_name, "\n");
if (!e.id.tags.empty()) {
r.print(" ", e.id.tags, "\n");
}
}
};
} // namespace
Expand Down
97 changes: 55 additions & 42 deletions tests/approval_tests/data/expected/reporter_console_list_tests
Original file line number Diff line number Diff line change
@@ -1,42 +1,55 @@
test pass
test fail
test mayfail good pass
test mayfail bad pass
test shouldfail good fail
test shouldfail bad pass
test no tags pass
test no tags fail
typed test no tags pass <int>
typed test no tags pass <float>
typed test no tags fail <int>
typed test no tags fail <float>
typed test with tags pass <int>
typed test with tags pass <float>
typed test with tags fail <int>
typed test with tags fail <float>
test fixture pass
test fixture fail
test SUCCEED pass
test FAIL fail
test expression pass
test expression fail
test long expression pass
test long expression fail
test too long expression pass
test too long expression fail
test too long message pass
test too long message fail
test NOTHROW pass
test NOTHROW fail
test THROW pass
test THROW fail
test unexpected throw fail
test unexpected throw in section fail
test unexpected throw in check fail
test unexpected throw in check & section fail
test SKIP
test INFO
test multiple INFO
test SECTION
test multiple SECTION
test SECTION & INFO
Matching test cases:
test pass
[tag2][tag1]
test fail
[tag2][tag1]
test mayfail good pass
[tag2][tag1][!mayfail]
test mayfail bad pass
[tag2][tag1][!mayfail]
test shouldfail good fail
[tag2][tag1][!shouldfail]
test shouldfail bad pass
[tag2][tag1][!shouldfail]
test no tags pass
test no tags fail
typed test no tags pass <int>
typed test no tags pass <float>
typed test no tags fail <int>
typed test no tags fail <float>
typed test with tags pass <int>
[tag1]
typed test with tags pass <float>
[tag1]
typed test with tags fail <int>
[tag1]
typed test with tags fail <float>
[tag1]
test fixture pass
[tag with space]
test fixture fail
[tag with space]
test SUCCEED pass
test FAIL fail
test expression pass
test expression fail
test long expression pass
test long expression fail
test too long expression pass
test too long expression fail
test too long message pass
test too long message fail
test NOTHROW pass
test NOTHROW fail
test THROW pass
test THROW fail
test unexpected throw fail
test unexpected throw in section fail
test unexpected throw in check fail
test unexpected throw in check & section fail
test SKIP
test INFO
test multiple INFO
test SECTION
test multiple SECTION
test SECTION & INFO
5 changes: 4 additions & 1 deletion tests/runtime_tests/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,10 @@ TEST_CASE("list tests", "[registry]") {
CAPTURE(tag);
console.messages.clear();

const auto header = "Matching test cases:\n"sv;

framework.registry.list_tests_with_tag(tag);
CHECK(console.messages == contains_substring(header));
if (tag == "[tag]"sv) {
CHECK(console.messages == contains_substring("how are you"));
CHECK(console.messages == contains_substring("how many lights"));
Expand Down Expand Up @@ -618,7 +621,7 @@ TEST_CASE("list tests", "[registry]") {
CHECK(console.messages == contains_substring("how many templated lights"));
CHECK(console.messages == contains_substring("hidden test 1"));
} else if (tag == "[wrong_tag]"sv || tag == "[.hidden]"sv) {
CHECK(console.messages.empty());
CHECK(console.messages == header);
}
}
}
Expand Down

0 comments on commit ade8932

Please sign in to comment.