From ade8932d9e12a3f1159eaf1935be93813a2457a7 Mon Sep 17 00:00:00 2001 From: Ethan Slattery Date: Sat, 27 Apr 2024 14:42:07 -0700 Subject: [PATCH] minimal emulation of Catch2 test listing 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 --- src/snitch_reporter_console.cpp | 9 +- .../data/expected/reporter_console_list_tests | 97 +++++++++++-------- tests/runtime_tests/registry.cpp | 5 +- 3 files changed, 66 insertions(+), 45 deletions(-) diff --git a/src/snitch_reporter_console.cpp b/src/snitch_reporter_console.cpp index 16ac72e7..af7331ae 100644 --- a/src/snitch_reporter_console.cpp +++ b/src/snitch_reporter_console.cpp @@ -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 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 diff --git a/tests/approval_tests/data/expected/reporter_console_list_tests b/tests/approval_tests/data/expected/reporter_console_list_tests index 3c7bb95e..eca1867a 100644 --- a/tests/approval_tests/data/expected/reporter_console_list_tests +++ b/tests/approval_tests/data/expected/reporter_console_list_tests @@ -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 -typed test no tags pass -typed test no tags fail -typed test no tags fail -typed test with tags pass -typed test with tags pass -typed test with tags fail -typed test with tags fail -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 + typed test no tags pass + typed test no tags fail + typed test no tags fail + typed test with tags pass + [tag1] + typed test with tags pass + [tag1] + typed test with tags fail + [tag1] + typed test with tags fail + [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 diff --git a/tests/runtime_tests/registry.cpp b/tests/runtime_tests/registry.cpp index 895a36b4..9dbaa2e9 100644 --- a/tests/runtime_tests/registry.cpp +++ b/tests/runtime_tests/registry.cpp @@ -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")); @@ -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); } } }