How do you exclude folders with colcon test?
The Problem (TL;DR)
I'm trying to run a series of tests and linters with colcon test
. But for some reason, colcon or CMake (not sure which) seems to test a bunch of build files, which are auto-generated and generate a ton of errors that have nothing to do with my source code, but clutter the test output, making it very difficult to actually figure out if the source code needs to be fixed.
How do I explicitly tell colcon test what folders to test (or not)?
The Problem (full explanation)
I'm running colcon tests with:
$ colcon build --cmake-args -DBUILD_TESTING=ON --packages-up-to my_package
$ colcon test --packages-select my_package --event-handlers=console_cohesion+
In my CMakeList file, I have set up the following tests with this code:
if(BUILD_TESTING)
find_package(ament_cmake_clang_tidy REQUIRED)
find_package(ament_cmake_xmllint REQUIRED)
ament_xmllint()
find_package(ament_cmake_clang_format REQUIRED)
ament_clang_format(CONFIG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../../../.clang-format)
find_package(ament_cmake_lint_cmake REQUIRED)
ament_lint_cmake()
find_package(ros_testing REQUIRED)
add_ros_test(
test/test_talker.py
TIMEOUT "30"
)
find_package(ament_cmake_gtest REQUIRED)
find_package(ament_cmake_gmock REQUIRED)
set(TEST_SOURCES test/test_listener.cpp)
set(TEST_RST_EXE test_listener)
ament_add_gtest(${TEST_RST_EXE} ${TEST_SOURCES})
target_link_libraries(${TEST_RST_EXE} ${TEMPLATE_LISTENER_NODE}_lib)
endif()
But several of these tests fail, and they fail with lines like this:
2: [build/my_package/CMakeFiles/3.24.0/CompilerIdCXX/CMakeCXXCompilerId.cpp:790:53]: Replace [ ] with [\n ]
2: - const char* info_language_extensions_default = "INFO" ":" "extensions_default["
2: + const char* info_language_extensions_default = "INFO"
2: +
or
3: build/my_package/ament_cmake_package_templates/templates.cmake:14: Lines should be <= 140 characters long [linelength]
... There are lines and lines of this junk, testing not my source code but build and install files that are auto-generated, and so shouldn't best tested in the first place. How do I change either the colcon test
commands, or the code in the CMakeList file to exclude the build and install folders?