Skip to content

Commit 2618d5a

Browse files
authored
ported tests to doctest. (#2405)
Ported tests to doctest.
1 parent 6f37731 commit 2618d5a

File tree

86 files changed

+2312
-2311
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+2312
-2311
lines changed

.appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ install:
3535
- CALL conda.bat activate xtensor
3636
- if "%APPVEYOR_BUILD_WORKER_IMAGE%" == "Visual Studio 2017" set CMAKE_ARGS="-DDISABLE_VS2017=ON"
3737
- if "%APPVEYOR_BUILD_WORKER_IMAGE%" == "Visual Studio 2015" set CMAKE_ARGS=""
38-
- cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=%MINICONDA%\\LIBRARY -DDOWNLOAD_GTEST=ON -DXTENSOR_USE_XSIMD=ON -DCMAKE_BUILD_TYPE=RELEASE %CMAKE_ARGS% .
38+
- cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=%MINICONDA%\\LIBRARY -DBUILD_TESTS=ON -DXTENSOR_USE_XSIMD=ON -DCMAKE_BUILD_TYPE=RELEASE %CMAKE_ARGS% .
3939
- nmake test_xtensor_lib
4040
- cd test
4141

.azure-pipelines/azure-pipelines-win.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
- script: |
3737
conda install cmake==3.14.0 ^
3838
ninja ^
39+
doctest ^
3940
nlohmann_json ^
4041
xtl==0.7.0 ^
4142
xsimd==7.4.8 ^
@@ -61,7 +62,7 @@ jobs:
6162
-DCMAKE_BUILD_TYPE=Release ^
6263
-DCMAKE_C_COMPILER=clang-cl ^
6364
-DCMAKE_CXX_COMPILER=clang-cl ^
64-
-DDOWNLOAD_GTEST=ON ^
65+
-DBUILD_TESTS=ON ^
6566
-DXTENSOR_USE_XSIMD=ON ^
6667
$(Build.SourcesDirectory)
6768
displayName: "Configure xtensor"

.azure-pipelines/unix-build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ steps:
2626
source activate xtensor
2727
mkdir build
2828
cd build
29+
CMAKE_EXTRA_ARGS="$CMAKE_EXTRA_ARGS -DBUILD_TESTS=ON";
2930
if [[ $(bound_checks) == 1 ]]; then
3031
CMAKE_EXTRA_ARGS="$CMAKE_EXTRA_ARGS -DXTENSOR_ENABLE_ASSERT=ON";
3132
fi
@@ -53,7 +54,7 @@ steps:
5354
CMAKE_EXTA_ARGS="$CMAKE_EXTRA_ARGS -DBUILD_BENCHMARK=ON";
5455
fi
5556
56-
cmake -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX $CMAKE_EXTRA_ARGS -DDOWNLOAD_GTEST=ON $(Build.SourcesDirectory)
57+
cmake -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX $CMAKE_EXTRA_ARGS $(Build.SourcesDirectory)
5758
displayName: Configure xtensor
5859
workingDirectory: $(Build.BinariesDirectory)
5960

CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,6 @@ OPTION(CPP20 "enables C++20 (experimental)" OFF)
207207
OPTION(XTENSOR_DISABLE_EXCEPTIONS "Disable C++ exceptions" OFF)
208208
OPTION(DISABLE_MSVC_ITERATOR_CHECK "Disable the MVSC iterator check" ON)
209209

210-
if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
211-
set(BUILD_TESTS ON)
212-
endif()
213210

214211
if(XTENSOR_ENABLE_ASSERT OR XTENSOR_CHECK_DIMENSION)
215212
add_definitions(-DXTENSOR_ENABLE_ASSERT)

environment-dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ dependencies:
66
- xtl=0.7.0
77
- xsimd=7.4.9
88
- nlohmann_json
9+
- doctest

include/xtensor/xlayout.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#ifndef XTENSOR_LAYOUT_HPP
1111
#define XTENSOR_LAYOUT_HPP
1212

13+
#include <type_traits>
14+
1315
// Do not include anything else here.
1416
// xlayout.hpp is included in xtensor_forward.hpp
1517
// and we don't want to bring other headers to it.

test/CMakeLists.txt

Lines changed: 8 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
cmake_minimum_required(VERSION 3.1)
1111

12+
find_package(doctest REQUIRED)
13+
find_package(Threads)
14+
1215
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
1316
project(xtensor-test)
1417

@@ -118,46 +121,6 @@ else()
118121
message(FATAL_ERROR "Unsupported compiler: ${CMAKE_CXX_COMPILER_ID}")
119122
endif()
120123

121-
if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
122-
if(DOWNLOAD_GTEST)
123-
# Download and unpack googletest at configure time
124-
configure_file(downloadGTest.cmake.in googletest-download/CMakeLists.txt)
125-
else()
126-
# Copy local source of googletest at configure time
127-
configure_file(copyGTest.cmake.in googletest-download/CMakeLists.txt)
128-
endif()
129-
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
130-
RESULT_VARIABLE result
131-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
132-
if(result)
133-
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
134-
endif()
135-
execute_process(COMMAND ${CMAKE_COMMAND} --build .
136-
RESULT_VARIABLE result
137-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
138-
if(result)
139-
message(FATAL_ERROR "Build step for googletest failed: ${result}")
140-
endif()
141-
142-
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
143-
144-
# Add googletest directly to our build. This defines
145-
# the gtest and gtest_main targets.
146-
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
147-
${CMAKE_CURRENT_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL)
148-
149-
set(GTEST_INCLUDE_DIRS "${gtest_SOURCE_DIR}/include")
150-
add_library(GTest::GTest INTERFACE IMPORTED)
151-
target_link_libraries(GTest::GTest INTERFACE gtest)
152-
add_library(GTest::Main INTERFACE IMPORTED)
153-
target_link_libraries(GTest::Main INTERFACE gtest_main)
154-
else()
155-
find_package(GTest REQUIRED)
156-
endif()
157-
158-
find_package(Threads)
159-
160-
include_directories(${GTEST_INCLUDE_DIRS} SYSTEM)
161124

162125
# For unit test and coverity scan.
163126
# The Coverity scanner takes time and it could cause build timeout(10mins) in Travis CI.
@@ -284,7 +247,7 @@ add_custom_target(
284247

285248
foreach(filename IN LISTS COMMON_BASE XTENSOR_TESTS)
286249
string(REPLACE ".cpp" "" targetname ${filename})
287-
add_executable(${targetname} ${filename} ${TEST_HEADERS} ${XTENSOR_HEADERS})
250+
add_executable(${targetname} main.cpp ${filename} ${TEST_HEADERS} ${XTENSOR_HEADERS})
288251
if(XTENSOR_USE_XSIMD)
289252
target_compile_definitions(${targetname}
290253
PRIVATE
@@ -300,19 +263,16 @@ foreach(filename IN LISTS COMMON_BASE XTENSOR_TESTS)
300263
if(XTENSOR_USE_OPENMP)
301264
target_compile_definitions(${targetname} PRIVATE XTENSOR_USE_OPENMP)
302265
endif()
303-
if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
304-
add_dependencies(${targetname} gtest_main)
305-
endif()
306266
target_include_directories(${targetname} PRIVATE ${XTENSOR_INCLUDE_DIR})
307-
target_link_libraries(${targetname} PRIVATE xtensor GTest::GTest GTest::Main ${CMAKE_THREAD_LIBS_INIT})
267+
target_link_libraries(${targetname} PRIVATE xtensor doctest::doctest ${CMAKE_THREAD_LIBS_INIT})
308268
add_custom_target(
309269
x${targetname}
310270
COMMAND ${targetname}
311271
DEPENDS ${targetname} ${filename} ${XTENSOR_HEADERS})
312272
add_test(NAME ${targetname} COMMAND ${targetname})
313273
endforeach()
314274

315-
add_executable(test_xtensor_lib ${COMMON_BASE} ${XTENSOR_TESTS} ${TEST_HEADERS} ${XTENSOR_HEADERS})
275+
add_executable(test_xtensor_lib main.cpp ${COMMON_BASE} ${XTENSOR_TESTS} ${TEST_HEADERS} ${XTENSOR_HEADERS})
316276
if(XTENSOR_USE_XSIMD)
317277
target_compile_definitions(test_xtensor_lib
318278
PRIVATE
@@ -329,12 +289,8 @@ if(XTENSOR_USE_OPENMP)
329289
target_compile_definitions(test_xtensor_lib PRIVATE XTENSOR_USE_OPENMP)
330290
endif()
331291

332-
if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
333-
add_dependencies(test_xtensor_lib gtest_main)
334-
endif()
335-
336292
target_include_directories(test_xtensor_lib PRIVATE ${XTENSOR_INCLUDE_DIR})
337-
target_link_libraries(test_xtensor_lib PRIVATE xtensor GTest::GTest GTest::Main ${CMAKE_THREAD_LIBS_INIT})
293+
target_link_libraries(test_xtensor_lib PRIVATE xtensor doctest::doctest ${CMAKE_THREAD_LIBS_INIT})
338294

339295
add_custom_target(xtest COMMAND test_xtensor_lib DEPENDS test_xtensor_lib)
340296
add_test(NAME xtest COMMAND test_xtensor_lib)
@@ -345,9 +301,5 @@ add_test(NAME xtest COMMAND test_xtensor_lib)
345301
add_library(test_xtensor_core_lib ${COMMON_BASE} ${TEST_HEADERS} ${XTENSOR_HEADERS})
346302
target_include_directories(test_xtensor_core_lib PRIVATE ${XTENSOR_INCLUDE_DIR})
347303

348-
if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
349-
add_dependencies(test_xtensor_core_lib gtest_main)
350-
endif()
351-
352-
target_link_libraries(test_xtensor_core_lib PRIVATE xtensor GTest::GTest GTest::Main ${CMAKE_THREAD_LIBS_INIT})
304+
target_link_libraries(test_xtensor_core_lib PRIVATE xtensor doctest::doctest ${CMAKE_THREAD_LIBS_INIT})
353305
add_custom_target(coverity COMMAND coverity_scan DEPENDS test_xtensor_core_lib)

test/copyGTest.cmake.in

Lines changed: 0 additions & 24 deletions
This file was deleted.

test/downloadGTest.cmake.in

Lines changed: 0 additions & 25 deletions
This file was deleted.

test/main.cpp

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
1-
/***************************************************************************
2-
* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht *
3-
* Copyright (c) QuantStack *
4-
* *
5-
* Distributed under the terms of the BSD 3-Clause License. *
6-
* *
7-
* The full license is in the file LICENSE, distributed with this software. *
8-
****************************************************************************/
9-
10-
#include "gtest/gtest.h"
11-
12-
int main(int argc, char* argv[])
13-
{
14-
::testing::InitGoogleTest(&argc, argv);
15-
return RUN_ALL_TESTS();
16-
}
1+
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
2+
#if defined(XTENSOR_DISABLE_EXCEPTIONS)
3+
#define DOCTEST_CONFIG_NO_EXCEPTIONS
4+
#endif
5+
#include "doctest/doctest.h"

0 commit comments

Comments
 (0)