From bbef5f7c0c06fd87787d132b5810c5c3dc7415a9 Mon Sep 17 00:00:00 2001 From: Tomas Baca Date: Fri, 9 Feb 2024 09:32:58 +0100 Subject: [PATCH] updated the test format --- CMakeLists.txt | 4 +++- test/compile_tests.sh | 2 +- test/gather_coverage.sh | 25 +++++++++++++++++++++++++ test/{all_tests.sh => run_tests.sh} | 4 ---- 4 files changed, 29 insertions(+), 6 deletions(-) create mode 100755 test/gather_coverage.sh rename test/{all_tests.sh => run_tests.sh} (53%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 55507ab..51f2f9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -206,7 +206,9 @@ target_link_libraries(MrsUavTrackers_MidairActivationTracker ## | Testing | ## -------------------------------------------------------------- -if(CATKIN_ENABLE_TESTING) +if(CATKIN_ENABLE_TESTING AND MRS_ENABLE_TESTING) + + message(WARNING "Testing enabled.") add_subdirectory(test) diff --git a/test/compile_tests.sh b/test/compile_tests.sh index 999699e..efbc058 100755 --- a/test/compile_tests.sh +++ b/test/compile_tests.sh @@ -7,4 +7,4 @@ trap 'echo "$0: \"${last_command}\" command failed with exit code $?"' ERR # build the package catkin build --this # it has to be fully built normally before building with --catkin-make-args tests -catkin build --this --no-deps --catkin-make-args tests +catkin build --this -DMRS_ENABLE_TESTING=1 --no-deps --catkin-make-args tests diff --git a/test/gather_coverage.sh b/test/gather_coverage.sh new file mode 100755 index 0000000..27404da --- /dev/null +++ b/test/gather_coverage.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +while [ ! -e ".catkin_tools" ]; do + cd .. + if [[ `pwd` == "/" ]]; then + # we reached the root and didn't find the build/COLCON_IGNORE file - that's a fail! + echo "$0: could not find the root of the current workspace". + return 1 + fi +done + +WORKSPACE_NAME=${PWD##*/} + +cd build + +lcov --capture --directory . --output-file coverage.info +lcov --remove coverage.info "*/test/*" --output-file coverage.info.removed +lcov --extract coverage.info.removed "*/${WORKSPACE_NAME}/src/*" --output-file coverage.info.cleaned +genhtml --title "MRS UAV System - Test coverage report" --demangle-cpp --legend --frames --show-details -o coverage_html coverage.info.cleaned | tee /tmp/genhtml.log + +COVERAGE_PCT=`cat /tmp/genhtml.log | tail -n 1 | awk '{print $2}'` + +echo "Coverage: $COVERAGE_PCT" + +xdg-open coverage_html/index.html diff --git a/test/all_tests.sh b/test/run_tests.sh similarity index 53% rename from test/all_tests.sh rename to test/run_tests.sh index aa6ca4e..6f0fb27 100755 --- a/test/all_tests.sh +++ b/test/run_tests.sh @@ -5,8 +5,4 @@ set -e trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG trap 'echo "$0: \"${last_command}\" command failed with exit code $?"' ERR -# build the package -catkin build --this # it has to be fully built normally before building with --catkin-make-args tests -catkin build --this --no-deps --catkin-make-args tests - catkin test --this -i -p 1 -s