removed string_view for string in tests

This commit is contained in:
Jordan Maples [MSFT] 2019-12-12 11:15:41 -08:00
parent 4f6f05d463
commit 5099e8fa3e
10 changed files with 183 additions and 185 deletions

View File

@ -35,11 +35,10 @@
#include <gsl/gsl_algorithm> // for copy #include <gsl/gsl_algorithm> // for copy
#include <gsl/span> // for span #include <gsl/span> // for span
#include <array> // for array #include <array> // for array
#include <string_view>
#include <cstddef> // for size_t #include <cstddef> // for size_t
namespace{ namespace{
constexpr std::string_view deathstring("Expected Death"); static const std::string deathstring("Expected Death");
} }
namespace gsl namespace gsl
@ -234,9 +233,9 @@ TEST(algorithm_tests, small_destination_span)
const span<int> dst_span_dyn(dst); const span<int> dst_span_dyn(dst);
const span<int, 4> dst_span_static(dst); const span<int, 4> dst_span_static(dst);
EXPECT_DEATH(copy(src_span_dyn, dst_span_dyn), deathstring.data()); EXPECT_DEATH(copy(src_span_dyn, dst_span_dyn), deathstring);
EXPECT_DEATH(copy(src_span_dyn, dst_span_static), deathstring.data()); EXPECT_DEATH(copy(src_span_dyn, dst_span_static), deathstring);
EXPECT_DEATH(copy(src_span_static, dst_span_dyn), deathstring.data()); EXPECT_DEATH(copy(src_span_static, dst_span_dyn), deathstring);
#ifdef CONFIRM_COMPILATION_ERRORS #ifdef CONFIRM_COMPILATION_ERRORS
copy(src_span_static, dst_span_static); copy(src_span_static, dst_span_static);

View File

@ -34,7 +34,6 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <gsl/gsl_assert> // for fail_fast (ptr only), Ensures, Expects #include <gsl/gsl_assert> // for fail_fast (ptr only), Ensures, Expects
#include <string_view>
using namespace gsl; using namespace gsl;
namespace namespace
@ -52,7 +51,7 @@ int g(int i)
return i; return i;
} }
constexpr std::string_view deathstring("Expected Death"); static const std::string deathstring("Expected Death");
} // namespace } // namespace
TEST(assertion_tests, expects) TEST(assertion_tests, expects)
@ -63,7 +62,7 @@ TEST(assertion_tests, expects)
}); });
EXPECT_TRUE(f(2) == 2); EXPECT_TRUE(f(2) == 2);
EXPECT_DEATH(f(10), deathstring.data()); EXPECT_DEATH(f(10), deathstring);
} }
@ -75,7 +74,7 @@ TEST(assertion_tests, ensures)
}); });
EXPECT_TRUE(g(2) == 3); EXPECT_TRUE(g(2) == 3);
EXPECT_DEATH(g(9), deathstring.data()); EXPECT_DEATH(g(9), deathstring);
} }
#if __clang__ || __GNUC__ #if __clang__ || __GNUC__

View File

@ -41,7 +41,7 @@
#include <vector> // for vector #include <vector> // for vector
namespace{ namespace{
constexpr std::string_view deathstring("Expected Death"); static const std::string deathstring("Expected Death");
} }
TEST(at_tests, static_array) TEST(at_tests, static_array)
@ -59,10 +59,10 @@ TEST(at_tests, static_array)
std::abort(); std::abort();
}); });
EXPECT_DEATH(gsl::at(a, -1), deathstring.data()); EXPECT_DEATH(gsl::at(a, -1), deathstring);
EXPECT_DEATH(gsl::at(a, 4), deathstring.data()); EXPECT_DEATH(gsl::at(a, 4), deathstring);
EXPECT_DEATH(gsl::at(c_a, -1), deathstring.data()); EXPECT_DEATH(gsl::at(c_a, -1), deathstring);
EXPECT_DEATH(gsl::at(c_a, 4), deathstring.data()); EXPECT_DEATH(gsl::at(c_a, 4), deathstring);
} }
TEST(at_tests, std_array) TEST(at_tests, std_array)
@ -80,10 +80,10 @@ TEST(at_tests, std_array)
std::abort(); std::abort();
}); });
EXPECT_DEATH(gsl::at(a, -1), deathstring.data()); EXPECT_DEATH(gsl::at(a, -1), deathstring);
EXPECT_DEATH(gsl::at(a, 4), deathstring.data()); EXPECT_DEATH(gsl::at(a, 4), deathstring);
EXPECT_DEATH(gsl::at(c_a, -1), deathstring.data()); EXPECT_DEATH(gsl::at(c_a, -1), deathstring);
EXPECT_DEATH(gsl::at(c_a, 4), deathstring.data()); EXPECT_DEATH(gsl::at(c_a, 4), deathstring);
} }
TEST(at_tests, std_vector) TEST(at_tests, std_vector)
@ -101,10 +101,10 @@ TEST(at_tests, std_vector)
std::abort(); std::abort();
}); });
EXPECT_DEATH(gsl::at(a, -1), deathstring.data()); EXPECT_DEATH(gsl::at(a, -1), deathstring);
EXPECT_DEATH(gsl::at(a, 4), deathstring.data()); EXPECT_DEATH(gsl::at(a, 4), deathstring);
EXPECT_DEATH(gsl::at(c_a, -1), deathstring.data()); EXPECT_DEATH(gsl::at(c_a, -1), deathstring);
EXPECT_DEATH(gsl::at(c_a, 4), deathstring.data()); EXPECT_DEATH(gsl::at(c_a, 4), deathstring);
} }
TEST(at_tests, InitializerList) TEST(at_tests, InitializerList)
@ -121,10 +121,10 @@ TEST(at_tests, InitializerList)
std::abort(); std::abort();
}); });
EXPECT_DEATH(gsl::at(a, -1), deathstring.data()); EXPECT_DEATH(gsl::at(a, -1), deathstring);
EXPECT_DEATH(gsl::at(a, 4), deathstring.data()); EXPECT_DEATH(gsl::at(a, 4), deathstring);
EXPECT_DEATH(gsl::at({1, 2, 3, 4}, -1), deathstring.data()); EXPECT_DEATH(gsl::at({1, 2, 3, 4}, -1), deathstring);
EXPECT_DEATH(gsl::at({1, 2, 3, 4}, 4), deathstring.data()); EXPECT_DEATH(gsl::at({1, 2, 3, 4}, 4), deathstring);
} }
#if !defined(_MSC_VER) || defined(__clang__) || _MSC_VER >= 1910 #if !defined(_MSC_VER) || defined(__clang__) || _MSC_VER >= 1910

View File

