Skip to content

Commit 4dd9144

Browse files
authored
Merge pull request #218 from snitch-org/empty-name
Fix #216
2 parents e865d5d + 9e55f7d commit 4dd9144

3 files changed

Lines changed: 34 additions & 14 deletions

File tree

include/snitch/snitch_registry.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct fixture_name_and_tags {
5353
std::string_view tags = {};
5454
};
5555

56-
SNITCH_EXPORT std::string_view
56+
SNITCH_EXPORT bool
5757
make_full_name(small_string<max_test_name_length>& buffer, const test_id& id) noexcept;
5858

5959
template<typename T, typename F>

src/snitch_registry.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,20 +140,14 @@ make_capture_buffer(const capture_state& captures) noexcept {
140140
}
141141
} // namespace
142142

143-
std::string_view
144-
make_full_name(small_string<max_test_name_length>& buffer, const test_id& id) noexcept {
143+
bool make_full_name(small_string<max_test_name_length>& buffer, const test_id& id) noexcept {
145144
buffer.clear();
145+
146146
if (id.type.length() != 0) {
147-
if (!append(buffer, id.name, " <", id.type, ">")) {
148-
return {};
149-
}
147+
return append(buffer, id.name, " <", id.type, ">");
150148
} else {
151-
if (!append(buffer, id.name)) {
152-
return {};
153-
}
149+
return append(buffer, id.name);
154150
}
155-
156-
return buffer.str();
157151
}
158152
} // namespace snitch::impl
159153

@@ -363,7 +357,7 @@ registry::add_impl(const test_id& id, const source_location& location, impl::tes
363357
test_list.push_back(impl::test_case{id, location, func});
364358

365359
small_string<max_test_name_length> buffer;
366-
if (impl::make_full_name(buffer, test_list.back().id).empty()) {
360+
if (!impl::make_full_name(buffer, test_list.back().id)) {
367361
using namespace snitch::impl;
368362
print(
369363
make_colored("error:", with_color, color::fail),
@@ -849,8 +843,9 @@ bool run_tests_impl(registry& r, const cli::input& args) noexcept {
849843

850844
// Evaluate each filter (provided as separate command-line argument).
851845
for (const auto& filter : filter_strings) {
852-
const filter_result sub_result =
853-
is_filter_match_id(impl::make_full_name(buffer, id), id.tags, filter);
846+
impl::make_full_name(buffer, id);
847+
848+
const filter_result sub_result = is_filter_match_id(buffer.str(), id.tags, filter);
854849

855850
if (!result.has_value()) {
856851
// The first filter initialises the result.

tests/runtime_tests/registry.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,31 @@ TEST_CASE("add regular test no tags", "[registry]") {
7171
CHECK_EVENT_TEST_ID(framework.events[1], test.id);
7272
}
7373

74+
TEST_CASE("add regular test no name", "[registry]") {
75+
mock_framework framework;
76+
77+
test_called = false;
78+
framework.registry.add({""}, SNITCH_CURRENT_LOCATION, []() { test_called = true; });
79+
80+
REQUIRE(framework.get_num_registered_tests() == 1u);
81+
82+
auto& test = framework.registry.test_cases()[0];
83+
CHECK(test.id.name == ""sv);
84+
CHECK(test.id.tags == ""sv);
85+
CHECK(test.id.type == ""sv);
86+
REQUIRE(test.func != nullptr);
87+
88+
framework.setup_reporter();
89+
framework.registry.run(test);
90+
91+
CHECK(test_called == true);
92+
REQUIRE(framework.events.size() == 2u);
93+
CHECK(framework.is_event<owning_event::test_case_started>(0u));
94+
CHECK(framework.is_event<owning_event::test_case_ended>(1u));
95+
CHECK_EVENT_TEST_ID(framework.events[0], test.id);
96+
CHECK_EVENT_TEST_ID(framework.events[1], test.id);
97+
}
98+
7499
TEST_CASE("add template test", "[registry]") {
75100
for (bool with_type_list : {false, true}) {
76101
mock_framework framework;

0 commit comments

Comments
 (0)