Skip to content

Commit b734ef9

Browse files
committed
Use rename annotation for the output
1 parent b46a8c7 commit b734ef9

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

include/rsl/testing/_testing_impl/expand.hpp

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ struct TestRunner {
4343
}
4444
}
4545

46+
template <typename... Ts>
47+
static std::string apply_args_to_name(std::string name, std::tuple<Ts...> args) {
48+
name += std::apply(
49+
[](auto&&... args) {
50+
std::string result = "(";
51+
std::size_t i = 0;
52+
((result += (i++ ? ", " : "") + repr(args)), ...);
53+
result += ")";
54+
return result;
55+
},
56+
args);
57+
return name;
58+
}
59+
4660
template <typename... Ts>
4761
static std::string get_name(std::tuple<Ts...> args) {
4862
std::string name;
@@ -59,21 +73,21 @@ struct TestRunner {
5973
if constexpr (has_template_arguments(Target)) {
6074
name += rsl::serializer::stringify_template_args(Target);
6175
}
62-
name += std::apply(
63-
[](auto&&... args) {
64-
std::string result = "(";
65-
std::size_t i = 0;
66-
((result += (i++ ? ", " : "") + repr(args)), ...);
67-
result += ")";
68-
return result;
69-
},
70-
args);
71-
return name;
76+
77+
return apply_args_to_name(name, args);
7278
}
7379

7480
template <typename... Ts>
7581
static TC bind(Test const* group, std::tuple<Ts...> args) {
76-
return {group, std::bind_front(run_one<std::tuple<Ts...>>, args), get_name(args)};
82+
constexpr auto ann = _testing_impl::Annotations(Def);
83+
if constexpr (!ann.name.empty()) {
84+
constexpr auto name = ann.name;
85+
return {group,
86+
std::bind_front(run_one<std::tuple<Ts...>>, args),
87+
apply_args_to_name(std::string(name), args)};
88+
} else {
89+
return {group, std::bind_front(run_one<std::tuple<Ts...>>, args), get_name(args)};
90+
}
7791
}
7892
};
7993

@@ -152,4 +166,4 @@ struct Expand {
152166
}
153167
}
154168
};
155-
} // namespace rsl::testing::_testing_impl
169+
} // namespace rsl::testing::_testing_impl

include/rsl/testing/annotations.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,4 @@ struct Annotations { // consteval-only
149149
}
150150
};
151151
} // namespace rsl::testing::_testing_impl
152-
}
152+
}

0 commit comments

Comments
 (0)