@ -139,7 +139,7 @@ void fn(const Bounds&)
static_assert(Bounds::static_size == 60, "static bounds is wrong size"); static_assert(Bounds::static_size == 60, "static bounds is wrong size");
} }
constexpr std::string_view deathstring("Expected Death"); static const std::string deathstring("Expected Death");
} // namespace } // namespace
TEST(multi_span_test, default_constructor) TEST(multi_span_test, default_constructor)
@ -262,18 +262,18 @@ TEST(multi_span_test, from_nullptr_length_constructor) {
{ {
auto workaround_macro = []() { const multi_span<int> s{nullptr, 1}; }; auto workaround_macro = []() { const multi_span<int> s{nullptr, 1}; };
EXPECT_DEATH(workaround_macro(), deathstring.data()); EXPECT_DEATH(workaround_macro(), deathstring);
auto const_workaround_macro = []() { const multi_span<const int> cs{nullptr, 1}; }; auto const_workaround_macro = []() { const multi_span<const int> cs{nullptr, 1}; };
EXPECT_DEATH(const_workaround_macro(), deathstring.data()); EXPECT_DEATH(const_workaround_macro(), deathstring);
} }
{ {
auto workaround_macro = []() { const multi_span<int, 0> s{nullptr, 1}; }; auto workaround_macro = []() { const multi_span<int, 0> s{nullptr, 1}; };
EXPECT_DEATH(workaround_macro(), deathstring.data()); EXPECT_DEATH(workaround_macro(), deathstring);
auto const_workaround_macro = []() { const multi_span<const int, 0> s{nullptr, 1}; }; auto const_workaround_macro = []() { const multi_span<const int, 0> s{nullptr, 1}; };
EXPECT_DEATH(const_workaround_macro(), deathstring.data()); EXPECT_DEATH(const_workaround_macro(), deathstring);
} }
{ {
@ -385,7 +385,7 @@ TEST(multi_span_test, from_pointer_length_constructor)
{ {
int* p = nullptr; int* p = nullptr;
auto workaround_macro = [=]() { const multi_span<int> s{p, 2}; }; auto workaround_macro = [=]() { const multi_span<int> s{p, 2}; };
EXPECT_DEATH(workaround_macro(), deathstring.data()); EXPECT_DEATH(workaround_macro(), deathstring);
} }
} }
@ -429,25 +429,25 @@ TEST(multi_span_test, from_pointer_pointer_constructor)
{ {
auto workaround_macro = [&]() { const multi_span<int> s{&arr[1], &arr[0]}; }; auto workaround_macro = [&]() { const multi_span<int> s{&arr[1], &arr[0]}; };
EXPECT_DEATH(workaround_macro(), deathstring.data()); EXPECT_DEATH(workaround_macro(), deathstring);
} }
{ {
int* p = nullptr; int* p = nullptr;
auto workaround_macro = [&]() { const multi_span<int> s{&arr[0], p}; }; auto workaround_macro = [&]() { const multi_span<int> s{&arr[0], p}; };
EXPECT_DEATH(workaround_macro(), deathstring.data()); EXPECT_DEATH(workaround_macro(), deathstring);
} }
{ {
int* p = nullptr; int* p = nullptr;
auto workaround_macro = [&]() { const multi_span<int> s{p, p}; }; auto workaround_macro = [&]() { const multi_span<int> s{p, p}; };
EXPECT_DEATH(workaround_macro(), deathstring.data()); EXPECT_DEATH(workaround_macro(), deathstring);
} }
{ {
int* p = nullptr; int* p = nullptr;
auto workaround_macro = [&]() { const multi_span<int> s{&arr[0], p}; }; auto workaround_macro = [&]() { const multi_span<int> s{&arr[0], p}; };
EXPECT_DEATH(workaround_macro(), deathstring.data()); EXPECT_DEATH(workaround_macro(), deathstring);
} }
} }
@ -605,7 +605,7 @@ TEST(multi_span_test, from_dynamic_array_constructor)
multi_span<double, dynamic_range, 3, 4> s(arr, 10); multi_span<double, dynamic_range, 3, 4> s(arr, 10);
EXPECT_TRUE(s.length() == 120); EXPECT_TRUE(s.length() == 120);
EXPECT_TRUE(s.data() == &arr[0][0][0]); EXPECT_TRUE(s.data() == &arr[0][0][0]);
EXPECT_DEATH(s[10][3][4], deathstring.data()); EXPECT_DEATH(s[10][3][4], deathstring);
} }
{ {
@ -838,7 +838,7 @@ TEST(multi_span_test, from_convertible_span_constructor)
}); });
auto f = [&]() { multi_span<int, 7, 4, 2> av1(nullptr); }; auto f = [&]() { multi_span<int, 7, 4, 2> av1(nullptr); };
EXPECT_DEATH(f(), deathstring.data()); EXPECT_DEATH(f(), deathstring);
#endif #endif
#ifdef CONFIRM_COMPILATION_ERRORS #ifdef CONFIRM_COMPILATION_ERRORS
@ -944,7 +944,7 @@ TEST(multi_span_test, first)
std::abort(); std::abort();
}); });
EXPECT_DEATH(av.first(6).length(), deathstring.data()); EXPECT_DEATH(av.first(6).length(), deathstring);
} }
{ {
@ -992,7 +992,7 @@ TEST(multi_span_test, last)
std::abort(); std::abort();
}); });
EXPECT_DEATH(av.last(6).length(), deathstring.data()); EXPECT_DEATH(av.last(6).length(), deathstring);
} }
{ {
@ -1032,8 +1032,8 @@ TEST(multi_span_test, subspan)
EXPECT_TRUE((av.subspan<0, 5>().bounds()) == static_bounds<5>()); EXPECT_TRUE((av.subspan<0, 5>().bounds()) == static_bounds<5>());
EXPECT_TRUE((av.subspan<0, 5>().length()) == 5); EXPECT_TRUE((av.subspan<0, 5>().length()) == 5);
EXPECT_TRUE(av.subspan(0, 5).length() == 5); EXPECT_TRUE(av.subspan(0, 5).length() == 5);
EXPECT_DEATH(av.subspan(0, 6).length(), deathstring.data()); EXPECT_DEATH(av.subspan(0, 6).length(), deathstring);
EXPECT_DEATH(av.subspan(1, 5).length(), deathstring.data()); EXPECT_DEATH(av.subspan(1, 5).length(), deathstring);
} }
{ {
@ -1041,7 +1041,7 @@ TEST(multi_span_test, subspan)
EXPECT_TRUE((av.subspan<5, 0>().bounds()) == static_bounds<0>()); EXPECT_TRUE((av.subspan<5, 0>().bounds()) == static_bounds<0>());
EXPECT_TRUE((av.subspan<5, 0>().length()) == 0); EXPECT_TRUE((av.subspan<5, 0>().length()) == 0);
EXPECT_TRUE(av.subspan(5, 0).length() == 0); EXPECT_TRUE(av.subspan(5, 0).length() == 0);
EXPECT_DEATH(av.subspan(6, 0).length(), deathstring.data()); EXPECT_DEATH(av.subspan(6, 0).length(), deathstring);
} }
{ {
@ -1049,13 +1049,13 @@ TEST(multi_span_test, subspan)
EXPECT_TRUE((av.subspan<0, 0>().bounds()) == static_bounds<0>()); EXPECT_TRUE((av.subspan<0, 0>().bounds()) == static_bounds<0>());
EXPECT_TRUE((av.subspan<0, 0>().length()) == 0); EXPECT_TRUE((av.subspan<0, 0>().length()) == 0);
EXPECT_TRUE(av.subspan(0, 0).length() == 0); EXPECT_TRUE(av.subspan(0, 0).length() == 0);
EXPECT_DEATH((av.subspan<1, 0>().length()), deathstring.data()); EXPECT_DEATH((av.subspan<1, 0>().length()), deathstring);
} }
{ {
multi_span<int> av; multi_span<int> av;
EXPECT_TRUE(av.subspan(0).length() == 0); EXPECT_TRUE(av.subspan(0).length() == 0);
EXPECT_DEATH(av.subspan(1).length(), deathstring.data()); EXPECT_DEATH(av.subspan(1).length(), deathstring);
} }
{ {
@ -1064,7 +1064,7 @@ TEST(multi_span_test, subspan)
EXPECT_TRUE(av.subspan(1).length() == 4); EXPECT_TRUE(av.subspan(1).length() == 4);
EXPECT_TRUE(av.subspan(4).length() == 1); EXPECT_TRUE(av.subspan(4).length() == 1);
EXPECT_TRUE(av.subspan(5).length() == 0); EXPECT_TRUE(av.subspan(5).length() == 0);
EXPECT_DEATH(av.subspan(6).length(), deathstring.data()); EXPECT_DEATH(av.subspan(6).length(), deathstring);
auto av2 = av.subspan(1); auto av2 = av.subspan(1);
for (int i = 0; i < 4; ++i) EXPECT_TRUE(av2[i] == i + 2); for (int i = 0; i < 4; ++i) EXPECT_TRUE(av2[i] == i + 2);
} }
@ -1075,7 +1075,7 @@ TEST(multi_span_test, subspan)
EXPECT_TRUE(av.subspan(1).length() == 4); EXPECT_TRUE(av.subspan(1).length() == 4);
EXPECT_TRUE(av.subspan(4).length() == 1); EXPECT_TRUE(av.subspan(4).length() == 1);
EXPECT_TRUE(av.subspan(5).length() == 0); EXPECT_TRUE(av.subspan(5).length() == 0);
EXPECT_DEATH(av.subspan(6).length(), deathstring.data()); EXPECT_DEATH(av.subspan(6).length(), deathstring);
auto av2 = av.subspan(1); auto av2 = av.subspan(1);
for (int i = 0; i < 4; ++i) EXPECT_TRUE(av2[i] == i + 2); for (int i = 0; i < 4; ++i) EXPECT_TRUE(av2[i] == i + 2);
} }
@ -1113,7 +1113,7 @@ TEST(multi_span_test, extent)
multi_span<int> s; multi_span<int> s;
EXPECT_TRUE(s.extent() == 0); EXPECT_TRUE(s.extent() == 0);
EXPECT_TRUE(s.extent(0) == 0); EXPECT_TRUE(s.extent(0) == 0);
EXPECT_DEATH(s.extent(1), deathstring.data()); EXPECT_DEATH(s.extent(1), deathstring);
#ifdef CONFIRM_COMPILATION_ERRORS #ifdef CONFIRM_COMPILATION_ERRORS
EXPECT_TRUE(s.extent<1>() == 0); EXPECT_TRUE(s.extent<1>() == 0);
#endif #endif
@ -1123,7 +1123,7 @@ TEST(multi_span_test, extent)
multi_span<int, 0> s; multi_span<int, 0> s;
EXPECT_TRUE(s.extent() == 0); EXPECT_TRUE(s.extent() == 0);
EXPECT_TRUE(s.extent(0) == 0); EXPECT_TRUE(s.extent(0) == 0);
EXPECT_DEATH(s.extent(1), deathstring.data()); EXPECT_DEATH(s.extent(1), deathstring);
} }
{ {
@ -1135,7 +1135,7 @@ TEST(multi_span_test, extent)
EXPECT_TRUE(s.extent<1>() == 2); EXPECT_TRUE(s.extent<1>() == 2);
EXPECT_TRUE(s.extent(0) == 1); EXPECT_TRUE(s.extent(0) == 1);
EXPECT_TRUE(s.extent(1) == 2); EXPECT_TRUE(s.extent(1) == 2);
EXPECT_DEATH(s.extent(3), deathstring.data()); EXPECT_DEATH(s.extent(3), deathstring);
} }
{ {
@ -1147,7 +1147,7 @@ TEST(multi_span_test, extent)
EXPECT_TRUE(s.extent<1>() == 2); EXPECT_TRUE(s.extent<1>() == 2);
EXPECT_TRUE(s.extent(0) == 0); EXPECT_TRUE(s.extent(0) == 0);
EXPECT_TRUE(s.extent(1) == 2); EXPECT_TRUE(s.extent(1) == 2);
EXPECT_DEATH(s.extent(3), deathstring.data()); EXPECT_DEATH(s.extent(3), deathstring);
} }
} }
@ -1163,7 +1163,7 @@ TEST(multi_span_test, operator_function_call)
{ {
multi_span<int> s = arr; multi_span<int> s = arr;
EXPECT_TRUE(s(0) == 1); EXPECT_TRUE(s(0) == 1);
EXPECT_DEATH(s(5), deathstring.data()); EXPECT_DEATH(s(5), deathstring);
} }
int arr2d[2][3] = {1, 2, 3, 4, 5, 6}; int arr2d[2][3] = {1, 2, 3, 4, 5, 6};
@ -1322,17 +1322,17 @@ TEST(multi_span_test, bounds_checks)
}); });
// out of bounds // out of bounds
EXPECT_DEATH(av[1][3] = 3, deathstring.data()); EXPECT_DEATH(av[1][3] = 3, deathstring);
EXPECT_DEATH((av[{1, 3}] = 3), deathstring.data()); EXPECT_DEATH((av[{1, 3}] = 3), deathstring);
EXPECT_DEATH(av[10][2], deathstring.data()); EXPECT_DEATH(av[10][2], deathstring);
EXPECT_DEATH((av[{10, 2}]), deathstring.data()); EXPECT_DEATH((av[{10, 2}]), deathstring);
EXPECT_DEATH(av[-1][0], deathstring.data()); EXPECT_DEATH(av[-1][0], deathstring);
EXPECT_DEATH((av[{-1, 0}]), deathstring.data()); EXPECT_DEATH((av[{-1, 0}]), deathstring);
EXPECT_DEATH(av[0][-1], deathstring.data()); EXPECT_DEATH(av[0][-1], deathstring);
EXPECT_DEATH((av[{0, -1}]), deathstring.data()); EXPECT_DEATH((av[{0, -1}]), deathstring);
} }
TEST(multi_span_test, span_parameter_test) TEST(multi_span_test, span_parameter_test)
@ -1459,9 +1459,9 @@ TEST(multi_span_test, empty_spans)
multi_span<int, 0> empty_av(nullptr); multi_span<int, 0> empty_av(nullptr);
EXPECT_TRUE(empty_av.bounds().index_bounds() == multi_span_index<1>{0}); EXPECT_TRUE(empty_av.bounds().index_bounds() == multi_span_index<1>{0});
EXPECT_DEATH(empty_av[0], deathstring.data()); EXPECT_DEATH(empty_av[0], deathstring);
EXPECT_DEATH(empty_av.begin()[0], deathstring.data()); EXPECT_DEATH(empty_av.begin()[0], deathstring);
EXPECT_DEATH(empty_av.cbegin()[0], deathstring.data()); EXPECT_DEATH(empty_av.cbegin()[0], deathstring);
for (auto& v : empty_av) for (auto& v : empty_av)
{ {
(void) v; (void) v;
@ -1472,9 +1472,9 @@ TEST(multi_span_test, empty_spans)
{ {
multi_span<int> empty_av = {}; multi_span<int> empty_av = {};
EXPECT_TRUE(empty_av.bounds().index_bounds() == multi_span_index<1>{0}); EXPECT_TRUE(empty_av.bounds().index_bounds() == multi_span_index<1>{0});
EXPECT_DEATH(empty_av[0], deathstring.data()); EXPECT_DEATH(empty_av[0], deathstring);
EXPECT_DEATH(empty_av.begin()[0], deathstring.data()); EXPECT_DEATH(empty_av.begin()[0], deathstring);
EXPECT_DEATH(empty_av.cbegin()[0], deathstring.data()); EXPECT_DEATH(empty_av.cbegin()[0], deathstring);
for (auto& v : empty_av) for (auto& v : empty_av)
{ {
(void) v; (void) v;
@ -1709,7 +1709,7 @@ TEST(multi_span_test, span_structure_size)
std::abort(); std::abort();
}); });
EXPECT_DEATH(av1[10][3][4], deathstring.data()); EXPECT_DEATH(av1[10][3][4], deathstring);
multi_span<const double, dynamic_range, 6, 4> av2 = multi_span<const double, dynamic_range, 6, 4> av2 =
as_multi_span(av1, dim(5), dim<6>(), dim<4>()); as_multi_span(av1, dim(5), dim<6>(), dim<4>());
@ -1808,7 +1808,7 @@ TEST(multi_span_test, fixed_size_conversions)
const multi_span<int, 4> av9 = {arr2, 2}; const multi_span<int, 4> av9 = {arr2, 2};
(void) av9; (void) av9;
}; };
EXPECT_DEATH(f(), deathstring.data()); EXPECT_DEATH(f(), deathstring);
} }
// this should fail - we are trying to assign a small dynamic a_v to a fixed_size larger one // this should fail - we are trying to assign a small dynamic a_v to a fixed_size larger one
@ -1817,7 +1817,7 @@ TEST(multi_span_test, fixed_size_conversions)
const multi_span<int, 4> av2 = av; const multi_span<int, 4> av2 = av;
(void) av2; (void) av2;
}; };
EXPECT_DEATH(f(), deathstring.data()); EXPECT_DEATH(f(), deathstring);
} }
TEST(multi_span_test, as_writeable_bytes) TEST(multi_span_test, as_writeable_bytes)

