Skip to content

Commit

Permalink
publish test report and code coverage on analysis pipeline. Fixes #143
Browse files Browse the repository at this point in the history
  • Loading branch information
Raffaello committed May 21, 2020
1 parent 5b8d806 commit d176ccd
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 28 deletions.
17 changes: 3 additions & 14 deletions azure-pipelines/templates/ci-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,9 @@ steps:
arch: ${{ parameters.arch }}
#build_wrapper:
- ${{ if eq(parameters.test, true) }}:
- script: ctest -C ${{ parameters.build_type }} -v -V -T Test
displayName: cmake test (ctest)
workingDirectory: build
- task: PublishTestResults@2
inputs:
testResultsFormat: 'cTest' # Options: JUnit, NUnit, VSTest, xUnit, cTest
testResultsFiles: '**/Test.xml'
searchFolder: build # Optional
#mergeTestResults: false # Optional
#failTaskOnFailedTests: false # Optional
#testRunTitle: # Optional
#buildPlatform: # Optional
#buildConfiguration: # Optional
#publishRunAttachments: true # Optional
- template: 'cmake-test-steps.yml'
parameters:
build_type: ${{ parameters.build_type }}

- ${{ if eq(parameters.install, true) }}:
- script: cmake --build . --target install
Expand Down
20 changes: 20 additions & 0 deletions azure-pipelines/templates/cmake-test-steps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
parameters:
- name: build_type
displayName: Build Type
type: string

steps:
- script: ctest -C ${{ parameters.build_type }} -v -V -T Test
displayName: cmake test (ctest)
workingDirectory: build
- task: PublishTestResults@2
inputs:
testResultsFormat: 'cTest' # Options: JUnit, NUnit, VSTest, xUnit, cTest
testResultsFiles: '**/Test.xml'
searchFolder: build # Optional
#mergeTestResults: false # Optional
#failTaskOnFailedTests: false # Optional
#testRunTitle: # Optional
#buildPlatform: # Optional
#buildConfiguration: # Optional
#publishRunAttachments: true # Optional
36 changes: 25 additions & 11 deletions azure-pipelines/templates/sonarcloud-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,10 @@ jobs:
arch: ${{ parameters.arch }}
build_wrapper: "${{ parameters.build_wrapper }} --out-dir bw-output"

- ${{ if eq(parameters.test, true) }}:
- script: ctest -C ${{ parameters.build_type }}
displayName: ctest
workingDirectory: build
# /usr/local/Cellar/llvm/10.0.0_3/bin/llvm-cov
- template: 'cmake-test-steps.yml'
parameters:
build_type: ${{ parameters.build_type }}

- bash: |
echo '#!/bin/bash' > g.sh
echo 'exec /usr/local/Cellar/llvm/10.0.0_3/bin/llvm-cov gcov "$@"' >> g.sh
Expand All @@ -146,20 +145,35 @@ jobs:
# condition: ne(variables['Agent.OS'], 'Windows_NT')
- bash: |
echo $OSTYPE
test $OSTYPE = "darwin19" && brew install lcov || apt-get install -y lcov
#brew install lcov
#echo "finding..."
#find . -name *.gcda
#echo "...."
test $OSTYPE = "darwin19" && brew install lcov || apt-get install -y lcov
./g.sh -f -b -u $(find . -name *.gcda)
lcov --directory . --base-directory . --gcov-tool ./g.sh --capture -o cov.info
lcov --remove cov.info '/Applications/*' --output-file coverage.info
lcov --list coverage.info
bash <(curl -s https://codecov.io/bash) -f coverage.info -t b8f07100-6985-49f7-aa4c-14e36f29ac80
#gcovr -r ../ --filter ../sdl2-vga-terminal/src -o sonarcube.xml --sonarqube
#gcovr -r ../ --filter ../sdl2-vga-terminal/src -o cobertura.xml --cobertura
displayName: collect coverage data
workingDirectory: build
condition: ne(variables['Agent.OS'], 'Windows_NT')
- bash: bash <(curl -s https://codecov.io/bash) -f coverage.info -t b8f07100-6985-49f7-aa4c-14e36f29ac80s
displayName: codeCov
workingDirectory: build
- bash: |
curl https://raw.githubusercontent.com/eriwen/lcov-to-cobertura-xml/master/lcov_cobertura/lcov_cobertura.py -o lcov_cobertura.py
lcov_cobertura.py cov.info -o cobertura.xml
displayName: gen cobertura.xml
workingDirectory: build
- task: SonarCloudAnalyze@1
- task: SonarCloudPublish@1
inputs:
pollingTimeoutSec: ${{ parameters.publish_timeout }}
# Publish code coverage results
# Publish Cobertura or JaCoCo code coverage results from a build
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: 'cobertura' #'JaCoCo' # Options: cobertura, jaCoCo
summaryFileLocation:
pathToSources: sdl2-vga-terminal/src # Optional
reportDirectory: build # Optional
#additionalCodeCoverageFiles: # Optional
#failIfCoverageEmpty: false # Optional
2 changes: 1 addition & 1 deletion sdl2-vga-terminal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "^GNU")
target_compile_options(vga-terminal-static PRIVATE
$<$<CONFIG:DEBUG>: -fprofile-arcs; -ftest-coverage;>
)
target_link_options(vga-terminal-static PRIVATE $<$<CONFIG:DEBUG>:-fprofile-arcs; -ftest-coverage; --coverage;>)
target_link_options(vga-terminal-static PUBLIC $<$<CONFIG:DEBUG>:-fprofile-arcs; -ftest-coverage; --coverage;>)
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang")
target_compile_options(vga-terminal-static PRIVATE -WCL4 -Wabstract-vbase-init -Wassign-enum
Expand Down
4 changes: 2 additions & 2 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ sonar.tests=sdl2-vga-terminal/test
sonar.cfamily.build-wrapper-output=build/bw-output
sonar.cfamily.threads=2
sonar.cfamily.cache.enabled=false
sonar.cfamily.gcov.reportsPath=build
#sonar.cfamily.llvm-cov.reportPath=build
sonar.cfamily.gcov.reportsPath=build/**
#sonar.cfamily.llvm-cov.reportPath=build/**

0 comments on commit d176ccd

Please sign in to comment.