diff --git a/.gitignore b/.gitignore
index ee5ca3c..cbb4a5c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,6 @@
CMakeFiles
+build
+include/catch
tests/CMakeFiles
tests/Debug
*.opensdf
diff --git a/.gitmodules b/.gitmodules
deleted file mode 100644
index b198402..0000000
--- a/.gitmodules
+++ /dev/null
@@ -1,3 +0,0 @@
-[submodule "tests/unittest-cpp"]
- path = tests/unittest-cpp
- url = https://github.com/unittest-cpp/unittest-cpp.git
diff --git a/.travis.yml b/.travis.yml
index 53d110d..82b8ec2 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -10,7 +10,7 @@ cache:
- ${TRAVIS_BUILD_DIR}/deps/llvm-3.6.2/install
- ${TRAVIS_BUILD_DIR}/deps/llvm-3.7.1/install
- ${TRAVIS_BUILD_DIR}/deps/llvm-3.8.1/install
- - ${TRAVIS_BUILD_DIR}/deps/llvm-3.9.0/install
+ - ${TRAVIS_BUILD_DIR}/deps/llvm-3.9.1/install
matrix:
include:
@@ -61,6 +61,19 @@ matrix:
- env: CLANG_VERSION=3.8 BUILD_TYPE=Release
os: linux
addons: *clang38
+ - env: CLANG_VERSION=3.9 BUILD_TYPE=Debug
+ os: linux
+ addons: &clang39
+ apt:
+ packages:
+ - clang-3.9
+ - g++-5
+ sources: &sources
+ - ubuntu-toolchain-r-test
+ - llvm-toolchain-precise-3.9
+ - env: CLANG_VERSION=3.9 BUILD_TYPE=Release
+ os: linux
+ addons: *clang39
- env: GCC_VERSION=5 BUILD_TYPE=Debug
os: linux
addons: &gcc5
@@ -110,7 +123,7 @@ install:
if [[ "$CLANG_VERSION" == "3.6" ]]; then LLVM_VERSION="3.6.2"; fi
if [[ "$CLANG_VERSION" == "3.7" ]]; then LLVM_VERSION="3.7.1"; fi
if [[ "$CLANG_VERSION" == "3.8" ]]; then LLVM_VERSION="3.8.1"; fi
- if [[ "$CLANG_VERSION" == "3.9" ]]; then LLVM_VERSION="3.9.0"; fi
+ if [[ "$CLANG_VERSION" == "3.9" ]]; then LLVM_VERSION="3.9.1"; fi
LLVM_ROOT="${DEPS_DIR}/llvm-${LLVM_VERSION}"
LLVM_URL="http://llvm.org/releases/${LLVM_VERSION}/llvm-${LLVM_VERSION}.src.tar.xz"
LIBCXX_URL="http://llvm.org/releases/${LLVM_VERSION}/libcxx-${LLVM_VERSION}.src.tar.xz"
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e4e4e48..e62a1d6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,13 +1,16 @@
-cmake_minimum_required(VERSION 2.8.7)
+cmake_minimum_required(VERSION 3.1.3)
project(GSL CXX)
+include(ExternalProject)
+find_package(Git REQUIRED)
+
# creates a library GSL which is an interface (header files only)
add_library(GSL INTERFACE)
# when minimum version required is 3.8.0 remove if below
# both branches do exactly the same thing
-if ( CMAKE_MAJOR_VERSION VERSION_LESS 3.7.9)
+if (CMAKE_MAJOR_VERSION VERSION_LESS 3.7.9)
if (NOT MSVC)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
@@ -16,7 +19,7 @@ if ( CMAKE_MAJOR_VERSION VERSION_LESS 3.7.9)
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++14 support. Please use a different C++ compiler.")
endif()
-
+
endif()
else ()
# set the GSL library to be compiled only with c++14
@@ -41,7 +44,7 @@ target_include_directories(GSL INTERFACE
)
# add natvis file to the library so it will automatically be loaded into Visual Studio
-target_sources(GSL INTERFACE
+target_sources(GSL INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/GSL.natvis
)
diff --git a/README.md b/README.md
index 9b7ae92..3b830c5 100644
--- a/README.md
+++ b/README.md
@@ -17,6 +17,9 @@ other platforms. Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for more inform
# Project Code of Conduct
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.
+
# Quick Start
## Supported Platforms
The test suite that exercises GSL has been built and passes successfully on the following platforms:1)
@@ -40,9 +43,7 @@ contributing any changes that were necessary back to this project to benefit the
## Building the tests
To build the tests, you will require the following:
-* [CMake](http://cmake.org), version 2.8.7 or later to be installed and in your PATH.
-* [UnitTest-cpp](https://github.com/Microsoft/unittest-cpp), to be cloned under the [tests/unittest-cpp](./tests/unittest-cpp) directory
-of your GSL source.
+* [CMake](http://cmake.org), version 3.1.3 or later to be installed and in your PATH.
These steps assume the source code of this repository has been cloned into a directory named `c:\GSL`.
@@ -56,11 +57,11 @@ These steps assume the source code of this repository has been cloned into a dir
cmake -G "Visual Studio 14 2015" c:\GSL
-3. Build the test suite (in this case, in the Debug configuration, Release is another good choice).
+3. Build the test suite (in this case, in the Debug configuration, Release is another good choice).
cmake --build . --config Debug
-4. Run the test suite.
+4. Run the test suite.
ctest -C Debug
diff --git a/ThirdPartyNotices.txt b/ThirdPartyNotices.txt
new file mode 100644
index 0000000..94b9acc
--- /dev/null
+++ b/ThirdPartyNotices.txt
@@ -0,0 +1,39 @@
+
+THIRD-PARTY SOFTWARE NOTICES AND INFORMATION
+Do Not Translate or Localize
+
+GSL: Guideline 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.
+
+
+1. Catch (https://github.com/philsquared/Catch)
+
+
+%% Catch NOTICES, INFORMATION, AND LICENSE BEGIN HERE
+=========================================
+Boost Software License - Version 1.0 - August 17th, 2003
+
+Permission is hereby granted, free of charge, to any person or organization
+obtaining a copy of the software and accompanying documentation covered by
+this license (the "Software") to use, reproduce, display, distribute,
+execute, and transmit the Software, and to prepare derivative works of the
+Software, and to permit third-parties to whom the Software is furnished to
+do so, all subject to the following:
+
+The copyright notices in the Software and this entire statement, including
+the above license grant, this restriction and the following disclaimer,
+must be included in all copies of the Software, in whole or in part, and
+all derivative works of the Software, unless such copies or derivative
+works are solely in the form of machine-executable object code generated by
+a source language processor.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+=========================================
+END OF Catch NOTICES, INFORMATION, AND LICENSE
+
+
diff --git a/appveyor.yml b/appveyor.yml
index 5acfd11..d978a5d 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -13,16 +13,15 @@ image:
- Visual Studio 2017
cache:
- - C:\cmake-3.7.2-win32-x86
+ - C:\cmake-3.8.0-win32-x86
install:
- - git clone --quiet --depth=1 https://github.com/Microsoft/unittest-cpp.git tests/unittest-cpp
- ps: |
- if (![IO.File]::Exists("C:\cmake-3.7.2-win32-x86\bin\cmake.exe")) {
- Start-FileDownload 'https://cmake.org/files/v3.7/cmake-3.7.2-win32-x86.zip'
- 7z x -y cmake-3.7.2-win32-x86.zip -oC:\
+ if (![IO.File]::Exists("C:\cmake-3.8.0-win32-x86\bin\cmake.exe")) {
+ Start-FileDownload 'https://cmake.org/files/v3.8/cmake-3.8.0-win32-x86.zip'
+ 7z x -y cmake-3.8.0-win32-x86.zip -oC:\
}
- $env:PATH="C:\cmake-3.7.2-win32-x86\bin;$env:PATH"
+ $env:PATH="C:\cmake-3.8.0-win32-x86\bin;$env:PATH"
before_build:
- ps: |
diff --git a/include/gsl/multi_span b/include/gsl/multi_span
index e381861..618c95e 100644
--- a/include/gsl/multi_span
+++ b/include/gsl/multi_span
@@ -41,6 +41,7 @@
// turn off some warnings that are noisy about our Expects statements
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
+#pragma warning(disable : 4702) // unreachable code
#if _MSC_VER < 1910
#pragma push_macro("constexpr")
diff --git a/include/gsl/span b/include/gsl/span
index 0d8841b..f3a76b1 100644
--- a/include/gsl/span
+++ b/include/gsl/span
@@ -37,6 +37,7 @@
// turn off some warnings that are noisy about our Expects statements
#pragma warning(disable : 4127) // conditional expression is constant
+#pragma warning(disable : 4702) // unreachable code
// blanket turn off warnings from CppCoreCheck for now
// so people aren't annoyed by them when running the tool.
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index eb08360..5306e85 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -5,15 +5,21 @@ project(GSLTests CXX)
# will make visual studio generated project group files
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
-if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/unittest-cpp/CMakeLists.txt)
- find_package(Git)
- execute_process(
- COMMAND ${GIT_EXECUTABLE} submodule update --init
- WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
- )
-endif()
+list(APPEND CATCH_CMAKE_ARGS
+ "-DCMAKE_INSTALL_PREFIX=${CMAKE_SOURCE_DIR}"
+ "-DNO_SELFTEST=true"
+)
-add_subdirectory(unittest-cpp)
+# add catch
+ExternalProject_Add(
+ catch
+ PREFIX ${CMAKE_BINARY_DIR}/catch
+ GIT_REPOSITORY https://github.com/philsquared/Catch.git
+ GIT_TAG v1.9.6
+ CMAKE_ARGS ${CATCH_CMAKE_ARGS}
+ LOG_DOWNLOAD 1
+ UPDATE_DISCONNECTED 1
+)
# this interface adds compile options to how the tests are run
# please try to keep entries ordered =)
@@ -42,24 +48,29 @@ target_compile_options(gsl_tests_config INTERFACE
>
)
-# set test to include the unittest-cpp headers
-# this shiuld be removed when UnitTest++ has the proper headers
-target_include_directories(gsl_tests_config INTERFACE
- ./unittest-cpp
-)
-
# set definitions for tests
target_compile_definitions(gsl_tests_config INTERFACE
GSL_THROW_ON_CONTRACT_VIOLATION
)
+# create the main executable for each test. this reduces the compile time
+# of each test by pre-compiling catch.
+add_library(test_catch STATIC test.cpp)
+target_link_libraries(test_catch
+ GSL
+ gsl_tests_config
+)
+add_dependencies(test_catch catch)
+set_property(TARGET test_catch PROPERTY FOLDER "GSL_tests")
+
function(add_gsl_test name)
add_executable(${name} ${name}.cpp)
target_link_libraries(${name}
- UnitTest++
GSL
+ test_catch
gsl_tests_config
)
+ add_dependencies(${name} catch)
add_test(
${name}
${name}
diff --git a/tests/algorithm_tests.cpp b/tests/algorithm_tests.cpp
index 7b5f429..045fd3e 100644
--- a/tests/algorithm_tests.cpp
+++ b/tests/algorithm_tests.cpp
@@ -14,7 +14,7 @@
//
///////////////////////////////////////////////////////////////////////////////
-#include
+#include
#include
@@ -23,188 +23,182 @@
using namespace std;
using namespace gsl;
-SUITE(copy_tests)
+TEST_CASE("same_type")
{
-
- TEST(same_type)
+ // dynamic source and destination span
{
- // dynamic source and destination span
- {
- std::array src{1, 2, 3, 4, 5};
- std::array dst{};
+ std::array src{1, 2, 3, 4, 5};
+ std::array dst{};
- span src_span(src);
- span dst_span(dst);
+ span src_span(src);
+ span dst_span(dst);
- copy(src_span, dst_span);
- copy(src_span, dst_span.subspan(src_span.size()));
+ copy(src_span, dst_span);
+ copy(src_span, dst_span.subspan(src_span.size()));
- for (std::size_t i = 0; i < src.size(); ++i) {
- CHECK(dst[i] == src[i]);
- CHECK(dst[i + src.size()] == src[i]);
- }
- }
-
- // static source and dynamic destination span
- {
- std::array src{1, 2, 3, 4, 5};
- std::array dst{};
-
- span src_span(src);
- span dst_span(dst);
-
- copy(src_span, dst_span);
- copy(src_span, dst_span.subspan(src_span.size()));
-
- for (std::size_t i = 0; i < src.size(); ++i) {
- CHECK(dst[i] == src[i]);
- CHECK(dst[i + src.size()] == src[i]);
- }
- }
-
- // dynamic source and static destination span
- {
- std::array src{1, 2, 3, 4, 5};
- std::array dst{};
-
- span src_span(src);
- span dst_span(dst);
-
- copy(src_span, dst_span);
- copy(src_span, dst_span.subspan(src_span.size()));
-
- for (std::size_t i = 0; i < src.size(); ++i) {
- CHECK(dst[i] == src[i]);
- CHECK(dst[i + src.size()] == src[i]);
- }
- }
-
- // static source and destination span
- {
- std::array src{1, 2, 3, 4, 5};
- std::array dst{};
-
- span src_span(src);
- span dst_span(dst);
-
- copy(src_span, dst_span);
- copy(src_span, dst_span.subspan(src_span.size()));
-
- for (std::size_t i = 0; i < src.size(); ++i) {
- CHECK(dst[i] == src[i]);
- CHECK(dst[i + src.size()] == src[i]);
- }
+ for (std::size_t i = 0; i < src.size(); ++i) {
+ CHECK(dst[i] == src[i]);
+ CHECK(dst[i + src.size()] == src[i]);
}
}
- TEST(compatible_type)
+ // static source and dynamic destination span
{
- // dynamic source and destination span
- {
- std::array src{1, 2, 3, 4, 5};
- std::array dst{};
+ std::array src{1, 2, 3, 4, 5};
+ std::array dst{};
- span src_span(src);
- span dst_span(dst);
+ span src_span(src);
+ span dst_span(dst);
- copy(src_span, dst_span);
- copy(src_span, dst_span.subspan(src_span.size()));
+ copy(src_span, dst_span);
+ copy(src_span, dst_span.subspan(src_span.size()));
- for (std::size_t i = 0; i < src.size(); ++i) {
- CHECK(dst[i] == src[i]);
- CHECK(dst[i + src.size()] == src[i]);
- }
- }
-
- // static source and dynamic destination span
- {
- std::array src{1, 2, 3, 4, 5};
- std::array dst{};
-
- span src_span(src);
- span dst_span(dst);
-
- copy(src_span, dst_span);
- copy(src_span, dst_span.subspan(src_span.size()));
-
- for (std::size_t i = 0; i < src.size(); ++i) {
- CHECK(dst[i] == src[i]);
- CHECK(dst[i + src.size()] == src[i]);
- }
- }
-
- // dynamic source and static destination span
- {
- std::array src{1, 2, 3, 4, 5};
- std::array dst{};
-
- span src_span(src);
- span dst_span(dst);
-
- copy(src_span, dst_span);
- copy(src_span, dst_span.subspan(src_span.size()));
-
- for (std::size_t i = 0; i < src.size(); ++i) {
- CHECK(dst[i] == src[i]);
- CHECK(dst[i + src.size()] == src[i]);
- }
- }
-
- // static source and destination span
- {
- std::array src{1, 2, 3, 4, 5};
- std::array dst{};
-
- span src_span(src);
- span dst_span(dst);
-
- copy(src_span, dst_span);
- copy(src_span, dst_span.subspan(src_span.size()));
-
- for (std::size_t i = 0; i < src.size(); ++i) {
- CHECK(dst[i] == src[i]);
- CHECK(dst[i + src.size()] == src[i]);
- }
+ for (std::size_t i = 0; i < src.size(); ++i) {
+ CHECK(dst[i] == src[i]);
+ CHECK(dst[i + src.size()] == src[i]);
}
}
-#ifdef CONFIRM_COMPILATION_ERRORS
- TEST(incompatible_type)
+ // dynamic source and static destination span
{
- std::array src{1, 2, 3, 4};
- std::array dst{};
+ std::array src{1, 2, 3, 4, 5};
+ std::array dst{};
- span src_span_dyn(src);
- span src_span_static(src);
- span dst_span_dyn(dst);
- span dst_span_static(dst);
+ span src_span(src);
+ span dst_span(dst);
- // every line should produce a compilation error
- copy(src_span_dyn, dst_span_dyn);
- copy(src_span_dyn, dst_span_static);
- copy(src_span_static, dst_span_dyn);
- copy(src_span_static, dst_span_static);
+ copy(src_span, dst_span);
+ copy(src_span, dst_span.subspan(src_span.size()));
+
+ for (std::size_t i = 0; i < src.size(); ++i) {
+ CHECK(dst[i] == src[i]);
+ CHECK(dst[i + src.size()] == src[i]);
+ }
}
-#endif
- TEST(small_destination_span)
+ // static source and destination span
{
- std::array src{1, 2, 3, 4};
- std::array dst{};
+ std::array src{1, 2, 3, 4, 5};
+ std::array dst{};
- span src_span_dyn(src);
- span src_span_static(src);
- span dst_span_dyn(dst);
- span dst_span_static(dst);
+ span src_span(src);
+ span dst_span(dst);
- CHECK_THROW(copy(src_span_dyn, dst_span_dyn), fail_fast);
- CHECK_THROW(copy(src_span_dyn, dst_span_static), fail_fast);
- CHECK_THROW(copy(src_span_static, dst_span_dyn), fail_fast);
+ copy(src_span, dst_span);
+ copy(src_span, dst_span.subspan(src_span.size()));
-#ifdef CONFIRM_COMPILATION_ERRORS
- copy(src_span_static, dst_span_static);
-#endif
+ for (std::size_t i = 0; i < src.size(); ++i) {
+ CHECK(dst[i] == src[i]);
+ CHECK(dst[i + src.size()] == src[i]);
+ }
}
}
-int main() { return UnitTest::RunAllTests(); }
+TEST_CASE("compatible_type")
+{
+ // dynamic source and destination span
+ {
+ std::array src{1, 2, 3, 4, 5};
+ std::array dst{};
+
+ span src_span(src);
+ span dst_span(dst);
+
+ copy(src_span, dst_span);
+ copy(src_span, dst_span.subspan(src_span.size()));
+
+ for (std::size_t i = 0; i < src.size(); ++i) {
+ CHECK(dst[i] == src[i]);
+ CHECK(dst[i + src.size()] == src[i]);
+ }
+ }
+
+ // static source and dynamic destination span
+ {
+ std::array src{1, 2, 3, 4, 5};
+ std::array dst{};
+
+ span src_span(src);
+ span dst_span(dst);
+
+ copy(src_span, dst_span);
+ copy(src_span, dst_span.subspan(src_span.size()));
+
+ for (std::size_t i = 0; i < src.size(); ++i) {
+ CHECK(dst[i] == src[i]);
+ CHECK(dst[i + src.size()] == src[i]);
+ }
+ }
+
+ // dynamic source and static destination span
+ {
+ std::array src{1, 2, 3, 4, 5};
+ std::array dst{};
+
+ span src_span(src);
+ span dst_span(dst);
+
+ copy(src_span, dst_span);
+ copy(src_span, dst_span.subspan(src_span.size()));
+
+ for (std::size_t i = 0; i < src.size(); ++i) {
+ CHECK(dst[i] == src[i]);
+ CHECK(dst[i + src.size()] == src[i]);
+ }
+ }
+
+ // static source and destination span
+ {
+ std::array src{1, 2, 3, 4, 5};
+ std::array dst{};
+
+ span src_span(src);
+ span dst_span(dst);
+
+ copy(src_span, dst_span);
+ copy(src_span, dst_span.subspan(src_span.size()));
+
+ for (std::size_t i = 0; i < src.size(); ++i) {
+ CHECK(dst[i] == src[i]);
+ CHECK(dst[i + src.size()] == src[i]);
+ }
+ }
+}
+
+#ifdef CONFIRM_COMPILATION_ERRORS
+TEST_CASE("incompatible_type")
+{
+ std::array src{1, 2, 3, 4};
+ std::array dst{};
+
+ span src_span_dyn(src);
+ span src_span_static(src);
+ span dst_span_dyn(dst);
+ span dst_span_static(dst);
+
+ // every line should produce a compilation error
+ copy(src_span_dyn, dst_span_dyn);
+ copy(src_span_dyn, dst_span_static);
+ copy(src_span_static, dst_span_dyn);
+ copy(src_span_static, dst_span_static);
+}
+#endif
+
+TEST_CASE("small_destination_span")
+{
+ std::array src{1, 2, 3, 4};
+ std::array dst{};
+
+ span src_span_dyn(src);
+ span src_span_static(src);
+ span dst_span_dyn(dst);
+ span dst_span_static(dst);
+
+ CHECK_THROWS_AS(copy(src_span_dyn, dst_span_dyn), fail_fast);
+ CHECK_THROWS_AS(copy(src_span_dyn, dst_span_static), fail_fast);
+ CHECK_THROWS_AS(copy(src_span_static, dst_span_dyn), fail_fast);
+
+#ifdef CONFIRM_COMPILATION_ERRORS
+ copy(src_span_static, dst_span_static);
+#endif
+}
diff --git a/tests/assertion_tests.cpp b/tests/assertion_tests.cpp
index b817a6d..42966d1 100644
--- a/tests/assertion_tests.cpp
+++ b/tests/assertion_tests.cpp
@@ -14,38 +14,33 @@
//
///////////////////////////////////////////////////////////////////////////////
-#include
+#include
#include
using namespace gsl;
-SUITE(assertion_tests)
+int f(int i)
{
- int f(int i)
- {
- Expects(i > 0 && i < 10);
- return i;
- }
-
- TEST(expects)
- {
- CHECK(f(2) == 2);
- CHECK_THROW(f(10), fail_fast);
- }
-
- int g(int i)
- {
- i++;
- Ensures(i > 0 && i < 10);
- return i;
- }
-
- TEST(ensures)
- {
- CHECK(g(2) == 3);
- CHECK_THROW(g(9), fail_fast);
- }
+ Expects(i > 0 && i < 10);
+ return i;
}
-int main(int, const char* []) { return UnitTest::RunAllTests(); }
+TEST_CASE("expects")
+{
+ CHECK(f(2) == 2);
+ CHECK_THROWS_AS(f(10), fail_fast);
+}
+
+int g(int i)
+{
+ i++;
+ Ensures(i > 0 && i < 10);
+ return i;
+}
+
+TEST_CASE("ensures")
+{
+ CHECK(g(2) == 3);
+ CHECK_THROWS_AS(g(9), fail_fast);
+}
diff --git a/tests/at_tests.cpp b/tests/at_tests.cpp
index 96e00f3..78e8e3d 100644
--- a/tests/at_tests.cpp
+++ b/tests/at_tests.cpp
@@ -14,7 +14,7 @@
//
///////////////////////////////////////////////////////////////////////////////
-#include
+#include
#include
@@ -23,70 +23,67 @@
using gsl::fail_fast;
-SUITE(at_tests)
+TEST_CASE("static_array")
{
- TEST(static_array)
- {
- int a[4] = {1, 2, 3, 4};
- const int(&c_a)[4] = a;
+ int a[4] = {1, 2, 3, 4};
+ const int(&c_a)[4] = a;
- for (int i = 0; i < 4; ++i) {
- CHECK(&gsl::at(a, i) == &a[i]);
- CHECK(&gsl::at(c_a, i) == &a[i]);
- }
-
- CHECK_THROW(gsl::at(a, -1), fail_fast);
- CHECK_THROW(gsl::at(a, 4), fail_fast);
- CHECK_THROW(gsl::at(c_a, -1), fail_fast);
- CHECK_THROW(gsl::at(c_a, 4), fail_fast);
+ for (int i = 0; i < 4; ++i) {
+ CHECK(&gsl::at(a, i) == &a[i]);
+ CHECK(&gsl::at(c_a, i) == &a[i]);
}
- TEST(std_array)
- {
- std::array a = {1, 2, 3, 4};
- const std::array& c_a = a;
+ CHECK_THROWS_AS(gsl::at(a, -1), fail_fast);
+ CHECK_THROWS_AS(gsl::at(a, 4), fail_fast);
+ CHECK_THROWS_AS(gsl::at(c_a, -1), fail_fast);
+ CHECK_THROWS_AS(gsl::at(c_a, 4), fail_fast);
+}
- for (int i = 0; i < 4; ++i) {
- CHECK(&gsl::at(a, i) == &a[static_cast(i)]);
- CHECK(&gsl::at(c_a, i) == &a[static_cast(i)]);
- }
+TEST_CASE("std_array")
+{
+ std::array a = {1, 2, 3, 4};
+ const std::array& c_a = a;
- CHECK_THROW(gsl::at(a, -1), fail_fast);
- CHECK_THROW(gsl::at(a, 4), fail_fast);
- CHECK_THROW(gsl::at(c_a, -1), fail_fast);
- CHECK_THROW(gsl::at(c_a, 4), fail_fast);
+ for (int i = 0; i < 4; ++i) {
+ CHECK(&gsl::at(a, i) == &a[static_cast(i)]);
+ CHECK(&gsl::at(c_a, i) == &a[static_cast(i)]);
}
- TEST(StdVector)
- {
- std::vector a = {1, 2, 3, 4};
- const std::vector& c_a = a;
+ CHECK_THROWS_AS(gsl::at(a, -1), fail_fast);
+ CHECK_THROWS_AS(gsl::at(a, 4), fail_fast);
+ CHECK_THROWS_AS(gsl::at(c_a, -1), fail_fast);
+ CHECK_THROWS_AS(gsl::at(c_a, 4), fail_fast);
+}
- for (int i = 0; i < 4; ++i) {
- CHECK(&gsl::at(a, i) == &a[static_cast(i)]);
- CHECK(&gsl::at(c_a, i) == &a[static_cast(i)]);
- }
+TEST_CASE("StdVector")
+{
+ std::vector a = {1, 2, 3, 4};
+ const std::vector& c_a = a;
- CHECK_THROW(gsl::at(a, -1), fail_fast);
- CHECK_THROW(gsl::at(a, 4), fail_fast);
- CHECK_THROW(gsl::at(c_a, -1), fail_fast);
- CHECK_THROW(gsl::at(c_a, 4), fail_fast);
+ for (int i = 0; i < 4; ++i) {
+ CHECK(&gsl::at(a, i) == &a[static_cast(i)]);
+ CHECK(&gsl::at(c_a, i) == &a[static_cast(i)]);
}
- TEST(InitializerList)
- {
- std::initializer_list a = {1, 2, 3, 4};
+ CHECK_THROWS_AS(gsl::at(a, -1), fail_fast);
+ CHECK_THROWS_AS(gsl::at(a, 4), fail_fast);
+ CHECK_THROWS_AS(gsl::at(c_a, -1), fail_fast);
+ CHECK_THROWS_AS(gsl::at(c_a, 4), fail_fast);
+}
- for (int i = 0; i < 4; ++i) {
- CHECK(gsl::at(a, i) == i + 1);
- CHECK(gsl::at({1, 2, 3, 4}, i) == i + 1);
- }
+TEST_CASE("InitializerList")
+{
+ std::initializer_list a = {1, 2, 3, 4};
- CHECK_THROW(gsl::at(a, -1), fail_fast);
- CHECK_THROW(gsl::at(a, 4), fail_fast);
- CHECK_THROW(gsl::at({1, 2, 3, 4}, -1), fail_fast);
- CHECK_THROW(gsl::at({1, 2, 3, 4}, 4), fail_fast);
+ for (int i = 0; i < 4; ++i) {
+ CHECK(gsl::at(a, i) == i + 1);
+ CHECK(gsl::at({1, 2, 3, 4}, i) == i + 1);
}
+
+ CHECK_THROWS_AS(gsl::at(a, -1), fail_fast);
+ CHECK_THROWS_AS(gsl::at(a, 4), fail_fast);
+ CHECK_THROWS_AS(gsl::at({1, 2, 3, 4}, -1), fail_fast);
+ CHECK_THROWS_AS(gsl::at({1, 2, 3, 4}, 4), fail_fast);
}
#if !defined(_MSC_VER) || defined(__clang__) || _MSC_VER >= 1910
@@ -111,5 +108,3 @@ static constexpr bool test_constexpr()
static_assert(test_constexpr(), "FAIL");
#endif
-
-int main() { return UnitTest::RunAllTests(); }
diff --git a/tests/bounds_tests.cpp b/tests/bounds_tests.cpp
index b010c3b..51b5393 100644
--- a/tests/bounds_tests.cpp
+++ b/tests/bounds_tests.cpp
@@ -14,7 +14,7 @@
//
///////////////////////////////////////////////////////////////////////////////
-#include
+#include
#include
@@ -28,73 +28,68 @@ namespace
void use(std::ptrdiff_t&) {}
}
-SUITE(bounds_test)
+TEST_CASE("basic_bounds")
{
- TEST(basic_bounds)
- {
- for (auto point : static_bounds{2}) {
- for (decltype(point)::size_type j = 0;
- j < static_cast(decltype(point)::rank); j++)
- {
- use(j);
- use(point[static_cast(j)]);
- }
+ for (auto point : static_bounds{2}) {
+ for (decltype(point)::size_type j = 0;
+ j < static_cast(decltype(point)::rank); j++)
+ {
+ use(j);
+ use(point[static_cast(j)]);
}
}
-
- TEST(bounds_basic)
- {
- static_bounds<3, 4, 5> b;
- const auto a = b.slice();
- (void) a;
- static_bounds<4, dynamic_range, 2> x{4};
- x.slice().slice();
- }
-
- TEST(arrayview_iterator)
- {
- static_bounds<4, dynamic_range, 2> bounds{3};
-
- const auto itr = bounds.begin();
- (void) itr;
-#ifdef CONFIRM_COMPILATION_ERRORS
- multi_span av(nullptr, bounds);
-
- auto itr2 = av.cbegin();
-
- for (auto& v : av) {
- v = 4;
- }
- fill(av.begin(), av.end(), 0);
-#endif
- }
-
- TEST(bounds_convertible)
- {
- static_bounds<7, 4, 2> b1;
- static_bounds<7, dynamic_range, 2> b2 = b1;
- (void) b2;
-#ifdef CONFIRM_COMPILATION_ERRORS
- static_bounds<7, dynamic_range, 1> b4 = b2;
-#endif
-
- static_bounds b3 = b1;
- static_bounds<7, 4, 2> b4 = b3;
- (void) b4;
-
- static_bounds b11;
-
- static_bounds b5;
- static_bounds<34> b6;
-
- b5 = static_bounds<20>();
- CHECK_THROW(b6 = b5, fail_fast);
- b5 = static_bounds<34>();
- b6 = b5;
-
- CHECK(b5 == b6);
- CHECK(b5.size() == b6.size());
- }
}
-int main(int, const char* []) { return UnitTest::RunAllTests(); }
+TEST_CASE("bounds_basic")
+{
+ static_bounds<3, 4, 5> b;
+ const auto a = b.slice();
+ (void) a;
+ static_bounds<4, dynamic_range, 2> x{4};
+ x.slice().slice();
+}
+
+TEST_CASE("arrayview_iterator")
+{
+ static_bounds<4, dynamic_range, 2> bounds{3};
+
+ const auto itr = bounds.begin();
+ (void) itr;
+#ifdef CONFIRM_COMPILATION_ERRORS
+ multi_span av(nullptr, bounds);
+
+ auto itr2 = av.cbegin();
+
+ for (auto& v : av) {
+ v = 4;
+ }
+ fill(av.begin(), av.end(), 0);
+#endif
+}
+
+TEST_CASE("bounds_convertible")
+{
+ static_bounds<7, 4, 2> b1;
+ static_bounds<7, dynamic_range, 2> b2 = b1;
+ (void) b2;
+#ifdef CONFIRM_COMPILATION_ERRORS
+ static_bounds<7, dynamic_range, 1> b4 = b2;
+#endif
+
+ static_bounds b3 = b1;
+ static_bounds<7, 4, 2> b4 = b3;
+ (void) b4;
+
+ static_bounds b11;
+
+ static_bounds b5;
+ static_bounds<34> b6;
+
+ b5 = static_bounds<20>();
+ CHECK_THROWS_AS(b6 = b5, fail_fast);
+ b5 = static_bounds<34>();
+ b6 = b5;
+
+ CHECK(b5 == b6);
+ CHECK(b5.size() == b6.size());
+}
diff --git a/tests/byte_tests.cpp b/tests/byte_tests.cpp
index 753936e..2c6259d 100644
--- a/tests/byte_tests.cpp
+++ b/tests/byte_tests.cpp
@@ -14,7 +14,7 @@
//
///////////////////////////////////////////////////////////////////////////////
-#include
+#include
#include
@@ -31,105 +31,101 @@ using namespace gsl;
namespace
{
-SUITE(byte_tests)
+TEST_CASE("construction")
{
- TEST(construction)
{
- {
- const byte b = static_cast(4);
- CHECK(static_cast(b) == 4);
- }
-
- {
- const byte b = byte(12);
- CHECK(static_cast(b) == 12);
- }
-
- {
- const byte b = to_byte<12>();
- CHECK(static_cast(b) == 12);
- }
- {
- const unsigned char uc = 12;
- const byte b = to_byte(uc);
- CHECK(static_cast(b) == 12);
- }
-
- // waiting for C++17 enum class direct initializer support
- //{
- // byte b { 14 };
- // CHECK(static_cast(b) == 14);
- //}
+ const byte b = static_cast(4);
+ CHECK(static_cast(b) == 4);
}
- TEST(bitwise_operations)
{
- const byte b = to_byte<0xFF>();
-
- byte a = to_byte<0x00>();
- CHECK((b | a) == to_byte<0xFF>());
- CHECK(a == to_byte<0x00>());
-
- a |= b;
- CHECK(a == to_byte<0xFF>());
-
- a = to_byte<0x01>();
- CHECK((b & a) == to_byte<0x01>());
-
- a &= b;
- CHECK(a == to_byte<0x01>());
-
- CHECK((b ^ a) == to_byte<0xFE>());
-
- CHECK(a == to_byte<0x01>());
- a ^= b;
- CHECK(a == to_byte<0xFE>());
-
- a = to_byte<0x01>();
- CHECK(~a == to_byte<0xFE>());
-
- a = to_byte<0xFF>();
- CHECK((a << 4) == to_byte<0xF0>());
- CHECK((a >> 4) == to_byte<0x0F>());
-
- a <<= 4;
- CHECK(a == to_byte<0xF0>());
- a >>= 4;
- CHECK(a == to_byte<0x0F>());
+ const byte b = byte(12);
+ CHECK(static_cast(b) == 12);
}
- TEST(to_integer)
{
- const byte b = to_byte<0x12>();
-
- CHECK(0x12 == gsl::to_integer(b));
- CHECK(0x12 == gsl::to_integer(b));
- CHECK(0x12 == gsl::to_integer(b));
- CHECK(0x12 == gsl::to_integer(b));
-
- CHECK(0x12 == gsl::to_integer(b));
- CHECK(0x12 == gsl::to_integer(b));
- CHECK(0x12 == gsl::to_integer(b));
- CHECK(0x12 == gsl::to_integer(b));
-
- // CHECK(0x12 == gsl::to_integer(b)); // expect compile-time error
- // CHECK(0x12 == gsl::to_integer(b)); // expect compile-time error
+ const byte b = to_byte<12>();
+ CHECK(static_cast(b) == 12);
+ }
+ {
+ const unsigned char uc = 12;
+ const byte b = to_byte(uc);
+ CHECK(static_cast(b) == 12);
}
- int modify_both(gsl::byte & b, int& i)
- {
- i = 10;
- b = to_byte<5>();
- return i;
- }
-
- TEST(aliasing)
- {
- int i{0};
- const int res = modify_both(reinterpret_cast(i), i);
- CHECK(res == i);
- }
-}
+ // waiting for C++17 enum class direct initializer support
+ //{
+ // byte b { 14 };
+ // CHECK(static_cast(b) == 14);
+ //}
}
-int main(int, const char* []) { return UnitTest::RunAllTests(); }
+TEST_CASE("bitwise_operations")
+{
+ const byte b = to_byte<0xFF>();
+
+ byte a = to_byte<0x00>();
+ CHECK((b | a) == to_byte<0xFF>());
+ CHECK(a == to_byte<0x00>());
+
+ a |= b;
+ CHECK(a == to_byte<0xFF>());
+
+ a = to_byte<0x01>();
+ CHECK((b & a) == to_byte<0x01>());
+
+ a &= b;
+ CHECK(a == to_byte<0x01>());
+
+ CHECK((b ^ a) == to_byte<0xFE>());
+
+ CHECK(a == to_byte<0x01>());
+ a ^= b;
+ CHECK(a == to_byte<0xFE>());
+
+ a = to_byte<0x01>();
+ CHECK(~a == to_byte<0xFE>());
+
+ a = to_byte<0xFF>();
+ CHECK((a << 4) == to_byte<0xF0>());
+ CHECK((a >> 4) == to_byte<0x0F>());
+
+ a <<= 4;
+ CHECK(a == to_byte<0xF0>());
+ a >>= 4;
+ CHECK(a == to_byte<0x0F>());
+}
+
+TEST_CASE("to_integer")
+{
+ const byte b = to_byte<0x12>();
+
+ CHECK(0x12 == gsl::to_integer(b));
+ CHECK(0x12 == gsl::to_integer(b));
+ CHECK(0x12 == gsl::to_integer(b));
+ CHECK(0x12 == gsl::to_integer(b));
+
+ CHECK(0x12 == gsl::to_integer(b));
+ CHECK(0x12 == gsl::to_integer(b));
+ CHECK(0x12 == gsl::to_integer(b));
+ CHECK(0x12 == gsl::to_integer(b));
+
+ // CHECK(0x12 == gsl::to_integer(b)); // expect compile-time error
+ // CHECK(0x12 == gsl::to_integer(b)); // expect compile-time error
+}
+
+int modify_both(gsl::byte & b, int& i)
+{
+ i = 10;
+ b = to_byte<5>();
+ return i;
+}
+
+TEST_CASE("aliasing")
+{
+ int i{0};
+ const int res = modify_both(reinterpret_cast(i), i);
+ CHECK(res == i);
+}
+
+}
diff --git a/tests/multi_span_tests.cpp b/tests/multi_span_tests.cpp
index 5f829e1..af58d76 100644
--- a/tests/multi_span_tests.cpp
+++ b/tests/multi_span_tests.cpp
@@ -14,7 +14,7 @@
//
///////////////////////////////////////////////////////////////////////////////
-#include
+#include
#include
@@ -38,1324 +38,1324 @@ struct DerivedClass : BaseClass
};
}
-SUITE(multi_span_tests)
+TEST_CASE("default_constructor")
{
-
- TEST(default_constructor)
{
- {
- multi_span s;
- CHECK(s.length() == 0 && s.data() == nullptr);
+ multi_span s;
+ CHECK((s.length() == 0 && s.data() == nullptr));
- multi_span cs;
- CHECK(cs.length() == 0 && cs.data() == nullptr);
- }
-
- {
- multi_span s;
- CHECK(s.length() == 0 && s.data() == nullptr);
-
- multi_span cs;
- CHECK(cs.length() == 0 && cs.data() == nullptr);
- }
-
- {
-#ifdef CONFIRM_COMPILATION_ERRORS
- multi_span s;
- CHECK(s.length() == 1 && s.data() == nullptr); // explains why it can't compile
-#endif
- }
-
- {
- multi_span s{};
- CHECK(s.length() == 0 && s.data() == nullptr);
-
- multi_span cs{};
- CHECK(cs.length() == 0 && cs.data() == nullptr);
- }
+ multi_span cs;
+ CHECK((cs.length() == 0 && cs.data() == nullptr));
}
- TEST(from_nullptr_constructor)
{
- {
- multi_span s = nullptr;
- CHECK(s.length() == 0 && s.data() == nullptr);
+ multi_span s;
+ CHECK((s.length() == 0 && s.data() == nullptr));
- multi_span cs = nullptr;
- CHECK(cs.length() == 0 && cs.data() == nullptr);
- }
-
- {
- multi_span s = nullptr;
- CHECK(s.length() == 0 && s.data() == nullptr);
-
- multi_span cs = nullptr;
- CHECK(cs.length() == 0 && cs.data() == nullptr);
- }
-
- {
-#ifdef CONFIRM_COMPILATION_ERRORS
- multi_span s = nullptr;
- CHECK(s.length() == 1 && s.data() == nullptr); // explains why it can't compile
-#endif
- }
-
- {
- multi_span s{nullptr};
- CHECK(s.length() == 0 && s.data() == nullptr);
-
- multi_span cs{nullptr};
- CHECK(cs.length() == 0 && cs.data() == nullptr);
- }
-
- {
- multi_span s{nullptr};
- CHECK(s.length() == 0 && s.data() == nullptr);
-
- multi_span cs{nullptr};
- CHECK(cs.length() == 0 && cs.data() == nullptr);
- }
+ multi_span cs;
+ CHECK((cs.length() == 0 && cs.data() == nullptr));
}
- TEST(from_nullptr_length_constructor)
{
- {
- multi_span s{nullptr, 0};
- CHECK(s.length() == 0 && s.data() == nullptr);
-
- multi_span cs{nullptr, 0};
- CHECK(cs.length() == 0 && cs.data() == nullptr);
- }
-
- {
- multi_span s{nullptr, 0};
- CHECK(s.length() == 0 && s.data() == nullptr);
-
- multi_span cs{nullptr, 0};
- CHECK(cs.length() == 0 && cs.data() == nullptr);
- }
-
- {
#ifdef CONFIRM_COMPILATION_ERRORS
- multi_span s{nullptr, 0};
- CHECK(s.length() == 1 && s.data() == nullptr); // explains why it can't compile
+ multi_span s;
+ CHECK((s.length() == 1 && s.data() == nullptr)); // explains why it can't compile
#endif
- }
-
- {
- auto workaround_macro = []() { multi_span s{nullptr, 1}; };
- CHECK_THROW(workaround_macro(), fail_fast);
-
- auto const_workaround_macro = []() { multi_span cs{nullptr, 1}; };
- CHECK_THROW(const_workaround_macro(), fail_fast);
- }
-
- {
- auto workaround_macro = []() { multi_span s{nullptr, 1}; };
- CHECK_THROW(workaround_macro(), fail_fast);
-
- auto const_workaround_macro = []() { multi_span s{nullptr, 1}; };
- CHECK_THROW(const_workaround_macro(), fail_fast);
- }
-
- {
- multi_span s{nullptr, 0};
- CHECK(s.length() == 0 && s.data() == nullptr);
-
- multi_span cs{nullptr, 0};
- CHECK(cs.length() == 0 && cs.data() == nullptr);
- }
}
- TEST(from_element_constructor)
{
- int i = 5;
+ multi_span s{};
+ CHECK((s.length() == 0 && s.data() == nullptr));
- {
- multi_span s = i;
- CHECK(s.length() == 1 && s.data() == &i);
- CHECK(s[0] == 5);
+ multi_span cs{};
+ CHECK((cs.length() == 0 && cs.data() == nullptr));
+ }
+}
- multi_span cs = i;
- CHECK(cs.length() == 1 && cs.data() == &i);
- CHECK(cs[0] == 5);
- }
+TEST_CASE("from_nullptr_constructor")
+{
+ {
+ multi_span s = nullptr;
+ CHECK((s.length() == 0 && s.data() == nullptr));
- {
-#ifdef CONFIRM_COMPILATION_ERRORS
- const j = 1;
- multi_span s = j;
-#endif
- }
-
- {
-#ifdef CONFIRM_COMPILATION_ERRORS
- multi_span s = i;
- CHECK(s.length() == 0 && s.data() == &i);
-#endif
- }
-
- {
- multi_span s = i;
- CHECK(s.length() == 1 && s.data() == &i);
- CHECK(s[0] == 5);
- }
-
- {
-#ifdef CONFIRM_COMPILATION_ERRORS
- multi_span s = i;
- CHECK(s.length() == 2 && s.data() == &i);
-#endif
- }
-
- {
-#ifdef CONFIRM_COMPILATION_ERRORS
- auto get_a_temp = []() -> int { return 4; };
- auto use_a_span = [](multi_span s) { (void) s; };
- use_a_span(get_a_temp());
-#endif
- }
+ multi_span cs = nullptr;
+ CHECK((cs.length() == 0 && cs.data() == nullptr));
}
- TEST(from_pointer_length_constructor)
{
- int arr[4] = {1, 2, 3, 4};
+ multi_span s = nullptr;
+ CHECK((s.length() == 0 && s.data() == nullptr));
- {
- multi_span s{&arr[0], 2};
- CHECK(s.length() == 2 && s.data() == &arr[0]);
- CHECK(s[0] == 1 && s[1] == 2);
- }
-
- {
- multi_span s{&arr[0], 2};
- CHECK(s.length() == 2 && s.data() == &arr[0]);
- CHECK(s[0] == 1 && s[1] == 2);
- }
-
- {
- int* p = nullptr;
- multi_span s{p, 0};
- CHECK(s.length() == 0 && s.data() == nullptr);
- }
-
- {
- int* p = nullptr;
- auto workaround_macro = [=]() { multi_span s{p, 2}; };
- CHECK_THROW(workaround_macro(), fail_fast);
- }
+ multi_span cs = nullptr;
+ CHECK((cs.length() == 0 && cs.data() == nullptr));
}
- TEST(from_pointer_pointer_constructor)
{
- int arr[4] = {1, 2, 3, 4};
-
- {
- multi_span s{&arr[0], &arr[2]};
- CHECK(s.length() == 2 && s.data() == &arr[0]);
- CHECK(s[0] == 1 && s[1] == 2);
- }
-
- {
- multi_span s{&arr[0], &arr[2]};
- CHECK(s.length() == 2 && s.data() == &arr[0]);
- CHECK(s[0] == 1 && s[1] == 2);
- }
-
- {
- multi_span s{&arr[0], &arr[0]};
- CHECK(s.length() == 0 && s.data() == &arr[0]);
- }
-
- {
- multi_span s{&arr[0], &arr[0]};
- CHECK(s.length() == 0 && s.data() == &arr[0]);
- }
-
- {
- auto workaround_macro = [&]() { multi_span s{&arr[1], &arr[0]}; };
- CHECK_THROW(workaround_macro(), fail_fast);
- }
-
- {
- int* p = nullptr;
- auto workaround_macro = [&]() { multi_span s{&arr[0], p}; };
- CHECK_THROW(workaround_macro(), fail_fast);
- }
-
- {
- int* p = nullptr;
- auto workaround_macro = [&]() { multi_span s{p, p}; };
- CHECK_THROW(workaround_macro(), fail_fast);
- }
-
- {
- int* p = nullptr;
- auto workaround_macro = [&]() { multi_span s{&arr[0], p}; };
- CHECK_THROW(workaround_macro(), fail_fast);
- }
+#ifdef CONFIRM_COMPILATION_ERRORS
+ multi_span s = nullptr;
+ CHECK((s.length() == 1 && s.data() == nullptr)); // explains why it can't compile
+#endif
}
- TEST(from_array_constructor)
{
- int arr[5] = {1, 2, 3, 4, 5};
+ multi_span s{nullptr};
+ CHECK((s.length() == 0 && s.data() == nullptr));
- {
- multi_span s{arr};
- CHECK(s.length() == 5 && s.data() == &arr[0]);
- }
-
- {
- multi_span s{arr};
- CHECK(s.length() == 5 && s.data() == &arr[0]);
- }
-
- {
-#ifdef CONFIRM_COMPILATION_ERRORS
- multi_span s{arr};
-#endif
- }
-
- {
- multi_span s{arr};
- CHECK(s.length() == 0 && s.data() == &arr[0]);
- }
-
- int arr2d[2][3] = {1, 2, 3, 4, 5, 6};
-
- {
- multi_span s{arr2d};
- CHECK(s.length() == 6 && s.data() == &arr2d[0][0]);
- CHECK(s[0] == 1 && s[5] == 6);
- }
-
- {
- multi_span s{arr2d};
- CHECK(s.length() == 0 && s.data() == &arr2d[0][0]);
- }
-
- {
-#ifdef CONFIRM_COMPILATION_ERRORS
- multi_span s{arr2d};
-#endif
- }
-
- {
- multi_span s{arr2d};
- CHECK(s.length() == 6 && s.data() == &arr2d[0][0]);
- CHECK(s[0] == 1 && s[5] == 6);
- }
-
- {
-#ifdef CONFIRM_COMPILATION_ERRORS
- multi_span s{arr2d};
-#endif
- }
-
- {
- multi_span s{arr2d[0]};
- CHECK(s.length() == 1 && s.data() == &arr2d[0]);
- }
-
- {
- multi_span s{arr2d};
- CHECK(s.length() == 6 && s.data() == &arr2d[0][0]);
- auto workaround_macro = [&]() { return s[{1, 2}] == 6; };
- CHECK(workaround_macro());
- }
-
- {
-#ifdef CONFIRM_COMPILATION_ERRORS
- multi_span s{arr2d};
-#endif
- }
-
- int arr3d[2][3][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
-
- {
- multi_span s{arr3d};
- CHECK(s.length() == 12 && s.data() == &arr3d[0][0][0]);
- CHECK(s[0] == 1 && s[11] == 12);
- }
-
- {
- multi_span s{arr3d};
- CHECK(s.length() == 0 && s.data() == &arr3d[0][0][0]);
- }
-
- {
-#ifdef CONFIRM_COMPILATION_ERRORS
- multi_span s{arr3d};
-#endif
- }
-
- {
- multi_span s{arr3d};
- CHECK(s.length() == 12 && s.data() == &arr3d[0][0][0]);
- CHECK(s[0] == 1 && s[5] == 6);
- }
-
- {
-#ifdef CONFIRM_COMPILATION_ERRORS
- multi_span s{arr3d};
-#endif
- }
-
- {
- multi_span s{arr3d[0]};
- CHECK(s.length() == 1 && s.data() == &arr3d[0]);
- }
-
- {
- multi_span s{arr3d};
- CHECK(s.length() == 12 && s.data() == &arr3d[0][0][0]);
- auto workaround_macro = [&]() { return s[{2, 1, 0}] == 11; };
- CHECK(workaround_macro());
- }
-
- {
-#ifdef CONFIRM_COMPILATION_ERRORS
- multi_span s{arr3d};
-#endif
- }
+ multi_span cs{nullptr};
+ CHECK((cs.length() == 0 && cs.data() == nullptr));
}
- TEST(from_dynamic_array_constructor)
{
- double(*arr)[3][4] = new double[100][3][4];
+ multi_span s{nullptr};
+ CHECK((s.length() == 0 && s.data() == nullptr));
- {
- multi_span s(arr, 10);
- CHECK(s.length() == 120 && s.data() == &arr[0][0][0]);
- CHECK_THROW(s[10][3][4], fail_fast);
- }
+ multi_span