View File

@ -53,7 +53,7 @@ struct fail_fast;
using namespace gsl; using namespace gsl;
namespace{ namespace{
constexpr std::string_view deathstring("Expected Death"); static const std::string deathstring("Expected Death");
} }
struct MyBase struct MyBase
@ -182,7 +182,7 @@ TEST(notnull_tests, TestNotNullConstructors)
std::make_shared<int>(10)); // shared_ptr<int> is nullptr assignable std::make_shared<int>(10)); // shared_ptr<int> is nullptr assignable
int* pi = nullptr; int* pi = nullptr;
EXPECT_DEATH((not_null<decltype(pi)>(pi)), deathstring.data()); EXPECT_DEATH((not_null<decltype(pi)>(pi)), deathstring);
} }
{ {
@ -239,8 +239,8 @@ TEST(notnull_tests, TestNotNullConstructors)
{ {
// from returned pointer // from returned pointer
EXPECT_DEATH(helper(return_pointer()), deathstring.data()); EXPECT_DEATH(helper(return_pointer()), deathstring);
EXPECT_DEATH(helper_const(return_pointer()), deathstring.data()); EXPECT_DEATH(helper_const(return_pointer()), deathstring);
} }
} }
@ -310,7 +310,7 @@ TEST(notnull_tests, TestNotNullAssignment)
EXPECT_TRUE(helper(p)); EXPECT_TRUE(helper(p));
int* q = nullptr; int* q = nullptr;
EXPECT_DEATH(p = not_null<int*>(q), deathstring.data()); EXPECT_DEATH(p = not_null<int*>(q), deathstring);
} }
TEST(notnull_tests, TestNotNullRawPointerComparison) TEST(notnull_tests, TestNotNullRawPointerComparison)
@ -469,7 +469,7 @@ TEST(notnull_tests, TestNotNullConstructorTypeDeduction)
int* p1 = nullptr; int* p1 = nullptr;
const not_null x{p1}; const not_null x{p1};
}; };
EXPECT_DEATH(workaround_macro(), deathstring.data()); EXPECT_DEATH(workaround_macro(), deathstring);
} }
{ {
@ -477,14 +477,14 @@ TEST(notnull_tests, TestNotNullConstructorTypeDeduction)
const int* p1 = nullptr; const int* p1 = nullptr;
const not_null x{p1}; const not_null x{p1};
}; };
EXPECT_DEATH(workaround_macro(), deathstring.data()); EXPECT_DEATH(workaround_macro(), deathstring);
} }
{ {
int* p = nullptr; int* p = nullptr;
EXPECT_DEATH(helper(not_null{p}), deathstring.data()); EXPECT_DEATH(helper(not_null{p}), deathstring);
EXPECT_DEATH(helper_const(not_null{p}), deathstring.data()); EXPECT_DEATH(helper_const(not_null{p}), deathstring);
} }
#ifdef CONFIRM_COMPILATION_ERRORS #ifdef CONFIRM_COMPILATION_ERRORS
@ -531,7 +531,7 @@ TEST(notnull_tests, TestMakeNotNull)
const auto x = make_not_null(p1); const auto x = make_not_null(p1);
EXPECT_TRUE(*x == 42); EXPECT_TRUE(*x == 42);
}; };
EXPECT_DEATH(workaround_macro(), deathstring.data()); EXPECT_DEATH(workaround_macro(), deathstring);
} }
{ {
@ -540,21 +540,21 @@ TEST(notnull_tests, TestMakeNotNull)
const auto x = make_not_null(p1); const auto x = make_not_null(p1);
EXPECT_TRUE(*x == 42); EXPECT_TRUE(*x == 42);
}; };
EXPECT_DEATH(workaround_macro(), deathstring.data()); EXPECT_DEATH(workaround_macro(), deathstring);
} }
{ {
int* p = nullptr; int* p = nullptr;
EXPECT_DEATH(helper(make_not_null(p)), deathstring.data()); EXPECT_DEATH(helper(make_not_null(p)), deathstring);
EXPECT_DEATH(helper_const(make_not_null(p)), deathstring.data()); EXPECT_DEATH(helper_const(make_not_null(p)), deathstring);
} }
#ifdef CONFIRM_COMPILATION_ERRORS #ifdef CONFIRM_COMPILATION_ERRORS
{ {
EXPECT_DEATH(make_not_null(nullptr), deathstring.data()); EXPECT_DEATH(make_not_null(nullptr), deathstring);
EXPECT_DEATH(helper(make_not_null(nullptr)), deathstring.data()); EXPECT_DEATH(helper(make_not_null(nullptr)), deathstring);
EXPECT_DEATH(helper_const(make_not_null(nullptr)), deathstring.data()); EXPECT_DEATH(helper_const(make_not_null(nullptr)), deathstring);
} }
#endif #endif
} }

