From aa1bbb0b570b34be19b63f7affbab7f2ceecbae0 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Fri, 27 Oct 2017 05:40:58 +0200 Subject: [PATCH] ci: use ctest scripts to run the tests --- .travis.yml | 6 ++-- cmake/ctest/travis_script.cmake | 63 +++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 cmake/ctest/travis_script.cmake diff --git a/.travis.yml b/.travis.yml index e58c4b9b..4dedfd43 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,10 +25,8 @@ addons: git: depth: 3 script: - - mkdir build - - cd build - - cmake .. -DBUILD_TESTS=1 -DTESTS_NODATA=1 -DBUILD_VIEWER=1 && make - - tests/run_tests + - ctest -S cmake/ctest/travis_script.cmake -VV -DSRC_DIR=. -DBIN_DIR=build + - if [ -f FATAL_ERROR ]; then printf "Fatal failure detected.\nExiting with non-zero result code.\n"; exit 1; fi notifications: email: false # irc: diff --git a/cmake/ctest/travis_script.cmake b/cmake/ctest/travis_script.cmake new file mode 100644 index 00000000..20b8de07 --- /dev/null +++ b/cmake/ctest/travis_script.cmake @@ -0,0 +1,63 @@ +cmake_minimum_required(VERSION 3.2.2) + +set(TRAVIS "$ENV{TRAVIS}") + +if(TRAVIS) + message("travis_script: Travis detected") + set(CTEST_SITE "Travis") + string(SUBSTRING "$ENV{TRAVIS_COMMIT}" 0 8 SHORT_COMMIT) + set(CTEST_BUILD_NAME "$ENV{TRAVIS_EVENT_TYPE}-$ENV{TRAVIS_REPO_SLUG}-$ENV{TRAVIS_BRANCH}-${SHORT_COMMIT}") +else() + message("travis_script: Travis NOT detected") +endif() + +get_filename_component(SRC_DIR "${SRC_DIR}" ABSOLUTE) +get_filename_component(BIN_DIR "${BIN_DIR}" ABSOLUTE) + +set(CTEST_SOURCE_DIRECTORY "${SRC_DIR}") +set(CTEST_BINARY_DIRECTORY "${BIN_DIR}") + +set(CTEST_CMAKE_GENERATOR "Unix Makefiles") +ctest_empty_binary_directory("${BIN_DIR}") + +ctest_start("Continuous") +ctest_configure( + OPTIONS + "-DBUILD_VIEWER=1;-DBUILD_TESTS=1;-DTESTS_NODATA=1" + RETURN_VALUE + CONFIGURE_RESULT + ) +ctest_build( + NUMBER_ERRORS BUILD_NB_ERRORS + NUMBER_WARNINGS BUILD_NB_WARNINGS + ) + +ctest_test( + RETURN_VALUE TEST_RESULT + ) + +file(REMOVE FATAL_ERROR) +if(NOT CONFIGURE_RESULT EQUAL "0") + message(WARNING "Configure error detected!") + file(APPEND "FATAL_ERROR" "configure error\n") +endif() + +if(NOT BUILD_NB_ERRORS EQUAL "0") + message(WARNING "Build failure detected!") + file(APPEND "FATAL_ERROR" "build error\n") +endif() + +if(NOT TEST_RESULT EQUAL "0") + message(WARNING "Test failure detected!") + file(WRITE "FATAL_ERROR" "test(s) error\n") +endif() + +if(TRAVIS) + ctest_submit( + RETURN_VALUE SUBMIT_RESULT + ) + + if(NOT SUBMIT_RESULT EQUAL "0") + message(WARNING "Submit failure detected!") + endif() +endif()