Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions include/rsl/testing/_testing_impl/expand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ struct TestRunner {
}
}

template <typename... Ts>
static std::string apply_args_to_name(std::string name, std::tuple<Ts...> args) {
name += std::apply(
[](auto&&... args) {
std::string result = "(";
std::size_t i = 0;
((result += (i++ ? ", " : "") + repr(args)), ...);
result += ")";
return result;
},
args);
return name;
}

template <typename... Ts>
static std::string get_name(std::tuple<Ts...> args) {
std::string name;
Expand All @@ -59,21 +73,21 @@ struct TestRunner {
if constexpr (has_template_arguments(Target)) {
name += rsl::serializer::stringify_template_args(Target);
}
name += std::apply(
[](auto&&... args) {
std::string result = "(";
std::size_t i = 0;
((result += (i++ ? ", " : "") + repr(args)), ...);
result += ")";
return result;
},
args);
return name;

return apply_args_to_name(name, args);
}

template <typename... Ts>
static TC bind(Test const* group, std::tuple<Ts...> args) {
return {group, std::bind_front(run_one<std::tuple<Ts...>>, args), get_name(args)};
constexpr auto ann = _testing_impl::Annotations(Def);
if constexpr (!ann.name.empty()) {
constexpr auto name = ann.name;
return {group,
std::bind_front(run_one<std::tuple<Ts...>>, args),
apply_args_to_name(std::string(name), args)};
} else {
return {group, std::bind_front(run_one<std::tuple<Ts...>>, args), get_name(args)};
}
}
};

Expand Down Expand Up @@ -152,4 +166,4 @@ struct Expand {
}
}
};
} // namespace rsl::testing::_testing_impl
} // namespace rsl::testing::_testing_impl
2 changes: 1 addition & 1 deletion include/rsl/testing/annotations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@ struct Annotations { // consteval-only
}
};
} // namespace rsl::testing::_testing_impl
}
}
5 changes: 3 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target_sources(rsltest_test PRIVATE
always_passes.cpp
)
always_passes.cpp
discover.cpp
)
35 changes: 35 additions & 0 deletions test/discover.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <rsl/test>
#include <tuple>

namespace test_discovery
{
int called = 0;
[[= rsl::test]]
void test_called()
{
++called;
ASSERT(true);
}

void test_not_called()
{
--called;
ASSERT(false);
}

[[= rsl::test]]
[[= rsl::rename("renamed_test")]]
void ensure_called()
{
ASSERT(called == 1);
}


[[= rsl::test]]
[[=rsl::params({{'a', 10}, {'c', 12}})]]
void test_with_params(char foo, int bar){
ASSERT(bar > 5);
ASSERT(foo != 'x');
};

} // namespace test_discovery