View File

@ -75,7 +75,7 @@ struct AddressOverloaded
return {}; return {};
} }
}; };
constexpr std::string_view deathstring("Expected Death"); static const std::string deathstring("Expected Death");
} // namespace } // namespace
TEST(span_test, constructors) TEST(span_test, constructors)
@ -139,21 +139,21 @@ TEST(span_test, from_nullptr_size_constructor)
auto workaround_macro = []() { auto workaround_macro = []() {
const span<int, 1> s{nullptr, narrow_cast<span<int>::index_type>(0)}; const span<int, 1> s{nullptr, narrow_cast<span<int>::index_type>(0)};
}; };
EXPECT_DEATH(workaround_macro(), deathstring.data()); EXPECT_DEATH(workaround_macro(), deathstring);
} }
{ {
auto workaround_macro = []() { const span<int> s{nullptr, 1}; }; auto workaround_macro = []() { const span<int> s{nullptr, 1}; };
EXPECT_DEATH(workaround_macro(), deathstring.data()); EXPECT_DEATH(workaround_macro(), deathstring);
auto const_workaround_macro = []() { const span<const int> s{nullptr, 1}; }; auto const_workaround_macro = []() { const span<const int> s{nullptr, 1}; };
EXPECT_DEATH(const_workaround_macro(), deathstring.data()); EXPECT_DEATH(const_workaround_macro(), deathstring);
} }
{ {
auto workaround_macro = []() { const span<int, 0> s{nullptr, 1}; }; auto workaround_macro = []() { const span<int, 0> s{nullptr, 1}; };
EXPECT_DEATH(workaround_macro(), deathstring.data()); EXPECT_DEATH(workaround_macro(), deathstring);
auto const_workaround_macro = []() { const span<const int, 0> s{nullptr, 1}; }; auto const_workaround_macro = []() { const span<const int, 0> s{nullptr, 1}; };
EXPECT_DEATH(const_workaround_macro(), deathstring.data()); EXPECT_DEATH(const_workaround_macro(), deathstring);
} }
{ {
span<int*> s{nullptr, narrow_cast<span<int>::index_type>(0)}; span<int*> s{nullptr, narrow_cast<span<int>::index_type>(0)};
@ -223,7 +223,7 @@ TEST(span_test, from_pointer_length_constructor)
{ {
int* p = nullptr; int* p = nullptr;
auto workaround_macro = [=]() { const span<int> s{p, 2}; }; auto workaround_macro = [=]() { const span<int> s{p, 2}; };
EXPECT_DEATH(workaround_macro(), deathstring.data()); EXPECT_DEATH(workaround_macro(), deathstring);
} }
{ {
@ -244,7 +244,7 @@ TEST(span_test, from_pointer_length_constructor)
{ {
int* p = nullptr; int* p = nullptr;
auto workaround_macro = [=]() { make_span(p, 2); }; auto workaround_macro = [=]() { make_span(p, 2); };
EXPECT_DEATH(workaround_macro(), deathstring.data()); EXPECT_DEATH(workaround_macro(), deathstring);
} }
} }
@ -282,14 +282,14 @@ TEST(span_test, from_pointer_pointer_construction)
// this will fail the std::distance() precondition, which asserts on MSVC debug builds // this will fail the std::distance() precondition, which asserts on MSVC debug builds
//{ //{
// auto workaround_macro = [&]() { span<int> s{&arr[1], &arr[0]}; }; // auto workaround_macro = [&]() { span<int> s{&arr[1], &arr[0]}; };
// EXPECT_DEATH(workaround_macro(), deathstring.data()); // EXPECT_DEATH(workaround_macro(), deathstring);
//} //}
// this will fail the std::distance() precondition, which asserts on MSVC debug builds // this will fail the std::distance() precondition, which asserts on MSVC debug builds
//{ //{
// int* p = nullptr; // int* p = nullptr;
// auto workaround_macro = [&]() { span<int> s{&arr[0], p}; }; // auto workaround_macro = [&]() { span<int> s{&arr[0], p}; };
// EXPECT_DEATH(workaround_macro(), deathstring.data()); // EXPECT_DEATH(workaround_macro(), deathstring);
//} //}
{ {
@ -310,7 +310,7 @@ TEST(span_test, from_pointer_pointer_construction)
//{ //{
// int* p = nullptr; // int* p = nullptr;
// auto workaround_macro = [&]() { span<int> s{&arr[0], p}; }; // auto workaround_macro = [&]() { span<int> s{&arr[0], p}; };
// EXPECT_DEATH(workaround_macro(), deathstring.data()); // EXPECT_DEATH(workaround_macro(), deathstring);
//} //}
{ {
@ -862,7 +862,7 @@ TEST(span_test, from_array_constructor)
EXPECT_TRUE(av.first<6>().size() == 6); EXPECT_TRUE(av.first<6>().size() == 6);
EXPECT_TRUE(av.first<-1>().size() == -1); EXPECT_TRUE(av.first<-1>().size() == -1);
#endif #endif
EXPECT_DEATH(av.first(6).size(), deathstring.data()); EXPECT_DEATH(av.first(6).size(), deathstring);
} }
{ {
@ -903,7 +903,7 @@ TEST(span_test, from_array_constructor)
#ifdef CONFIRM_COMPILATION_ERRORS #ifdef CONFIRM_COMPILATION_ERRORS
EXPECT_TRUE(av.last<6>().size() == 6); EXPECT_TRUE(av.last<6>().size() == 6);
#endif #endif
EXPECT_DEATH(av.last(6).size(), deathstring.data()); EXPECT_DEATH(av.last(6).size(), deathstring);
} }
{ {
@ -942,8 +942,8 @@ TEST(span_test, from_array_constructor)
EXPECT_TRUE(decltype(av.subspan<0, 5>())::extent == 5); EXPECT_TRUE(decltype(av.subspan<0, 5>())::extent == 5);
EXPECT_TRUE(av.subspan(0, 5).size() == 5); EXPECT_TRUE(av.subspan(0, 5).size() == 5);
EXPECT_DEATH(av.subspan(0, 6).size(), deathstring.data()); EXPECT_DEATH(av.subspan(0, 6).size(), deathstring);
EXPECT_DEATH(av.subspan(1, 5).size(), deathstring.data()); EXPECT_DEATH(av.subspan(1, 5).size(), deathstring);
} }
{ {
@ -952,7 +952,7 @@ TEST(span_test, from_array_constructor)
EXPECT_TRUE(decltype(av.subspan<4, 0>())::extent == 0); EXPECT_TRUE(decltype(av.subspan<4, 0>())::extent == 0);
EXPECT_TRUE(av.subspan(4, 0).size() == 0); EXPECT_TRUE(av.subspan(4, 0).size() == 0);
EXPECT_TRUE(av.subspan(5, 0).size() == 0); EXPECT_TRUE(av.subspan(5, 0).size() == 0);
EXPECT_DEATH(av.subspan(6, 0).size(), deathstring.data()); EXPECT_DEATH(av.subspan(6, 0).size(), deathstring);
} }
{ {
@ -966,13 +966,13 @@ TEST(span_test, from_array_constructor)
EXPECT_TRUE((av.subspan<0, 0>().size()) == 0); EXPECT_TRUE((av.subspan<0, 0>().size()) == 0);
EXPECT_TRUE(decltype(av.subspan<0, 0>())::extent == 0); EXPECT_TRUE(decltype(av.subspan<0, 0>())::extent == 0);
EXPECT_TRUE(av.subspan(0, 0).size() == 0); EXPECT_TRUE(av.subspan(0, 0).size() == 0);
EXPECT_DEATH((av.subspan<1, 0>().size()), deathstring.data()); EXPECT_DEATH((av.subspan<1, 0>().size()), deathstring);
} }
{ {
span<int> av; span<int> av;
EXPECT_TRUE(av.subspan(0).size() == 0); EXPECT_TRUE(av.subspan(0).size() == 0);
EXPECT_DEATH(av.subspan(1).size(), deathstring.data()); EXPECT_DEATH(av.subspan(1).size(), deathstring);
} }
{ {
@ -981,7 +981,7 @@ TEST(span_test, from_array_constructor)
EXPECT_TRUE(av.subspan(1).size() == 4); EXPECT_TRUE(av.subspan(1).size() == 4);
EXPECT_TRUE(av.subspan(4).size() == 1); EXPECT_TRUE(av.subspan(4).size() == 1);
EXPECT_TRUE(av.subspan(5).size() == 0); EXPECT_TRUE(av.subspan(5).size() == 0);
EXPECT_DEATH(av.subspan(6).size(), deathstring.data()); EXPECT_DEATH(av.subspan(6).size(), deathstring);
const auto av2 = av.subspan(1); const auto av2 = av.subspan(1);
for (int i = 0; i < 4; ++i) EXPECT_TRUE(av2[i] == i + 2); for (int i = 0; i < 4; ++i) EXPECT_TRUE(av2[i] == i + 2);
} }
@ -992,7 +992,7 @@ TEST(span_test, from_array_constructor)
EXPECT_TRUE(av.subspan(1).size() == 4); EXPECT_TRUE(av.subspan(1).size() == 4);
EXPECT_TRUE(av.subspan(4).size() == 1); EXPECT_TRUE(av.subspan(4).size() == 1);
EXPECT_TRUE(av.subspan(5).size() == 0); EXPECT_TRUE(av.subspan(5).size() == 0);
EXPECT_DEATH(av.subspan(6).size(), deathstring.data()); EXPECT_DEATH(av.subspan(6).size(), deathstring);
const auto av2 = av.subspan(1); const auto av2 = av.subspan(1);
for (int i = 0; i < 4; ++i) EXPECT_TRUE(av2[i] == i + 2); for (int i = 0; i < 4; ++i) EXPECT_TRUE(av2[i] == i + 2);
} }
@ -1009,7 +1009,7 @@ TEST(span_test, from_array_constructor)
{ {
span<int> s = arr; span<int> s = arr;
EXPECT_TRUE(s.at(0) == 1); EXPECT_TRUE(s.at(0) == 1);
EXPECT_DEATH(s.at(5), deathstring.data()); EXPECT_DEATH(s.at(5), deathstring);
} }
{ {
@ -1017,7 +1017,7 @@ TEST(span_test, from_array_constructor)
span<int, 2> s = arr2d; span<int, 2> s = arr2d;
EXPECT_TRUE(s.at(0) == 1); EXPECT_TRUE(s.at(0) == 1);
EXPECT_TRUE(s.at(1) == 6); EXPECT_TRUE(s.at(1) == 6);
EXPECT_DEATH(s.at(2), deathstring.data()); EXPECT_DEATH(s.at(2), deathstring);
} }
} }
@ -1032,7 +1032,7 @@ TEST(span_test, from_array_constructor)
{ {
span<int> s = arr; span<int> s = arr;
EXPECT_TRUE(s(0) == 1); EXPECT_TRUE(s(0) == 1);
EXPECT_DEATH(s(5), deathstring.data()); EXPECT_DEATH(s(5), deathstring);
} }
{ {
@ -1040,7 +1040,7 @@ TEST(span_test, from_array_constructor)
span<int, 2> s = arr2d; span<int, 2> s = arr2d;
EXPECT_TRUE(s(0) == 1); EXPECT_TRUE(s(0) == 1);
EXPECT_TRUE(s(1) == 6); EXPECT_TRUE(s(1) == 6);
EXPECT_DEATH(s(2), deathstring.data()); EXPECT_DEATH(s(2), deathstring);
} }
} }
@ -1157,7 +1157,7 @@ TEST(span_test, from_array_constructor)
auto beyond = s.end(); auto beyond = s.end();
EXPECT_TRUE(it != beyond); EXPECT_TRUE(it != beyond);
EXPECT_DEATH(*beyond, deathstring.data()); EXPECT_DEATH(*beyond, deathstring);
EXPECT_TRUE(beyond - first == 4); EXPECT_TRUE(beyond - first == 4);
EXPECT_TRUE(first - first == 0); EXPECT_TRUE(first - first == 0);
@ -1215,7 +1215,7 @@ TEST(span_test, from_array_constructor)
auto beyond = s.cend(); auto beyond = s.cend();
EXPECT_TRUE(it != beyond); EXPECT_TRUE(it != beyond);
EXPECT_DEATH(*beyond, deathstring.data()); EXPECT_DEATH(*beyond, deathstring);
EXPECT_TRUE(beyond - first == 4); EXPECT_TRUE(beyond - first == 4);
EXPECT_TRUE(first - first == 0); EXPECT_TRUE(first - first == 0);
@ -1259,7 +1259,7 @@ TEST(span_test, from_array_constructor)
auto beyond = s.rend(); auto beyond = s.rend();
EXPECT_TRUE(it != beyond); EXPECT_TRUE(it != beyond);
EXPECT_DEATH(auto _ = *beyond , deathstring.data()); EXPECT_DEATH(auto _ = *beyond , deathstring);
EXPECT_TRUE(beyond - first == 4); EXPECT_TRUE(beyond - first == 4);
EXPECT_TRUE(first - first == 0); EXPECT_TRUE(first - first == 0);
@ -1304,7 +1304,7 @@ TEST(span_test, from_array_constructor)
auto beyond = s.crend(); auto beyond = s.crend();
EXPECT_TRUE(it != beyond); EXPECT_TRUE(it != beyond);
EXPECT_DEATH(auto _ = *beyond, deathstring.data()); EXPECT_DEATH(auto _ = *beyond, deathstring);
EXPECT_TRUE(beyond - first == 4); EXPECT_TRUE(beyond - first == 4);
EXPECT_TRUE(first - first == 0); EXPECT_TRUE(first - first == 0);
@ -1552,7 +1552,7 @@ TEST(span_test, from_array_constructor)
const span<int, 2> s2 = s; const span<int, 2> s2 = s;
static_cast<void>(s2); static_cast<void>(s2);
}; };
EXPECT_DEATH(f(), deathstring.data()); EXPECT_DEATH(f(), deathstring);
} }
// but doing so explicitly is ok // but doing so explicitly is ok
@ -1591,7 +1591,7 @@ TEST(span_test, from_array_constructor)
const span<int, 4> _s4 = {arr2, 2}; const span<int, 4> _s4 = {arr2, 2};
static_cast<void>(_s4); static_cast<void>(_s4);
}; };
EXPECT_DEATH(f(), deathstring.data()); EXPECT_DEATH(f(), deathstring);
} }
// this should fail - we are trying to assign a small dynamic span to a fixed_size larger one // this should fail - we are trying to assign a small dynamic span to a fixed_size larger one
@ -1599,7 +1599,7 @@ TEST(span_test, from_array_constructor)
const span<int, 4> _s4 = av; const span<int, 4> _s4 = av;
static_cast<void>(_s4); static_cast<void>(_s4);
}; };
EXPECT_DEATH(f(), deathstring.data()); EXPECT_DEATH(f(), deathstring);
} }
TEST(span_test, interop_with_std_regex) TEST(span_test, interop_with_std_regex)

