Skip to content

Commit

Permalink
changing text in notices & readme. adding terminate handler for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanMaples committed Dec 12, 2019
1 parent ec05ecd commit 4f6f05d
Show file tree
Hide file tree
Showing 15 changed files with 451 additions and 216 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -18,7 +18,7 @@ other platforms. Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for more inform
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

# Usage of Third Party Libraries
This project makes use of the [Catch](https://github.com/philsquared/catch) testing library. Please see the [ThirdPartyNotices.txt](./ThirdPartyNotices.txt) file for details regarding the licensing of Catch.
This project makes use of the [Google Test](https://github.com/google/gooletest) testing library. Please see the [ThirdPartyNotices.txt](./ThirdPartyNotices.txt) file for details regarding the licensing of Google Test.

# Quick Start
## Supported Platforms
Expand Down
2 changes: 0 additions & 2 deletions ThirdPartyNotices.txt
Expand Up @@ -3,8 +3,6 @@ THIRD-PARTY SOFTWARE NOTICES AND INFORMATION
Do Not Translate or Localize

GSL: Guidelines Support Library incorporates third party material from the projects listed below.
The original copyright notice and the license under which Microsoft received such third party material are set forth below.
Microsoft reserves all other rights not expressly granted, whether by implication, estoppel or otherwise.

-------------------------------------------------------------------------------
Software: Google Test
Expand Down
4 changes: 2 additions & 2 deletions tests/CMakeLists.txt
Expand Up @@ -188,5 +188,5 @@ function(add_gsl_test_noexcept name)
set_property(TARGET ${name} PROPERTY FOLDER "GSL_tests_noexcept")
endfunction()

# add_gsl_test_noexcept(no_exception_throw_tests)
# add_gsl_test_noexcept(no_exception_ensure_tests)
add_gsl_test_noexcept(no_exception_throw_tests)
add_gsl_test_noexcept(no_exception_ensure_tests)
48 changes: 33 additions & 15 deletions tests/algorithm_tests.cpp
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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]);
}
Expand All @@ -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]);
}
Expand All @@ -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]);
}
Expand All @@ -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]);
}
Expand All @@ -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]);
}
Expand All @@ -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]);
}
Expand All @@ -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]);
}
Expand All @@ -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]);
}
Expand Down Expand Up @@ -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{};

Expand All @@ -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);
Expand Down
18 changes: 15 additions & 3 deletions tests/assertion_tests.cpp
Expand Up @@ -34,7 +34,7 @@
#include <gtest/gtest.h>

#include <gsl/gsl_assert> // for fail_fast (ptr only), Ensures, Expects

#include <string_view>
using namespace gsl;

namespace
Expand All @@ -51,19 +51,31 @@ int g(int i)
Ensures(i > 0 && i < 10);
return i;
}

constexpr std::string_view deathstring("Expected Death");
} // namespace

TEST(assertion_tests, expects)
{
std::set_terminate([] {
std::cerr << "Expected Death. expects";
std::abort();
});

EXPECT_TRUE(f(2) == 2);
EXPECT_DEATH(f(10), ".*");
EXPECT_DEATH(f(10), deathstring.data());
}


TEST(assertion_tests, ensures)
{
std::set_terminate([] {
std::cerr << "Expected Death. ensures";
std::abort();
});

EXPECT_TRUE(g(2) == 3);
EXPECT_DEATH(g(9), ".*");
EXPECT_DEATH(g(9), deathstring.data());
}

#if __clang__ || __GNUC__
Expand Down
60 changes: 42 additions & 18 deletions tests/at_tests.cpp
Expand Up @@ -40,6 +40,10 @@
#include <initializer_list> // for initializer_list
#include <vector> // for vector

namespace{
constexpr std::string_view deathstring("Expected Death");
}

TEST(at_tests, static_array)
{
int a[4] = {1, 2, 3, 4};
Expand All @@ -50,10 +54,15 @@ TEST(at_tests, static_array)
EXPECT_TRUE(&gsl::at(c_a, i) == &a[i]);
}

EXPECT_DEATH(gsl::at(a, -1), ".*");
EXPECT_DEATH(gsl::at(a, 4), ".*");
EXPECT_DEATH(gsl::at(c_a, -1), ".*");
EXPECT_DEATH(gsl::at(c_a, 4), ".*");
std::set_terminate([] {
std::cerr << "Expected Death. static_array";
std::abort();
});

