Skip to content

Commit b3041bd

Browse files
authored
Merge pull request #454 from JohanMabille/doctest
Migrated to doctest
2 parents 8aeb0bf + fbc0f53 commit b3041bd

File tree

9 files changed

+23
-111
lines changed

9 files changed

+23
-111
lines changed

.appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ install:
2727
- conda update -q conda
2828
- conda info -a
2929
# Install dependencies
30-
- conda install cmake dirent xeus-zmq=1.0.0 cling=0.8 clangdev=5 llvmdev=5 nlohmann_json cppzmq xtl=0.7 pugixml cxxopts=2.1.2 -c conda-forge
30+
- conda install cmake dirent xeus-zmq=1.0.0 cling=0.8 clangdev=5 llvmdev=5 nlohmann_json cppzmq xtl=0.7 pugixml cxxopts=2.1.2 doctest>=2.4.6 -c conda-forge
3131
# Build and install xeus-cling
3232
- mkdir build
3333
- cd build
34-
- cmake -G "NMake Makefiles" -D CMAKE_INSTALL_PREFIX=%MINICONDA%\\Library -D CMAKE_BUILD_TYPE=Release -D XEXTRA_JUPYTER_DATA_DIR=%MINICONDA%\\share\\jupyter -D DOWNLOAD_GTEST=ON ..
34+
- cmake -G "NMake Makefiles" -D CMAKE_INSTALL_PREFIX=%MINICONDA%\\Library -D CMAKE_BUILD_TYPE=Release -D XEXTRA_JUPYTER_DATA_DIR=%MINICONDA%\\share\\jupyter -D XEUS_CLING_BUILD_TESTS=ON ..
3535
- nmake
3636
- nmake install
3737
# Install jupyter_kernel_test and pytest

.azure-pipelines/unix-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ steps:
2020
source activate build-xeus-cling
2121
mkdir build
2222
cd build
23-
cmake -DCMAKE_PREFIX_PATH=$PREFIX -DCMAKE_INSTALL_PREFIX=$PREFIX -DDOWNLOAD_GTEST=ON -DCMAKE_INSTALL_LIBDIR=lib $(Build.SourcesDirectory)
23+
cmake -DCMAKE_PREFIX_PATH=$PREFIX -DCMAKE_INSTALL_PREFIX=$PREFIX -DXEUS_CLING_BUILD_TESTS=ON -DCMAKE_INSTALL_LIBDIR=lib $(Build.SourcesDirectory)
2424
displayName: Configure xeus-cling
2525
workingDirectory: $(Build.BinariesDirectory)
2626

CMakeLists.txt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,9 @@ endif(MSVC)
330330
# Tests #
331331
#########
332332

333-
OPTION(BUILD_TESTS "xeus-cling test suite" OFF)
334-
OPTION(DOWNLOAD_GTEST "build gtest from downloaded sources" OFF)
333+
OPTION(XEUS_CLING_BUILD_TESTS "xeus-cling test suite" OFF)
335334

336-
if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
337-
set(BUILD_TESTS ON)
338-
endif()
339-
340-
if(BUILD_TESTS)
335+
if(XEUS_CLING_BUILD_TESTS)
341336
add_subdirectory(test)
342337
endif()
343338

environment-host.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ dependencies:
1717
# Test dependencies
1818
- pytest
1919
- jupyter_kernel_test
20+
- doctest >= 2.4.6

test/CMakeLists.txt

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -30,52 +30,17 @@ if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
3030
set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO)
3131
endif()
3232

33-
if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
34-
if(DOWNLOAD_GTEST)
35-
# Download and unpack googletest at configure time
36-
configure_file(downloadGTest.cmake.in googletest-download/CMakeLists.txt)
37-
else()
38-
# Copy local source of googletest at configure time
39-
configure_file(copyGTest.cmake.in googletest-download/CMakeLists.txt)
40-
endif()
41-
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
42-
RESULT_VARIABLE result
43-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
44-
if(result)
45-
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
46-
endif()
47-
execute_process(COMMAND ${CMAKE_COMMAND} --build .
48-
RESULT_VARIABLE result
49-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
50-
if(result)
51-
message(FATAL_ERROR "Build step for googletest failed: ${result}")
52-
endif()
53-
54-
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
55-
56-
# Add googletest directly to our build. This defines
57-
# the gtest and gtest_main targets.
58-
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
59-
${CMAKE_CURRENT_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL)
60-
61-
set(GTEST_INCLUDE_DIRS "${gtest_SOURCE_DIR}/include")
62-
set(GTEST_BOTH_LIBRARIES gtest_main gtest)
63-
else()
64-
find_package(GTest REQUIRED)
65-
endif()
66-
33+
find_package(doctest)
6734
find_package(Threads)
6835

6936
include_directories(${GTEST_INCLUDE_DIRS} SYSTEM)
7037

7138
set(XEUS_CLING_TESTS
39+
main.cpp
7240
test_stream.cpp
7341
)
7442

7543
add_executable(test_xeus_cling ${XEUS_CLING_TESTS})
76-
if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
77-
add_dependencies(test_xeus_cling gtest_main)
78-
endif()
7944

8045
if (APPLE)
8146
set_target_properties(test_xeus_cling PROPERTIES
@@ -93,7 +58,7 @@ set_target_properties(test_xeus_cling PROPERTIES
9358
)
9459

9560
target_link_libraries(test_xeus_cling
96-
PRIVATE ${GTEST_BOTH_LIBRARIES}
61+
PRIVATE doctest::doctest
9762
PRIVATE ${CMAKE_THREAD_LIBS_INIT})
9863
target_include_directories(test_xeus_cling PRIVATE ${XEUS_CLING_INCLUDE_DIR})
9964

test/copyGTest.cmake.in

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

test/downloadGTest.cmake.in

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

test/main.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,5 @@
77
* The full license is in the file LICENSE, distributed with this software. *
88
************************************************************************************/
99

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-
}
10+
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
11+
#include "doctest/doctest.h"

test/test_stream.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* The full license is in the file LICENSE, distributed with this software. *
88
************************************************************************************/
99

10-
#include "gtest/gtest.h"
10+
#include "doctest/doctest.h"
1111

1212
#include <functional>
1313
#include <iostream>
@@ -23,13 +23,16 @@ void callback(std::string value, std::list<std::string>& outputs)
2323
outputs.push_back(value);
2424
}
2525

26-
TEST(stream, output)
26+
TEST_SUITE("stream")
2727
{
28-
std::list<std::string> outputs;
29-
xcpp::xoutput_buffer buffer(std::bind(callback, _1, std::ref(outputs)));
30-
auto cout_strbuf = std::cout.rdbuf();
31-
std::cout.rdbuf(&buffer);
32-
std::cout << "Some output" << std::endl;
33-
EXPECT_EQ(outputs.front(), "Some output\n");
34-
std::cout.rdbuf(cout_strbuf);
28+
TEST_CASE("output")
29+
{
30+
std::list<std::string> outputs;
31+
xcpp::xoutput_buffer buffer(std::bind(callback, _1, std::ref(outputs)));
32+
auto cout_strbuf = std::cout.rdbuf();
33+
std::cout.rdbuf(&buffer);
34+
std::cout << "Some output" << std::endl;
35+
REQUIRE_EQ(outputs.front(), "Some output\n");
36+
std::cout.rdbuf(cout_strbuf);
37+
}
3538
}

0 commit comments

Comments
 (0)