View File

@ -43,7 +43,7 @@ struct fail_fast;
} // namespace gsl } // namespace gsl
namespace{ namespace{
constexpr std::string_view deathstring("Expected Death"); static const std::string deathstring("Expected Death");
} }
using namespace gsl; using namespace gsl;
@ -181,7 +181,7 @@ TEST(strict_notnull_tests, TestStrictNotNullConstructorTypeDeduction)
int* p1 = nullptr; int* p1 = nullptr;
const strict_not_null x{p1}; const strict_not_null x{p1};
}; };
EXPECT_DEATH(workaround_macro(), deathstring.data()); EXPECT_DEATH(workaround_macro(), deathstring);
} }
{ {
@ -189,14 +189,14 @@ TEST(strict_notnull_tests, TestStrictNotNullConstructorTypeDeduction)
const int* p1 = nullptr; const int* p1 = nullptr;
const strict_not_null x{p1}; const strict_not_null x{p1};
}; };
EXPECT_DEATH(workaround_macro(), deathstring.data()); EXPECT_DEATH(workaround_macro(), deathstring);
} }
{ {
int* p = nullptr; int* p = nullptr;
EXPECT_DEATH(helper(strict_not_null{p}), deathstring.data()); EXPECT_DEATH(helper(strict_not_null{p}), deathstring);
EXPECT_DEATH(helper_const(strict_not_null{p}), deathstring.data()); EXPECT_DEATH(helper_const(strict_not_null{p}), deathstring);
} }
#ifdef CONFIRM_COMPILATION_ERRORS #ifdef CONFIRM_COMPILATION_ERRORS

