ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How do you exclude folders with colcon test?

asked 2023-01-03 19:09:06 -0500

M@t gravatar image

updated 2023-01-04 20:11:22 -0500

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?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2023-01-18 10:11:28 -0500

ryanf55 gravatar image

I see one problem. It looks like your build directory is in the same folder as your CMakeLists.txt. The linters lint any files in that directory. Building inside the package is considered in-tree and is not recommended by ROS; that's why in the tutorials they make you create a "workspace" and put a src/ directory inside of it. Then, the build folder does not get linted by any of the packages.

That said, ament_cmake_flake8 was an issue I fixed, and it's merged into (rolling), but not humble or galactic.

edit flag offensive delete link more

Comments

I do have an out-of-source build. so my directory structure looks like:

package_name/
    src/
    install/
    build/

Does that mean something is configured incorrectly in my CMakelist?

M@t gravatar image M@t  ( 2023-01-24 18:56:52 -0500 )edit
0

answered 2023-01-04 20:30:45 -0500

M@t gravatar image

updated 2023-01-04 20:31:15 -0500

So after reading a ton of source code and docs, it turns out that only some of the linters provided in the ament_lint repo support any kind of "exclude" feature. They are:

Everything else doesn't seem to have any exclude feature implemented (although don't let me stop you from implementing this feature if you have the time).

As for actually implementing these exclusions, you have two methods:

  1. Set AMENT_LINT_AUTO_FILE_EXCLUDE if you're using ament_lint_auto - see the readme for implementation details
  2. Setting the exclude paths explicitly, when you manually call the linter in your CMakeLists file e.g:

    file(GLOB_RECURSE EXCLUDE_FILES
        build/*
        install/*
    )
    ament_cmake_cpplint(EXCLUDE ${EXCLUDE_FILES})
    

For further reading, here are some relevant issues from the repo:

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2023-01-03 19:09:06 -0500

Seen: 708 times

Last updated: Jan 04 '23