Skip to content

Commit 9873e7f

Browse files
committed
🐛 Fix #569 - test.name lifetime with dynamic names
1 parent 788f6b4 commit 9873e7f

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

include/boost/ut.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ struct suite_end {
597597
template <class Test, class TArg = none>
598598
struct test {
599599
std::string_view type{};
600-
std::string_view name{};
600+
std::string name{}; /// might be dynamic
601601
std::vector<std::string_view> tag{};
602602
reflection::source_location location{};
603603
TArg arg{};
@@ -2265,7 +2265,7 @@ struct test {
22652265
template <class... Ts>
22662266
constexpr auto operator=(test_location<void (*)()> _test) {
22672267
on<Ts...>(events::test<void (*)()>{.type = type,
2268-
.name = name,
2268+
.name = std::string{name},
22692269
.tag = tag,
22702270
.location = _test.location,
22712271
.arg = none{},
@@ -2279,7 +2279,7 @@ struct test {
22792279
constexpr auto operator=(Test _test) ->
22802280
typename type_traits::identity<Test, decltype(_test())>::type {
22812281
on<Test>(events::test<Test>{.type = type,
2282-
.name = name,
2282+
.name = std::string{name},
22832283
.tag = tag,
22842284
.location = {},
22852285
.arg = none{},
@@ -2716,7 +2716,7 @@ template <class F, class T,
27162716
for (const auto& arg : t) {
27172717
detail::on<F>(events::test<F, decltype(arg)>{
27182718
.type = "test",
2719-
.name = name,
2719+
.name = std::string{name},
27202720
.tag = {},
27212721
.location = {},
27222722
.arg = arg,
@@ -2733,7 +2733,7 @@ template <
27332733
apply(
27342734
[f, name](const auto&... args) {
27352735
(detail::on<F>(events::test<F, Ts>{.type = "test",
2736-
.name = name,
2736+
.name = std::string{name},
27372737
.tag = {},
27382738
.location = {},
27392739
.arg = args,

test/ut/ut.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ struct fake_cfg {
102102

103103
struct test_call {
104104
std::string_view type{};
105-
std::string_view name{};
105+
std::string name{};
106106
ut::reflection::source_location location{};
107107
std::any arg{};
108108
};
@@ -137,7 +137,7 @@ struct fake_cfg {
137137
template <class... Ts>
138138
auto on(ut::events::skip<Ts...> test) -> void {
139139
skip_calls.push_back(
140-
{.type = test.type, .name = test.name, .arg = test.arg});
140+
{.type = test.type, .name = std::string{test.name}, .arg = test.arg});
141141
}
142142

143143
template <class TExpr>

0 commit comments

Comments
 (0)