View File

@ -56,7 +56,7 @@ using namespace gsl;
namespace namespace
{ {
constexpr std::string_view deathstring("Expected Death"); static const std::string deathstring("Expected Death");
struct BaseClass struct BaseClass
{ {
}; };
@ -429,15 +429,15 @@ TEST(strided_span_tests, strided_span_bounds)
{ {
// incorrect sections // incorrect sections
EXPECT_DEATH(av.section(0, 0)[0], deathstring.data()); EXPECT_DEATH(av.section(0, 0)[0], deathstring);
EXPECT_DEATH(av.section(1, 0)[0], deathstring.data()); EXPECT_DEATH(av.section(1, 0)[0], deathstring);
EXPECT_DEATH(av.section(1, 1)[1], deathstring.data()); EXPECT_DEATH(av.section(1, 1)[1], deathstring);
EXPECT_DEATH(av.section(2, 5), deathstring.data()); EXPECT_DEATH(av.section(2, 5), deathstring);
EXPECT_DEATH(av.section(5, 2), deathstring.data()); EXPECT_DEATH(av.section(5, 2), deathstring);
EXPECT_DEATH(av.section(5, 0), deathstring.data()); EXPECT_DEATH(av.section(5, 0), deathstring);
EXPECT_DEATH(av.section(0, 5), deathstring.data()); EXPECT_DEATH(av.section(0, 5), deathstring);
EXPECT_DEATH(av.section(5, 5), deathstring.data()); EXPECT_DEATH(av.section(5, 5), deathstring);
} }
{ {
@ -445,19 +445,19 @@ TEST(strided_span_tests, strided_span_bounds)
strided_span<int, 1> sav{av, {{4}, {}}}; strided_span<int, 1> sav{av, {{4}, {}}};
EXPECT_TRUE(sav[0] == 0); EXPECT_TRUE(sav[0] == 0);
EXPECT_TRUE(sav[3] == 0); EXPECT_TRUE(sav[3] == 0);
EXPECT_DEATH(sav[4], deathstring.data()); EXPECT_DEATH(sav[4], deathstring);
} }
{ {
// zero extent // zero extent
strided_span<int, 1> sav{av, {{}, {1}}}; strided_span<int, 1> sav{av, {{}, {1}}};
EXPECT_DEATH(sav[0], deathstring.data()); EXPECT_DEATH(sav[0], deathstring);
} }
{ {
// zero extent and stride // zero extent and stride
strided_span<int, 1> sav{av, {{}, {}}}; strided_span<int, 1> sav{av, {{}, {}}};
EXPECT_DEATH(sav[0], deathstring.data()); EXPECT_DEATH(sav[0], deathstring);
} }
{ {
@ -465,7 +465,7 @@ TEST(strided_span_tests, strided_span_bounds)
strided_span<int, 1> sav{arr, {4, 1}}; strided_span<int, 1> sav{arr, {4, 1}};
EXPECT_TRUE(sav.bounds().index_bounds() == multi_span_index<1>{4}); EXPECT_TRUE(sav.bounds().index_bounds() == multi_span_index<1>{4});
EXPECT_TRUE(sav[3] == 3); EXPECT_TRUE(sav[3] == 3);
EXPECT_DEATH(sav[4], deathstring.data()); EXPECT_DEATH(sav[4], deathstring);
} }
{ {
@ -473,7 +473,7 @@ TEST(strided_span_tests, strided_span_bounds)
strided_span<int, 1> sav{arr, {2, 1}}; strided_span<int, 1> sav{arr, {2, 1}};
EXPECT_TRUE(sav.bounds().index_bounds() == multi_span_index<1>{2}); EXPECT_TRUE(sav.bounds().index_bounds() == multi_span_index<1>{2});
EXPECT_TRUE(sav[1] == 1); EXPECT_TRUE(sav[1] == 1);
EXPECT_DEATH(sav[2], deathstring.data()); EXPECT_DEATH(sav[2], deathstring);
} }
{ {
@ -482,35 +482,35 @@ TEST(strided_span_tests, strided_span_bounds)
EXPECT_TRUE(sav.bounds().index_bounds() == multi_span_index<1>{2}); EXPECT_TRUE(sav.bounds().index_bounds() == multi_span_index<1>{2});
EXPECT_TRUE(sav[0] == 0); EXPECT_TRUE(sav[0] == 0);
EXPECT_TRUE(sav[1] == 3); EXPECT_TRUE(sav[1] == 3);
EXPECT_DEATH(sav[2], deathstring.data()); EXPECT_DEATH(sav[2], deathstring);
} }
{ {
// bounds cross data boundaries - from static arrays // bounds cross data boundaries - from static arrays
EXPECT_DEATH((strided_span<int, 1>{arr, {3, 2}}), deathstring.data()); EXPECT_DEATH((strided_span<int, 1>{arr, {3, 2}}), deathstring);
EXPECT_DEATH((strided_span<int, 1>{arr, {3, 3}}), deathstring.data()); EXPECT_DEATH((strided_span<int, 1>{arr, {3, 3}}), deathstring);
EXPECT_DEATH((strided_span<int, 1>{arr, {4, 5}}), deathstring.data()); EXPECT_DEATH((strided_span<int, 1>{arr, {4, 5}}), deathstring);
EXPECT_DEATH((strided_span<int, 1>{arr, {5, 1}}), deathstring.data()); EXPECT_DEATH((strided_span<int, 1>{arr, {5, 1}}), deathstring);
EXPECT_DEATH((strided_span<int, 1>{arr, {5, 5}}), deathstring.data()); EXPECT_DEATH((strided_span<int, 1>{arr, {5, 5}}), deathstring);
} }
{ {
// bounds cross data boundaries - from array view // bounds cross data boundaries - from array view
EXPECT_DEATH((strided_span<int, 1>{av, {3, 2}}), deathstring.data()); EXPECT_DEATH((strided_span<int, 1>{av, {3, 2}}), deathstring);
EXPECT_DEATH((strided_span<int, 1>{av, {3, 3}}), deathstring.data()); EXPECT_DEATH((strided_span<int, 1>{av, {3, 3}}), deathstring);
EXPECT_DEATH((strided_span<int, 1>{av, {4, 5}}), deathstring.data()); EXPECT_DEATH((strided_span<int, 1>{av, {4, 5}}), deathstring);
EXPECT_DEATH((strided_span<int, 1>{av, {5, 1}}), deathstring.data()); EXPECT_DEATH((strided_span<int, 1>{av, {5, 1}}), deathstring);
EXPECT_DEATH((strided_span<int, 1>{av, {5, 5}}), deathstring.data()); EXPECT_DEATH((strided_span<int, 1>{av, {5, 5}}), deathstring);
} }
{ {
// bounds cross data boundaries - from dynamic arrays // bounds cross data boundaries - from dynamic arrays
EXPECT_DEATH((strided_span<int, 1>{av.data(), 4, {3, 2}}), deathstring.data()); EXPECT_DEATH((strided_span<int, 1>{av.data(), 4, {3, 2}}), deathstring);
EXPECT_DEATH((strided_span<int, 1>{av.data(), 4, {3, 3}}), deathstring.data()); EXPECT_DEATH((strided_span<int, 1>{av.data(), 4, {3, 3}}), deathstring);
EXPECT_DEATH((strided_span<int, 1>{av.data(), 4, {4, 5}}), deathstring.data()); EXPECT_DEATH((strided_span<int, 1>{av.data(), 4, {4, 5}}), deathstring);
EXPECT_DEATH((strided_span<int, 1>{av.data(), 4, {5, 1}}), deathstring.data()); EXPECT_DEATH((strided_span<int, 1>{av.data(), 4, {5, 1}}), deathstring);
EXPECT_DEATH((strided_span<int, 1>{av.data(), 4, {5, 5}}), deathstring.data()); EXPECT_DEATH((strided_span<int, 1>{av.data(), 4, {5, 5}}), deathstring);
EXPECT_DEATH((strided_span<int, 1>{av.data(), 2, {2, 2}}), deathstring.data()); EXPECT_DEATH((strided_span<int, 1>{av.data(), 2, {2, 2}}), deathstring);
} }
#ifdef CONFIRM_COMPILATION_ERRORS #ifdef CONFIRM_COMPILATION_ERRORS
@ -569,8 +569,8 @@ TEST(strided_span_tests, strided_span_type_conversion)
strided_span<const int, 2> sav3 = sav2.as_strided_span<const int>(); strided_span<const int, 2> sav3 = sav2.as_strided_span<const int>();
EXPECT_TRUE(sav3[0][0] == 0); EXPECT_TRUE(sav3[0][0] == 0);
EXPECT_TRUE(sav3[1][0] == 2); EXPECT_TRUE(sav3[1][0] == 2);
EXPECT_DEATH(sav3[1][1], deathstring.data()); EXPECT_DEATH(sav3[1][1], deathstring);
EXPECT_DEATH(sav3[0][1], deathstring.data()); EXPECT_DEATH(sav3[0][1], deathstring);
} }
// retype strided array with regular strides - from multi_span // retype strided array with regular strides - from multi_span
@ -582,8 +582,8 @@ TEST(strided_span_tests, strided_span_type_conversion)
strided_span<int, 2> sav3 = sav2.as_strided_span<int>(); strided_span<int, 2> sav3 = sav2.as_strided_span<int>();
EXPECT_TRUE(sav3[0][0] == 0); EXPECT_TRUE(sav3[0][0] == 0);
EXPECT_TRUE(sav3[1][0] == 2); EXPECT_TRUE(sav3[1][0] == 2);
EXPECT_DEATH(sav3[1][1], deathstring.data()); EXPECT_DEATH(sav3[1][1], deathstring);
EXPECT_DEATH(sav3[0][1], deathstring.data()); EXPECT_DEATH(sav3[0][1], deathstring);
} }
// retype strided array with not enough elements - last dimension of the array is too small // retype strided array with not enough elements - last dimension of the array is too small
@ -592,7 +592,7 @@ TEST(strided_span_tests, strided_span_type_conversion)
multi_span<const byte, 2, dynamic_range> bytes2 = multi_span<const byte, 2, dynamic_range> bytes2 =
as_multi_span(bytes, dim<2>(), dim(bytes.size() / 2)); as_multi_span(bytes, dim<2>(), dim(bytes.size() / 2));
strided_span<const byte, 2> sav2{bytes2, bounds}; strided_span<const byte, 2> sav2{bytes2, bounds};
EXPECT_DEATH(sav2.as_strided_span<int>(), deathstring.data()); EXPECT_DEATH(sav2.as_strided_span<int>(), deathstring);
} }
// retype strided array with not enough elements - strides are too small // retype strided array with not enough elements - strides are too small
@ -601,7 +601,7 @@ TEST(strided_span_tests, strided_span_type_conversion)
multi_span<const byte, 2, dynamic_range> bytes2 = multi_span<const byte, 2, dynamic_range> bytes2 =
as_multi_span(bytes, dim<2>(), dim(bytes.size() / 2)); as_multi_span(bytes, dim<2>(), dim(bytes.size() / 2));
strided_span<const byte, 2> sav2{bytes2, bounds}; strided_span<const byte, 2> sav2{bytes2, bounds};
EXPECT_DEATH(sav2.as_strided_span<int>(), deathstring.data()); EXPECT_DEATH(sav2.as_strided_span<int>(), deathstring);
} }
// retype strided array with not enough elements - last dimension does not divide by the new // retype strided array with not enough elements - last dimension does not divide by the new
@ -611,7 +611,7 @@ TEST(strided_span_tests, strided_span_type_conversion)
multi_span<const byte, 2, dynamic_range> bytes2 = multi_span<const byte, 2, dynamic_range> bytes2 =
as_multi_span(bytes, dim<2>(), dim(bytes.size() / 2)); as_multi_span(bytes, dim<2>(), dim(bytes.size() / 2));
strided_span<const byte, 2> sav2{bytes2, bounds}; strided_span<const byte, 2> sav2{bytes2, bounds};
EXPECT_DEATH(sav2.as_strided_span<int>(), deathstring.data()); EXPECT_DEATH(sav2.as_strided_span<int>(), deathstring);
} }
// retype strided array with not enough elements - strides does not divide by the new // retype strided array with not enough elements - strides does not divide by the new
@ -621,21 +621,21 @@ TEST(strided_span_tests, strided_span_type_conversion)
multi_span<const byte, 2, dynamic_range> bytes2 = multi_span<const byte, 2, dynamic_range> bytes2 =
as_multi_span(bytes, dim<2>(), dim(bytes.size() / 2)); as_multi_span(bytes, dim<2>(), dim(bytes.size() / 2));
strided_span<const byte, 2> sav2{bytes2, bounds}; strided_span<const byte, 2> sav2{bytes2, bounds};
EXPECT_DEATH(sav2.as_strided_span<int>(), deathstring.data()); EXPECT_DEATH(sav2.as_strided_span<int>(), deathstring);
} }
// retype strided array with irregular strides - from raw data // retype strided array with irregular strides - from raw data
{ {
strided_bounds<1> bounds{bytes.size() / 2, 2}; strided_bounds<1> bounds{bytes.size() / 2, 2};
strided_span<const byte, 1> sav2{bytes.data(), bytes.size(), bounds}; strided_span<const byte, 1> sav2{bytes.data(), bytes.size(), bounds};
EXPECT_DEATH(sav2.as_strided_span<int>(), deathstring.data()); EXPECT_DEATH(sav2.as_strided_span<int>(), deathstring);
} }
// retype strided array with irregular strides - from multi_span // retype strided array with irregular strides - from multi_span
{ {
strided_bounds<1> bounds{bytes.size() / 2, 2}; strided_bounds<1> bounds{bytes.size() / 2, 2};
strided_span<const byte, 1> sav2{bytes, bounds}; strided_span<const byte, 1> sav2{bytes, bounds};
EXPECT_DEATH(sav2.as_strided_span<int>(), deathstring.data()); EXPECT_DEATH(sav2.as_strided_span<int>(), deathstring);
} }
} }
@ -652,9 +652,9 @@ TEST(strided_span_tests, empty_strided_spans)
EXPECT_TRUE(empty_sav.bounds().index_bounds() == multi_span_index<1>{0}); EXPECT_TRUE(empty_sav.bounds().index_bounds() == multi_span_index<1>{0});
EXPECT_TRUE(empty_sav.empty()); EXPECT_TRUE(empty_sav.empty());
EXPECT_DEATH(empty_sav[0], deathstring.data()); EXPECT_DEATH(empty_sav[0], deathstring);
EXPECT_DEATH(empty_sav.begin()[0], deathstring.data()); EXPECT_DEATH(empty_sav.begin()[0], deathstring);
EXPECT_DEATH(empty_sav.cbegin()[0], deathstring.data()); EXPECT_DEATH(empty_sav.cbegin()[0], deathstring);
for (const auto& v : empty_sav) { for (const auto& v : empty_sav) {
(void) v; (void) v;
@ -666,9 +666,9 @@ TEST(strided_span_tests, empty_strided_spans)
strided_span<int, 1> empty_sav{nullptr, 0, {0, 1}}; strided_span<int, 1> empty_sav{nullptr, 0, {0, 1}};
EXPECT_TRUE(empty_sav.bounds().index_bounds() == multi_span_index<1>{0}); EXPECT_TRUE(empty_sav.bounds().index_bounds() == multi_span_index<1>{0});
EXPECT_DEATH(empty_sav[0], deathstring.data()); EXPECT_DEATH(empty_sav[0], deathstring);
EXPECT_DEATH(empty_sav.begin()[0], deathstring.data()); EXPECT_DEATH(empty_sav.begin()[0], deathstring);
EXPECT_DEATH(empty_sav.cbegin()[0], deathstring.data()); EXPECT_DEATH(empty_sav.cbegin()[0], deathstring);
for (const auto& v : empty_sav) { for (const auto& v : empty_sav) {
(void) v; (void) v;
@ -804,7 +804,7 @@ TEST(strided_span_tests, strided_span_conversion)
strided_span<int, 1> result = transposed[0]; strided_span<int, 1> result = transposed[0];
EXPECT_TRUE(result.bounds().index_bounds()[0] == 4); EXPECT_TRUE(result.bounds().index_bounds()[0] == 4);
EXPECT_DEATH(result.bounds().index_bounds()[1], deathstring.data()); EXPECT_DEATH(result.bounds().index_bounds()[1], deathstring);
int i = 0; int i = 0;
for (auto& num : result) { for (auto& num : result) {

View File

@ -72,7 +72,7 @@ auto strnlen(const CharT* s, std::size_t n)
namespace namespace
{ {
constexpr std::string_view deathstring("Expected Death"); static const std::string deathstring("Expected Death");
template <typename T> template <typename T>
T move_wrapper(T&& t) T move_wrapper(T&& t)
@ -988,7 +988,7 @@ TEST(string_span_tests, zstring)
buf[0] = 'a'; buf[0] = 'a';
auto workaround_macro = [&]() { const zstring_span<> zspan({buf, 1}); }; auto workaround_macro = [&]() { const zstring_span<> zspan({buf, 1}); };
EXPECT_DEATH(workaround_macro(), deathstring.data()); EXPECT_DEATH(workaround_macro(), deathstring);
} }
// usage scenario: create zero-terminated temp file name and pass to a legacy API // usage scenario: create zero-terminated temp file name and pass to a legacy API
@ -1029,7 +1029,7 @@ TEST(string_span_tests, wzstring)
buf[0] = L'a'; buf[0] = L'a';
const auto workaround_macro = [&]() { const wzstring_span<> zspan({buf, 1}); }; const auto workaround_macro = [&]() { const wzstring_span<> zspan({buf, 1}); };
EXPECT_DEATH(workaround_macro(), deathstring.data()); EXPECT_DEATH(workaround_macro(), deathstring);
} }
// usage scenario: create zero-terminated temp file name and pass to a legacy API // usage scenario: create zero-terminated temp file name and pass to a legacy API
@ -1070,7 +1070,7 @@ TEST(string_span_tests, u16zstring)
buf[0] = u'a'; buf[0] = u'a';
const auto workaround_macro = [&]() { const u16zstring_span<> zspan({buf, 1}); }; const auto workaround_macro = [&]() { const u16zstring_span<> zspan({buf, 1}); };
EXPECT_DEATH(workaround_macro(), deathstring.data()); EXPECT_DEATH(workaround_macro(), deathstring);
} }
// usage scenario: create zero-terminated temp file name and pass to a legacy API // usage scenario: create zero-terminated temp file name and pass to a legacy API
@ -1111,7 +1111,7 @@ TEST(string_span_tests, u32zstring)
buf[0] = u'a'; buf[0] = u'a';
const auto workaround_macro = [&]() { const u32zstring_span<> zspan({buf, 1}); }; const auto workaround_macro = [&]() { const u32zstring_span<> zspan({buf, 1}); };
EXPECT_DEATH(workaround_macro(), deathstring.data()); EXPECT_DEATH(workaround_macro(), deathstring);
} }
// usage scenario: create zero-terminated temp file name and pass to a legacy API // usage scenario: create zero-terminated temp file name and pass to a legacy API

