Skip to content

Commit

Permalink
Place all unit test executables in the same build subdirectory (#2658)
Browse files Browse the repository at this point in the history
Use existing CMake function `add_boost_test` to instruct CMake to place
all executables in build/tests. This should help developers easily
locate tests to run them individually for debugging purposes.

## Before
```
cd build-debug
ctest .
test_feature1...OK
test_feature2...OK
test_feature3...FAILED
find -name test_feature3
# Developer copies the path
# Developer pastes the path
[gdb|valgrind] extremely/long/path/to/test_feature3
```

## After
```
cd build-debug
ctest .
test_feature1...OK
test_feature2...OK
test_feature3...FAILED
# Developer pushes tab a few times
[gdb|valgrind] tests/test_feature3
```

## Collisions
Two tests should never have the same name, or else the executable might
be overwritten. Since the executable name is the same as the target
name, there should be no collision. If there was any collision CMake
would tell us something along the lines of "target XX already defined in
YYY".
  • Loading branch information
flomnes authored Feb 24, 2025
1 parent ebe1594 commit ecc1714
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/tests/macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ function(add_boost_test)
# All tests use boost
target_link_libraries(${TEST_NAME} PRIVATE ${arg_LIBS} Boost::unit_test_framework)

# All executables in <build>/tests
set_target_properties(${TEST_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests)


# Optional: add private include directories
if (NOT "${arg_INCLUDE}" STREQUAL "")
target_include_directories(${TEST_NAME} PRIVATE ${arg_INCLUDE})
Expand Down

0 comments on commit ecc1714

Please sign in to comment.