Skip to content

Commit cc5504b

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

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

include/rsl/testing/_testing_impl/expand.hpp

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

46+
47+
template <typename... Ts>
48+
static std::string apply_args_to_name(std::string name, std::tuple<Ts...> args) {
49+
name += std::apply(
50+
[](auto&&... args) {
51+
std::string result = "(";
52+
std::size_t i = 0;
53+
((result += (i++ ? ", " : "") + repr(args)), ...);
54+
result += ")";
55+
return result;
56+
},
57+
args);
58+
return name;
59+
}
60+
4661
template <typename... Ts>
4762
static std::string get_name(std::tuple<Ts...> args) {
4863
std::string name;
@@ -59,21 +74,22 @@ struct TestRunner {
5974
if constexpr (has_template_arguments(Target)) {
6075
name += rsl::serializer::stringify_template_args(Target);
6176
}
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;
77+
78+
return apply_args_to_name(name, args);
7279
}
7380

7481
template <typename... Ts>
7582
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)};
83+
constexpr auto ann = _testing_impl::Annotations(Def);
84+
if constexpr (ann.name.empty()) // TODO fix this, for some reason it is reversed, check should be !ann.name.empty()
85+
{
86+
constexpr auto name = ann.name;
87+
return {group, std::bind_front(run_one<std::tuple<Ts...>>, args), apply_args_to_name(std::string(name), args)};
88+
}
89+
else
90+
{
91+
return {group, std::bind_front(run_one<std::tuple<Ts...>>, args), get_name(args)};
92+
}
7793
}
7894
};
7995

@@ -152,4 +168,4 @@ struct Expand {
152168
}
153169
}
154170
};
155-
} // namespace rsl::testing::_testing_impl
171+
} // namespace rsl::testing::_testing_impl

include/rsl/testing/annotations.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ struct Annotations { // consteval-only
133133
// constexpr_assert(skip == nullptr, "Cannot have more than one skip annotation.");
134134
skip = extract<annotations::Skip>(constant_of(annotation)).value;
135135
} else if (type == ^^annotations::Rename) {
136-
constexpr_assert(name.empty(), "Cannot rename more than once.");
136+
constexpr_assert(!name.empty(), "Cannot rename more than once.");
137137
name = extract<annotations::Rename>(constant_of(annotation)).value;
138138
} else if (type == ^^annotations::FuzzTag) {
139139
is_fuzz_test = true;
@@ -149,4 +149,4 @@ struct Annotations { // consteval-only
149149
}
150150
};
151151
} // namespace rsl::testing::_testing_impl
152-
}
152+
}

0 commit comments

Comments
 (0)