View File

@ -45,7 +45,7 @@
using namespace gsl; using namespace gsl;
namespace{ namespace{
constexpr std::string_view deathstring("Expected Death"); static const std::string deathstring("Expected Death");
void f(int& i) { i += 1; } void f(int& i) { i += 1; }
static int j = 0; static int j = 0;
void g() { j += 1; } void g() { j += 1; }
@ -130,7 +130,7 @@ TEST(utils_tests, narrow)
EXPECT_TRUE(c == 120); EXPECT_TRUE(c == 120);
n = 300; n = 300;
EXPECT_DEATH(narrow<char>(n), deathstring.data()); EXPECT_DEATH(narrow<char>(n), deathstring);
const auto int32_max = std::numeric_limits<int32_t>::max(); const auto int32_max = std::numeric_limits<int32_t>::max();
const auto int32_min = std::numeric_limits<int32_t>::min(); const auto int32_min = std::numeric_limits<int32_t>::min();
@ -139,11 +139,11 @@ TEST(utils_tests, narrow)
EXPECT_TRUE(narrow<uint32_t>(int32_t(1)) == 1); EXPECT_TRUE(narrow<uint32_t>(int32_t(1)) == 1);
EXPECT_TRUE(narrow<uint32_t>(int32_max) == static_cast<uint32_t>(int32_max)); EXPECT_TRUE(narrow<uint32_t>(int32_max) == static_cast<uint32_t>(int32_max));
EXPECT_DEATH(narrow<uint32_t>(int32_t(-1)), deathstring.data()); EXPECT_DEATH(narrow<uint32_t>(int32_t(-1)), deathstring);
EXPECT_DEATH(narrow<uint32_t>(int32_min), deathstring.data()); EXPECT_DEATH(narrow<uint32_t>(int32_min), deathstring);
n = -42; n = -42;
EXPECT_DEATH(narrow<unsigned>(n), deathstring.data()); EXPECT_DEATH(narrow<unsigned>(n), deathstring);
#if GSL_CONSTEXPR_NARROW #if GSL_CONSTEXPR_NARROW
static_assert(narrow<char>(120) == 120, "Fix GSL_CONSTEXPR_NARROW"); static_assert(narrow<char>(120) == 120, "Fix GSL_CONSTEXPR_NARROW");