Skip to content

Commit

Permalink
Merge pull request #166 from CrustyAuklet/feat/catch2-list-tests
Browse files Browse the repository at this point in the history
Match output of catch2 when listing tests with default reporter
  • Loading branch information
cschreib authored May 12, 2024
2 parents 86d18cb + ade8932 commit fe24bc4
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 fe24bc4

Please sign in to comment.