EXPECT_DEATH(gsl::at(a, -1), deathstring.data());
EXPECT_DEATH(gsl::at(a, 4), deathstring.data());
EXPECT_DEATH(gsl::at(c_a, -1), deathstring.data());
EXPECT_DEATH(gsl::at(c_a, 4), deathstring.data());
}

TEST(at_tests, std_array)
Expand All @@ -66,13 +75,18 @@ TEST(at_tests, std_array)
EXPECT_TRUE(&gsl::at(c_a, i) == &a[static_cast<std::size_t>(i)]);
}

EXPECT_DEATH(gsl::at(a, -1), ".*");
EXPECT_DEATH(gsl::at(a, 4), ".*");
EXPECT_DEATH(gsl::at(c_a, -1), ".*");
EXPECT_DEATH(gsl::at(c_a, 4), ".*");
std::set_terminate([] {
std::cerr << "Expected Death. std_array";
std::abort();
});

EXPECT_DEATH(gsl::at(a, -1), deathstring.data());
EXPECT_DEATH(gsl::at(a, 4), deathstring.data());
EXPECT_DEATH(gsl::at(c_a, -1), deathstring.data());
EXPECT_DEATH(gsl::at(c_a, 4), deathstring.data());
}

TEST(at_tests, StdVector)
TEST(at_tests, std_vector)
{
std::vector<int> a = {1, 2, 3, 4};
const std::vector<int>& c_a = a;
Expand All @@ -82,10 +96,15 @@ TEST(at_tests, StdVector)
EXPECT_TRUE(&gsl::at(c_a, i) == &a[static_cast<std::size_t>(i)]);
}

EXPECT_DEATH(gsl::at(a, -1), ".*");
EXPECT_DEATH(gsl::at(a, 4), ".*");
EXPECT_DEATH(gsl::at(c_a, -1), ".*");
EXPECT_DEATH(gsl::at(c_a, 4), ".*");
std::set_terminate([] {
std::cerr << "Expected Death. std_vector";
std::abort();
});

EXPECT_DEATH(gsl::at(a, -1), deathstring.data());
EXPECT_DEATH(gsl::at(a, 4), deathstring.data());
EXPECT_DEATH(gsl::at(c_a, -1), deathstring.data());
EXPECT_DEATH(gsl::at(c_a, 4), deathstring.data());
}

TEST(at_tests, InitializerList)
Expand All @@ -96,11 +115,16 @@ TEST(at_tests, InitializerList)
EXPECT_TRUE(gsl::at(a, i) == i + 1);
EXPECT_TRUE(gsl::at({1, 2, 3, 4}, i) == i + 1);
}

EXPECT_DEATH(gsl::at(a, -1), ".*");
EXPECT_DEATH(gsl::at(a, 4), ".*");
EXPECT_DEATH(gsl::at({1, 2, 3, 4}, -1), ".*");
EXPECT_DEATH(gsl::at({1, 2, 3, 4}, 4), ".*");

std::set_terminate([] {
std::cerr << "Expected Death. InitializerList";
std::abort();
});

EXPECT_DEATH(gsl::at(a, -1), deathstring.data());
EXPECT_DEATH(gsl::at(a, 4), deathstring.data());
EXPECT_DEATH(gsl::at({1, 2, 3, 4}, -1), deathstring.data());
EXPECT_DEATH(gsl::at({1, 2, 3, 4}, 4), deathstring.data());
}

#if !defined(_MSC_VER) || defined(__clang__) || _MSC_VER >= 1910
Expand Down
5 changes: 5 additions & 0 deletions tests/bounds_tests.cpp
Expand Up @@ -107,6 +107,11 @@ TEST(bounds_tests, bounds_convertible)
static_bounds<dynamic_range> b5;
static_bounds<34> b6;

std::set_terminate([] {
std::cerr << "Expected Death. bounds_convertible";
std::abort();
});

b5 = static_bounds<20>();
EXPECT_DEATH(b6 = b5, ".*");
b5 = static_bounds<34>();
Expand Down

0 comments on commit 4f6f05d

Please sign in to comment.