Skip to content

Commit

Permalink
ported tests to doctest. (xtensor-stack#2405)
Browse files Browse the repository at this point in the history
Ported tests to doctest.
  • Loading branch information
DerThorsten authored Jun 22, 2021
1 parent 6f37731 commit 2618d5a
Show file tree
Hide file tree
Showing 86 changed files with 2,312 additions and 2,311 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ install:
- CALL conda.bat activate xtensor
- if "%APPVEYOR_BUILD_WORKER_IMAGE%" == "Visual Studio 2017" set CMAKE_ARGS="-DDISABLE_VS2017=ON"
- if "%APPVEYOR_BUILD_WORKER_IMAGE%" == "Visual Studio 2015" set CMAKE_ARGS=""
- cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=%MINICONDA%\\LIBRARY -DDOWNLOAD_GTEST=ON -DXTENSOR_USE_XSIMD=ON -DCMAKE_BUILD_TYPE=RELEASE %CMAKE_ARGS% .
- cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=%MINICONDA%\\LIBRARY -DBUILD_TESTS=ON -DXTENSOR_USE_XSIMD=ON -DCMAKE_BUILD_TYPE=RELEASE %CMAKE_ARGS% .
- nmake test_xtensor_lib
- cd test

Expand Down
3 changes: 2 additions & 1 deletion .azure-pipelines/azure-pipelines-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
- script: |
conda install cmake==3.14.0 ^
ninja ^
doctest ^
nlohmann_json ^
xtl==0.7.0 ^
xsimd==7.4.8 ^
Expand All @@ -61,7 +62,7 @@ jobs:
-DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_C_COMPILER=clang-cl ^
-DCMAKE_CXX_COMPILER=clang-cl ^
-DDOWNLOAD_GTEST=ON ^
-DBUILD_TESTS=ON ^
-DXTENSOR_USE_XSIMD=ON ^
$(Build.SourcesDirectory)
displayName: "Configure xtensor"
Expand Down
3 changes: 2 additions & 1 deletion .azure-pipelines/unix-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ steps:
source activate xtensor
mkdir build
cd build
CMAKE_EXTRA_ARGS="$CMAKE_EXTRA_ARGS -DBUILD_TESTS=ON";
if [[ $(bound_checks) == 1 ]]; then
CMAKE_EXTRA_ARGS="$CMAKE_EXTRA_ARGS -DXTENSOR_ENABLE_ASSERT=ON";
fi
Expand Down Expand Up @@ -53,7 +54,7 @@ steps:
CMAKE_EXTA_ARGS="$CMAKE_EXTRA_ARGS -DBUILD_BENCHMARK=ON";
fi
cmake -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX $CMAKE_EXTRA_ARGS -DDOWNLOAD_GTEST=ON $(Build.SourcesDirectory)
cmake -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX $CMAKE_EXTRA_ARGS $(Build.SourcesDirectory)
displayName: Configure xtensor
workingDirectory: $(Build.BinariesDirectory)
Expand Down
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,6 @@ OPTION(CPP20 "enables C++20 (experimental)" OFF)
OPTION(XTENSOR_DISABLE_EXCEPTIONS "Disable C++ exceptions" OFF)
OPTION(DISABLE_MSVC_ITERATOR_CHECK "Disable the MVSC iterator check" ON)

if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
set(BUILD_TESTS ON)
endif()

if(XTENSOR_ENABLE_ASSERT OR XTENSOR_CHECK_DIMENSION)
add_definitions(-DXTENSOR_ENABLE_ASSERT)
Expand Down
1 change: 1 addition & 0 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ dependencies:
- xtl=0.7.0
- xsimd=7.4.9
- nlohmann_json
- doctest
2 changes: 2 additions & 0 deletions include/xtensor/xlayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#ifndef XTENSOR_LAYOUT_HPP
#define XTENSOR_LAYOUT_HPP

#include <type_traits>

// Do not include anything else here.
// xlayout.hpp is included in xtensor_forward.hpp
// and we don't want to bring other headers to it.
Expand Down
64 changes: 8 additions & 56 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

cmake_minimum_required(VERSION 3.1)

find_package(doctest REQUIRED)
find_package(Threads)

if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
project(xtensor-test)

Expand Down Expand Up @@ -118,46 +121,6 @@ else()
message(FATAL_ERROR "Unsupported compiler: ${CMAKE_CXX_COMPILER_ID}")
endif()

if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
if(DOWNLOAD_GTEST)
# Download and unpack googletest at configure time
configure_file(downloadGTest.cmake.in googletest-download/CMakeLists.txt)
else()
# Copy local source of googletest at configure time
configure_file(copyGTest.cmake.in googletest-download/CMakeLists.txt)
endif()
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()

set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
${CMAKE_CURRENT_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL)

set(GTEST_INCLUDE_DIRS "${gtest_SOURCE_DIR}/include")
add_library(GTest::GTest INTERFACE IMPORTED)
target_link_libraries(GTest::GTest INTERFACE gtest)
add_library(GTest::Main INTERFACE IMPORTED)
target_link_libraries(GTest::Main INTERFACE gtest_main)
else()
find_package(GTest REQUIRED)
endif()

find_package(Threads)

include_directories(${GTEST_INCLUDE_DIRS} SYSTEM)

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

foreach(filename IN LISTS COMMON_BASE XTENSOR_TESTS)
string(REPLACE ".cpp" "" targetname ${filename})
add_executable(${targetname} ${filename} ${TEST_HEADERS} ${XTENSOR_HEADERS})
add_executable(${targetname} main.cpp ${filename} ${TEST_HEADERS} ${XTENSOR_HEADERS})
if(XTENSOR_USE_XSIMD)
target_compile_definitions(${targetname}
PRIVATE
Expand All @@ -300,19 +263,16 @@ foreach(filename IN LISTS COMMON_BASE XTENSOR_TESTS)
if(XTENSOR_USE_OPENMP)
target_compile_definitions(${targetname} PRIVATE XTENSOR_USE_OPENMP)
endif()
if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
add_dependencies(${targetname} gtest_main)
endif()
target_include_directories(${targetname} PRIVATE ${XTENSOR_INCLUDE_DIR})
target_link_libraries(${targetname} PRIVATE xtensor GTest::GTest GTest::Main ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(${targetname} PRIVATE xtensor doctest::doctest ${CMAKE_THREAD_LIBS_INIT})
add_custom_target(
x${targetname}
COMMAND ${targetname}
DEPENDS ${targetname} ${filename} ${XTENSOR_HEADERS})
add_test(NAME ${targetname} COMMAND ${targetname})
endforeach()

add_executable(test_xtensor_lib ${COMMON_BASE} ${XTENSOR_TESTS} ${TEST_HEADERS} ${XTENSOR_HEADERS})
add_executable(test_xtensor_lib main.cpp ${COMMON_BASE} ${XTENSOR_TESTS} ${TEST_HEADERS} ${XTENSOR_HEADERS})
if(XTENSOR_USE_XSIMD)
target_compile_definitions(test_xtensor_lib
PRIVATE
Expand All @@ -329,12 +289,8 @@ if(XTENSOR_USE_OPENMP)
target_compile_definitions(test_xtensor_lib PRIVATE XTENSOR_USE_OPENMP)
endif()

if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
add_dependencies(test_xtensor_lib gtest_main)
endif()

target_include_directories(test_xtensor_lib PRIVATE ${XTENSOR_INCLUDE_DIR})
target_link_libraries(test_xtensor_lib PRIVATE xtensor GTest::GTest GTest::Main ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(test_xtensor_lib PRIVATE xtensor doctest::doctest ${CMAKE_THREAD_LIBS_INIT})

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

if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
add_dependencies(test_xtensor_core_lib gtest_main)
endif()

target_link_libraries(test_xtensor_core_lib PRIVATE xtensor GTest::GTest GTest::Main ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(test_xtensor_core_lib PRIVATE xtensor doctest::doctest ${CMAKE_THREAD_LIBS_INIT})
add_custom_target(coverity COMMAND coverity_scan DEPENDS test_xtensor_core_lib)
24 changes: 0 additions & 24 deletions test/copyGTest.cmake.in

This file was deleted.

25 changes: 0 additions & 25 deletions test/downloadGTest.cmake.in

This file was deleted.

21 changes: 5 additions & 16 deletions test/main.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht *
* Copyright (c) QuantStack *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

#include "gtest/gtest.h"

int main(int argc, char* argv[])
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#if defined(XTENSOR_DISABLE_EXCEPTIONS)
#define DOCTEST_CONFIG_NO_EXCEPTIONS
#endif
#include "doctest/doctest.h"
Loading

0 comments on commit 2618d5a

Please sign in to comment.