From ac7ea4c70f34bdc6d124d104c185079fbfef3607 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Mon, 23 May 2016 01:37:35 -0400 Subject: [PATCH] tests: Fix coverage data As the documentation generation insert increasingly large ammount of code into the lua files, the coverage data is getting less and less accurate. This try to fix this by only collecting such data after the `configure_file` calls are done. --- .travis.yml | 4 ++-- awesomeConfig.cmake | 10 ++++++++++ tests/examples/CMakeLists.txt | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index f769b9b6f..c9d81b132 100644 --- a/.travis.yml +++ b/.travis.yml @@ -84,14 +84,14 @@ install: - travis_retry sudo luarocks install lua-discount # Instal luacov-coveralls for code coverage testing. - - if [ "$DO_COVERAGE" = "true" ]; then sudo luarocks install luacov-coveralls; fi + - if [ "$DO_COVERAGE" = "true" ]; then sudo luarocks install luacov-coveralls; else export DO_COVERAGE=0; fi # Determine custom version. - export AWESOME_VERSION="${TRAVIS_BRANCH}-g$(git rev-parse --short HEAD)" - 'if [ "$TRAVIS_PULL_REQUEST" != false ]; then AWESOME_VERSION="${AWESOME_VERSION}-PR${TRAVIS_PULL_REQUEST}"; fi' script: - - export CMAKE_ARGS="-DLUA_LIBRARY=${LUALIBRARY} -DLUA_INCLUDE_DIR=${LUAINCLUDE} -D OVERRIDE_VERSION=$AWESOME_VERSION" + - export CMAKE_ARGS="-DLUA_LIBRARY=${LUALIBRARY} -DLUA_INCLUDE_DIR=${LUAINCLUDE} -D OVERRIDE_VERSION=$AWESOME_VERSION -D DO_COVERAGE=${DO_COVERAGE}" - | if [ -n "$BUILD_IN_DIR" ]; then SOURCE_DIRECTORY="$PWD" diff --git a/awesomeConfig.cmake b/awesomeConfig.cmake index 7f2fd5d16..a37d57109 100644 --- a/awesomeConfig.cmake +++ b/awesomeConfig.cmake @@ -346,4 +346,14 @@ foreach(file ${AWESOME_ADDITIONAL_FILES}) endforeach() #}}} +# The examples coverage need to be done again after the configure_file has +# inserted the additional code. Otherwise, the result will be off, rendering +# the coverage useless as a tool to track untested code. +if(GENERATE_DOC AND DO_COVERAGE) + message(STATUS "Running tests again with coverage") + set(USE_LCOV 1) + + include(tests/examples/CMakeLists.txt) +endif() + # vim: filetype=cmake:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80:foldmethod=marker diff --git a/tests/examples/CMakeLists.txt b/tests/examples/CMakeLists.txt index 0c40ede3c..ab9511fa4 100644 --- a/tests/examples/CMakeLists.txt +++ b/tests/examples/CMakeLists.txt @@ -144,11 +144,16 @@ function(run_test test_path namespace template escaped_content) get_filename_component(${test_path} TEST_FILE_NAME NAME) set(IMAGE_PATH "${IMAGE_DIR}/AUTOGEN${namespace}_${TEST_FILE_NAME}") + # Use the example testing as coverage source + if (USE_LCOV) + set(LCOV_PATH ${SOURCE_DIR}/.luacov) + endif() + # Execute the script, leave the image extension decision to the test # SVG is preferred, but PNG is better suited for some tests, like bitmap # patterns. execute_process( - COMMAND lua ${template} ${test_path} ${IMAGE_PATH} ${SOURCE_DIR}/.luacov + COMMAND lua ${template} ${test_path} ${IMAGE_PATH} ${LCOV_PATH} OUTPUT_VARIABLE TEST_OUTPUT ERROR_VARIABLE TEST_ERROR )