From 58b4a21deb8e40a375b237f4f8e4966f1674ee76 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 9 Jan 2020 17:43:54 +0200 Subject: [PATCH] Add CMake tests --- .travis.yml | 28 +++++++++++++++++++++++--- CMakeLists.txt | 6 ++++++ test/CMakeLists.txt | 11 ++++++++++ test/Jamfile | 2 ++ test/cmake_install_test/CMakeLists.txt | 17 ++++++++++++++++ test/cmake_subdir_test/CMakeLists.txt | 4 ++-- test/{cmake_subdir_test => }/quick.cpp | 0 7 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 test/CMakeLists.txt create mode 100644 test/cmake_install_test/CMakeLists.txt rename test/{cmake_subdir_test => }/quick.cpp (100%) diff --git a/.travis.yml b/.travis.yml index 7d0152d..d4ecf7c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -251,22 +251,44 @@ matrix: compiler: clang++ env: UBSAN=1 TOOLSET=clang COMPILER=clang++ CXXSTD=11,14,1z UBSAN_OPTIONS=print_stacktrace=1 + - os: linux + env: CMAKE_TEST=1 + script: + - mkdir __build__ && cd __build__ + - cmake -DBOOST_ENABLE_CMAKE=1 -DBoost_VERBOSE=1 -DBOOST_INCLUDE_LIBRARIES=variant2 .. + - ctest --output-on-failure -R boost_variant2 + - os: linux compiler: g++ env: CMAKE_SUBDIR_TEST=1 + install: + - BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true + - git clone -b $BOOST_BRANCH https://github.com/boostorg/assert.git ../assert + - git clone -b $BOOST_BRANCH https://github.com/boostorg/config.git ../config + - git clone -b $BOOST_BRANCH https://github.com/boostorg/core.git ../core + - git clone -b $BOOST_BRANCH https://github.com/boostorg/mp11.git ../mp11 script: - - cd libs/variant2/test/cmake_subdir_test && mkdir __build__ && cd __build__ + - cd test/cmake_subdir_test && mkdir __build__ && cd __build__ - cmake .. - cmake --build . - cmake --build . --target check + - os: linux + env: CMAKE_INSTALL_TEST=1 + script: + - mkdir __build__ && cd __build__ + - cmake -DBOOST_ENABLE_CMAKE=1 -DBoost_VERBOSE=1 -DBOOST_INCLUDE_LIBRARIES="variant2;config;mp11" -DCMAKE_INSTALL_PREFIX=~/.local .. + - cmake --build . --target install + - cd ../libs/variant2/test/cmake_install_test && mkdir __build__ && cd __build__ + - cmake -DCMAKE_INSTALL_PREFIX=~/.local .. + - cmake --build . + - cmake --build . --target check + install: - BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true - cd .. - git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root - cd boost-root - - git submodule update --init tools/build - - git submodule update --init libs/config - git submodule update --init tools/boostdep - mkdir -p libs/variant2 - cp -r $TRAVIS_BUILD_DIR/* libs/variant2 diff --git a/CMakeLists.txt b/CMakeLists.txt index 531a409..9d509ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,3 +23,9 @@ if(BOOST_SUPERPROJECT_VERSION) boost_install(TARGETS boost_variant2 HEADER_DIRECTORY include/) endif() + +if(BUILD_TESTING) + + add_subdirectory(test) + +endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..512feea --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,11 @@ +# Copyright 2018, 2019 Peter Dimov +# Distributed under the Boost Software License, Version 1.0. +# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt + +include(BoostTestJamfile OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST) + +if(HAVE_BOOST_TEST) + +boost_test_jamfile(FILE Jamfile LINK_LIBRARIES Boost::variant2 Boost::core) + +endif() diff --git a/test/Jamfile b/test/Jamfile index 1093712..22cfe2d 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -23,6 +23,8 @@ project clang:on ; +run quick.cpp ; + run variant_size.cpp ; run variant_alternative.cpp ; diff --git a/test/cmake_install_test/CMakeLists.txt b/test/cmake_install_test/CMakeLists.txt new file mode 100644 index 0000000..62a1176 --- /dev/null +++ b/test/cmake_install_test/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright 2018, 2019 Peter Dimov +# Distributed under the Boost Software License, Version 1.0. +# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt + +cmake_minimum_required(VERSION 3.5...3.16) + +project(cmake_install_test LANGUAGES CXX) + +find_package(boost_variant2 REQUIRED) + +add_executable(quick ../quick.cpp) +target_link_libraries(quick Boost::variant2) + +enable_testing() +add_test(quick quick) + +add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $) diff --git a/test/cmake_subdir_test/CMakeLists.txt b/test/cmake_subdir_test/CMakeLists.txt index 90fd014..91ad663 100644 --- a/test/cmake_subdir_test/CMakeLists.txt +++ b/test/cmake_subdir_test/CMakeLists.txt @@ -2,7 +2,7 @@ # Distributed under the Boost Software License, Version 1.0. # See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.5...3.16) project(cmake_subdir_test LANGUAGES CXX) @@ -10,7 +10,7 @@ add_subdirectory(../.. boostorg/variant2) add_subdirectory(../../../config boostorg/config) add_subdirectory(../../../mp11 boostorg/mp11) -add_executable(quick quick.cpp) +add_executable(quick ../quick.cpp) target_link_libraries(quick Boost::variant2) enable_testing() diff --git a/test/cmake_subdir_test/quick.cpp b/test/quick.cpp similarity index 100% rename from test/cmake_subdir_test/quick.cpp rename to test/quick.cpp