🎉 Added test coverage to sonarscan
This commit is contained in:
parent
f508e54ab0
commit
0dc0920b22
16
.github/workflows/sonarcloud.yml
vendored
16
.github/workflows/sonarcloud.yml
vendored
@ -3,8 +3,9 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- dev
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
types: [ opened, synchronize, reopened ]
|
||||
jobs:
|
||||
build:
|
||||
name: sonarcloud scan
|
||||
@ -15,6 +16,8 @@ jobs:
|
||||
BUILD_WRAPPER_OUT_DIR: sonar-out # Directory where build-wrapper output will be placed
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
@ -38,18 +41,23 @@ jobs:
|
||||
echo "$HOME/.sonar/build-wrapper-linux-x86" >> $GITHUB_PATH
|
||||
|
||||
- name: Configure
|
||||
run: cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TEST=ON .
|
||||
run: cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TEST=ON -DENABLE_COVERAGE=ON .
|
||||
|
||||
- name: Run build-wrapper
|
||||
run: |
|
||||
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} make -j4
|
||||
|
||||
- name: Test
|
||||
run: ctest .
|
||||
run: ctest --output-on-failure .
|
||||
|
||||
- name: Generate coverage
|
||||
run: make gcov
|
||||
|
||||
- name: Run sonar-scanner
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||
run: |
|
||||
sonar-scanner --define sonar.host.url="${{ env.SONAR_SERVER_URL }}" --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}"
|
||||
sonar-scanner \
|
||||
--define sonar.host.url="${{ env.SONAR_SERVER_URL }}" \
|
||||
--define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}"
|
||||
|
@ -4,6 +4,7 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
|
||||
include(CMakeCM)
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
|
131
cmake/CMakeCM.cmake
Normal file
131
cmake/CMakeCM.cmake
Normal file
@ -0,0 +1,131 @@
|
||||
macro(_cmcm_set_if_undef varname)
|
||||
if (NOT DEFINED "${varname}")
|
||||
set(__default "${ARGN}")
|
||||
else ()
|
||||
set(__default "${${varname}}")
|
||||
endif ()
|
||||
set("${varname}" "${__default}" CACHE STRING "" FORCE)
|
||||
endmacro()
|
||||
|
||||
# This is the base URL to resolve `LOCAL` modules
|
||||
_cmcm_set_if_undef(CMCM_LOCAL_RESOLVE_URL "https://AnotherFoxGuy.com/CMakeCM")
|
||||
# This is the directory where CMakeCM will store its downloaded modules
|
||||
_cmcm_set_if_undef(CMCM_MODULE_DIR "${CMAKE_BINARY_DIR}/_cmcm-modules")
|
||||
|
||||
function(cmcm_module name)
|
||||
set(options)
|
||||
set(args REMOTE LOCAL VERSION)
|
||||
set(list_args ALSO)
|
||||
cmake_parse_arguments(ARG "${options}" "${args}" "${list_args}" "${ARGV}")
|
||||
if (NOT ARG_REMOTE AND NOT ARG_LOCAL)
|
||||
message(FATAL_ERROR "Either LOCAL or REMOTE is required for cmcm_module")
|
||||
endif ()
|
||||
if (NOT ARG_VERSION)
|
||||
message(FATAL_ERROR "Expected a VERSION for cmcm_module")
|
||||
endif ()
|
||||
file(MAKE_DIRECTORY "${CMCM_MODULE_DIR}")
|
||||
file(WRITE "${CMCM_MODULE_DIR}/${name}"
|
||||
"_cmcm_include_module([[${name}]] [[${ARG_REMOTE}]] [[${ARG_LOCAL}]] [[${ARG_VERSION}]] [[${ARG_ALSO}]])\n"
|
||||
)
|
||||
endfunction()
|
||||
|
||||
macro(_cmcm_include_module name remote local version also)
|
||||
set(__module_name "${name}")
|
||||
set(__remote "${remote}")
|
||||
set(__local "${local}")
|
||||
set(__version "${version}")
|
||||
get_filename_component(__resolved_dir "${CMCM_MODULE_DIR}/resolved" ABSOLUTE)
|
||||
get_filename_component(__resolved "${__resolved_dir}/${__module_name}" ABSOLUTE)
|
||||
get_filename_component(__resolved_stamp "${CMCM_MODULE_DIR}/resolved/${__module_name}.whence" ABSOLUTE)
|
||||
set(__whence_string "${CMCM_LOCAL_RESOLVE_URL}::${__remote}${__local}.${__version}")
|
||||
set(__download FALSE)
|
||||
if (EXISTS "${__resolved}")
|
||||
file(READ "${__resolved_stamp}" __stamp)
|
||||
if (NOT __stamp STREQUAL __whence_string)
|
||||
set(__download TRUE)
|
||||
endif ()
|
||||
else ()
|
||||
set(__download TRUE)
|
||||
endif ()
|
||||
if (__download)
|
||||
file(MAKE_DIRECTORY "${__resolved_dir}")
|
||||
if (__remote)
|
||||
set(__url "${__remote}")
|
||||
else ()
|
||||
set(__url "${CMCM_LOCAL_RESOLVE_URL}/${__local}")
|
||||
endif ()
|
||||
message(STATUS "[CMakeCM] Downloading new module ${__module_name}")
|
||||
file(DOWNLOAD
|
||||
"${__url}"
|
||||
"${__resolved}"
|
||||
STATUS __st
|
||||
)
|
||||
list(GET __st 0 __rc)
|
||||
list(GET __st 1 __msg)
|
||||
if (__rc)
|
||||
message(FATAL_ERROR "Error while downloading file from '${__url}' to '${__resolved}' [${__rc}]: ${__msg}")
|
||||
endif ()
|
||||
file(WRITE "${__resolved_stamp}" "${__whence_string}")
|
||||
endif ()
|
||||
include("${__resolved}")
|
||||
endmacro()
|
||||
|
||||
list(INSERT CMAKE_MODULE_PATH 0 "${CMCM_MODULE_DIR}")
|
||||
|
||||
cmcm_module(FindFilesystem.cmake
|
||||
LOCAL modules/FindFilesystem.cmake
|
||||
VERSION 1
|
||||
)
|
||||
|
||||
cmcm_module(CMakeRC.cmake
|
||||
REMOTE https://cdn.statically.io/gh/vector-of-bool/cmrc/a64bea50/CMakeRC.cmake
|
||||
VERSION 2
|
||||
)
|
||||
|
||||
cmcm_module(FindBikeshed.cmake
|
||||
LOCAL modules/FindBikeshed.cmake
|
||||
VERSION 1
|
||||
)
|
||||
|
||||
cmcm_module(cotire.cmake
|
||||
REMOTE https://cdn.statically.io/gh/sakra/cotire/cotire-1.8.1/CMake/cotire.cmake
|
||||
VERSION 1.8.1
|
||||
)
|
||||
|
||||
cmcm_module(C++Concepts.cmake
|
||||
LOCAL modules/C++Concepts.cmake
|
||||
VERSION 1
|
||||
)
|
||||
|
||||
cmcm_module(codecov.cmake
|
||||
LOCAL modules/codecov.cmake
|
||||
VERSION 2
|
||||
)
|
||||
cmcm_module(FindGcov.cmake
|
||||
LOCAL modules/FindGcov.cmake
|
||||
VERSION 2
|
||||
)
|
||||
cmcm_module(FindLcov.cmake
|
||||
LOCAL modules/FindLcov.cmake
|
||||
VERSION 2
|
||||
)
|
||||
|
||||
cmcm_module(JSONParser.cmake
|
||||
LOCAL modules/JSONParser.cmake
|
||||
VERSION 1
|
||||
)
|
||||
|
||||
cmcm_module(libman.cmake
|
||||
REMOTE https://cdn.statically.io/gh/vector-of-bool/libman/85c5d23e700a9ed6b428aa78cfa556f60b925477/cmake/libman.cmake
|
||||
VERSION 1
|
||||
)
|
||||
|
||||
cmcm_module(UseLATEX.cmake
|
||||
REMOTE https://gitlab.kitware.com/kmorel/UseLATEX/raw/Version2.7.2/UseLATEX.cmake
|
||||
VERSION 2.7.2
|
||||
)
|
||||
|
||||
cmcm_module(conan.cmake
|
||||
REMOTE https://cdn.statically.io/gh/conan-io/cmake-conan/0.18.1/conan.cmake
|
||||
VERSION 0.18.1
|
||||
)
|
@ -9,4 +9,6 @@ sonar.projectVersion=1.2.0
|
||||
sonar.sources=.
|
||||
|
||||
# Encoding of the source code. Default is default system encoding
|
||||
#sonar.sourceEncoding=UTF-8
|
||||
#sonar.sourceEncoding=UTF-8
|
||||
|
||||
sonar.cfamily.gcov.reportsPath=test
|
@ -3,11 +3,14 @@ find_package(Catch2 REQUIRED)
|
||||
|
||||
include(CTest)
|
||||
include(Catch)
|
||||
include(codecov)
|
||||
|
||||
add_executable(${PROJECT_NAME} main.cpp test.cpp link_test.cpp)
|
||||
target_include_directories(moFileReaderTest PRIVATE ${CMAKE_SOURCE_DIR}/include)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Catch2::Catch2)
|
||||
catch_discover_tests(${PROJECT_NAME})
|
||||
catch_discover_tests(${PROJECT_NAME} REPORTER sonarqube OUTPUT_DIR reports)
|
||||
add_coverage(${PROJECT_NAME})
|
||||
coverage_evaluate()
|
||||
|
||||
add_custom_command(
|
||||
TARGET ${PROJECT_NAME} POST_BUILD
|
||||
|
@ -1,2 +1,3 @@
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
#include "catch.hpp"
|
||||
#include "catch_reporter_sonarqube.hpp"
|
Loading…
x
Reference in New Issue
Block a user