diff options
author | Jordan Maples [MSFT] <49793787+JordanMaples@users.noreply.github.com> | 2019-12-12 21:55:26 +0300 |
---|---|---|
committer | Jordan Maples [MSFT] <49793787+JordanMaples@users.noreply.github.com> | 2019-12-12 21:55:26 +0300 |
commit | 4f6f05d463780b94811d974426c1aef95b3db39b (patch) | |
tree | 7afff9111fdc0e061b28eb9484b8e5606a5d4f68 /tests/algorithm_tests.cpp | |
parent | ec05ecd6b145d1bf2473689408279c2e2685c94f (diff) |
changing text in notices & readme. adding terminate handler for tests
Diffstat (limited to 'tests/algorithm_tests.cpp')
-rw-r--r-- | tests/algorithm_tests.cpp | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/tests/algorithm_tests.cpp b/tests/algorithm_tests.cpp index eb6641c..299bb96 100644 --- a/tests/algorithm_tests.cpp +++ b/tests/algorithm_tests.cpp @@ -21,7 +21,7 @@ #endif #if __clang__ || __GNUC__ -//disable warnings from gtest +// disable warnings from gtest #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wundef" #endif @@ -34,13 +34,18 @@ #include <gsl/gsl_algorithm> // for copy #include <gsl/span> // for span - #include <array> // for array +#include <string_view> #include <cstddef> // for size_t -namespace gsl { +namespace{ +constexpr std::string_view deathstring("Expected Death"); +} + +namespace gsl +{ struct fail_fast; -} // namespace gsl +} // namespace gsl using namespace std; using namespace gsl; @@ -58,7 +63,8 @@ TEST(algorithm_tests, same_type) copy(src_span, dst_span); copy(src_span, dst_span.subspan(src_span.size())); - for (std::size_t i = 0; i < src.size(); ++i) { + for (std::size_t i = 0; i < src.size(); ++i) + { EXPECT_TRUE(dst[i] == src[i]); EXPECT_TRUE(dst[i + src.size()] == src[i]); } @@ -75,7 +81,8 @@ TEST(algorithm_tests, same_type) copy(src_span, dst_span); copy(src_span, dst_span.subspan(src_span.size())); - for (std::size_t i = 0; i < src.size(); ++i) { + for (std::size_t i = 0; i < src.size(); ++i) + { EXPECT_TRUE(dst[i] == src[i]); EXPECT_TRUE(dst[i + src.size()] == src[i]); } @@ -92,7 +99,8 @@ TEST(algorithm_tests, same_type) copy(src_span, dst_span); copy(src_span, dst_span.subspan(src_span.size())); - for (std::size_t i = 0; i < src.size(); ++i) { + for (std::size_t i = 0; i < src.size(); ++i) + { EXPECT_TRUE(dst[i] == src[i]); EXPECT_TRUE(dst[i + src.size()] == src[i]); } @@ -109,7 +117,8 @@ TEST(algorithm_tests, same_type) copy(src_span, dst_span); copy(src_span, dst_span.subspan(src_span.size())); - for (std::size_t i = 0; i < src.size(); ++i) { + for (std::size_t i = 0; i < src.size(); ++i) + { EXPECT_TRUE(dst[i] == src[i]); EXPECT_TRUE(dst[i + src.size()] == src[i]); } @@ -129,7 +138,8 @@ TEST(algorithm_tests, compatible_type) copy(src_span, dst_span); copy(src_span, dst_span.subspan(src_span.size())); - for (std::size_t i = 0; i < src.size(); ++i) { + for (std::size_t i = 0; i < src.size(); ++i) + { EXPECT_TRUE(dst[i] == src[i]); EXPECT_TRUE(dst[i + src.size()] == src[i]); } @@ -146,7 +156,8 @@ TEST(algorithm_tests, compatible_type) copy(src_span, dst_span); copy(src_span, dst_span.subspan(src_span.size())); - for (std::size_t i = 0; i < src.size(); ++i) { + for (std::size_t i = 0; i < src.size(); ++i) + { EXPECT_TRUE(dst[i] == src[i]); EXPECT_TRUE(dst[i + src.size()] == src[i]); } @@ -163,7 +174,8 @@ TEST(algorithm_tests, compatible_type) copy(src_span, dst_span); copy(src_span, dst_span.subspan(src_span.size())); - for (std::size_t i = 0; i < src.size(); ++i) { + for (std::size_t i = 0; i < src.size(); ++i) + { EXPECT_TRUE(dst[i] == src[i]); EXPECT_TRUE(dst[i + src.size()] == src[i]); } @@ -180,7 +192,8 @@ TEST(algorithm_tests, compatible_type) copy(src_span, dst_span); copy(src_span, dst_span.subspan(src_span.size())); - for (std::size_t i = 0; i < src.size(); ++i) { + for (std::size_t i = 0; i < src.size(); ++i) + { EXPECT_TRUE(dst[i] == src[i]); EXPECT_TRUE(dst[i + src.size()] == src[i]); } @@ -208,6 +221,11 @@ TEST(algorithm_tests, incompatible_type) TEST(algorithm_tests, small_destination_span) { + std::set_terminate([] { + std::cerr << "Expected Death. small_destination_span"; + std::abort(); + }); + std::array<int, 12> src{1, 2, 3, 4}; std::array<int, 4> dst{}; @@ -216,9 +234,9 @@ TEST(algorithm_tests, small_destination_span) const span<int> dst_span_dyn(dst); const span<int, 4> dst_span_static(dst); - EXPECT_DEATH(copy(src_span_dyn, dst_span_dyn), ".*"); - EXPECT_DEATH(copy(src_span_dyn, dst_span_static), ".*"); - EXPECT_DEATH(copy(src_span_static, dst_span_dyn), ".*"); + EXPECT_DEATH(copy(src_span_dyn, dst_span_dyn), deathstring.data()); + EXPECT_DEATH(copy(src_span_dyn, dst_span_static), deathstring.data()); + EXPECT_DEATH(copy(src_span_static, dst_span_dyn), deathstring.data()); #ifdef CONFIRM_COMPILATION_ERRORS copy(src_span_static, dst_span_static); |