From a11802272445f8f2b3d7d7adf058a10c9a13a7e1 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Wed, 5 Dec 2018 18:21:01 +0000 Subject: [PATCH] Testingupdates --- .gitlab-ci.yml | 2 +- chapters/features/modules.md | 3 +++ chapters/intro/installing.md | 6 +++--- chapters/testing.md | 6 ++++++ chapters/testing/googletest.md | 2 +- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1c5a726..83fe5b0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ test_code: stage: test before_script: - mkdir -p $HOME/.local - - curl -s "https://cmake.org/files/v3.13/cmake-3.13.0-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C $HOME/.local + - curl -s "https://cmake.org/files/v3.13/cmake-3.13.1-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C $HOME/.local - export PATH=$HOME/.local/bin:$PATH script: - mkdir -p build diff --git a/chapters/features/modules.md b/chapters/features/modules.md index 102511d..8108f7c 100644 --- a/chapters/features/modules.md +++ b/chapters/features/modules.md @@ -26,6 +26,9 @@ if(NOT BUILD_TESTS_DEFAULT) mark_as_advanced(BUILD_TESTS) endif() ``` + +Note that `BUILD_TESTING` is a better way to check for testing being enabled if you use `include(CTest)`, since it is defined for you. This is just an example of `CMakeDependentOption`. + ## «module:CMakePrintHelpers» diff --git a/chapters/intro/installing.md b/chapters/intro/installing.md index 18d953f..0a2b1f4 100644 --- a/chapters/intro/installing.md +++ b/chapters/intro/installing.md @@ -13,13 +13,13 @@ You can [download CMake from KitWare][cmake-download]. This is how you'll probab On Linux, there are binaries provided, but you'll need to pick an install location. If you already use `~/.local` for user-space packages, the following single line command[^1] will get CMake for you [^2]: {% term %} -~ $ wget -qO- "https://cmake.org/files/v3.13/cmake-3.13.0-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C ~/.local +~ $ wget -qO- "https://cmake.org/files/v3.13/cmake-3.13.1-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C ~/.local {% endterm %} If you just want a local folder with CMake only: {% term %} -~ $ mkdir -p cmake-3.13 && wget -qO- "https://cmake.org/files/v3.13/cmake-3.13.0-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C cmake-3.13 +~ $ mkdir -p cmake-3.13 && wget -qO- "https://cmake.org/files/v3.13/cmake-3.13.1-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C cmake-3.13 ~ $ export PATH=`pwd`/cmake-3.13/bin:$PATH {% endterm %} @@ -28,7 +28,7 @@ You'll obviously want to append to the PATH every time you start a new terminal, And, if you want a system install, install to `/usr/local`; this is an excellent choice in a Docker container, for example on GitLab CI. Do not try it on a non-containerized system. {% term %} -docker $ wget -qO- "https://cmake.org/files/v3.13/cmake-3.13.0-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local +docker $ wget -qO- "https://cmake.org/files/v3.13/cmake-3.13.1-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local {% endterm %} diff --git a/chapters/testing.md b/chapters/testing.md index 0271fd4..479d268 100644 --- a/chapters/testing.md +++ b/chapters/testing.md @@ -4,6 +4,12 @@ In your main CMakeLists.txt you need to add the following function call (not in a subfolder): +```cmake +include(CTest) +``` + +Which will enable testing and set a `BUILD_TESTING` option so users can turn testing on and off (Along with [a few other things](https://gitlab.kitware.com/cmake/cmake/blob/master/Modules/CTest.cmake)). Or you can do this yourself: + ```cmake enable_testing() ``` diff --git a/chapters/testing/googletest.md b/chapters/testing/googletest.md index 43bcdd5..5b9e73f 100644 --- a/chapters/testing/googletest.md +++ b/chapters/testing/googletest.md @@ -51,7 +51,7 @@ Then, to add a test, I'd recommend the following macro: macro(package_add_test TESTNAME) add_executable(${TESTNAME} ${ARGN}) target_link_libraries(${TESTNAME} gtest gmock gtest_main) - add_test(${TESTNAME} ${TESTNAME}) + add_test(${TESTNAME} COMMAND ${TESTNAME}) set_target_properties(${TESTNAME} PROPERTIES FOLDER tests) endmacro()