diff --git a/include/rsl/testing/_testing_impl/expand.hpp b/include/rsl/testing/_testing_impl/expand.hpp index 04d788f..93dd88c 100644 --- a/include/rsl/testing/_testing_impl/expand.hpp +++ b/include/rsl/testing/_testing_impl/expand.hpp @@ -43,6 +43,20 @@ struct TestRunner { } } + template + static std::string apply_args_to_name(std::string name, std::tuple 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 static std::string get_name(std::tuple args) { std::string name; @@ -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 static TC bind(Test const* group, std::tuple args) { - return {group, std::bind_front(run_one>, 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>, args), + apply_args_to_name(std::string(name), args)}; + } else { + return {group, std::bind_front(run_one>, args), get_name(args)}; + } } }; @@ -152,4 +166,4 @@ struct Expand { } } }; -} // namespace rsl::testing::_testing_impl \ No newline at end of file +} // namespace rsl::testing::_testing_impl diff --git a/include/rsl/testing/annotations.hpp b/include/rsl/testing/annotations.hpp index da7d808..9ba4d5b 100644 --- a/include/rsl/testing/annotations.hpp +++ b/include/rsl/testing/annotations.hpp @@ -149,4 +149,4 @@ struct Annotations { // consteval-only } }; } // namespace rsl::testing::_testing_impl -} \ No newline at end of file +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index dcc3b97..aa7c866 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,3 +1,4 @@ target_sources(rsltest_test PRIVATE - always_passes.cpp -) \ No newline at end of file + always_passes.cpp + discover.cpp +) diff --git a/test/discover.cpp b/test/discover.cpp new file mode 100644 index 0000000..7a7d0c0 --- /dev/null +++ b/test/discover.cpp @@ -0,0 +1,35 @@ +#include +#include + +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