Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce cmake test boilerplate #2276

Merged

Conversation

traversaro
Copy link
Contributor

@traversaro traversaro commented Dec 7, 2024

Before this PR, all instances of mujoco_test in the codebase were followed by a call to target_link_libraries(<testname> fixture gmock).

As anyhow mujoco_test already was calling target_link_libraries to some predefined list of targets (mujoco and gtest_main), this PR adds to the list of default linked targets also fixture and gmock, to reduce the boilerplate required to add a test.

Furthermore, to completely remove the need for calling target_link_libraries after a call to mujoco_test, this PR also adds to the mujoco_test macro the ADDITIONAL_LINK_LIBRARIES argument, that can be used if a given test needs to link some additional targets beside the default ones.

To permit to use these new features also for mujoco benchmarks, this PR adds a MAIN_TARGET parameter to mujoco_test, to select if gtest_main or another target is used to provide the main
entry point to the test executable, and migrate the existing usage of mujoco_benchmark_test to use mujoco_test.

This change is a requirement to add a TAGS argument to the mujoco_test macro, to permit to skip the compilation of a given test under some condition.

@traversaro traversaro force-pushed the reducetestboilerplate branch from fb296ef to 8b68d27 Compare December 7, 2024 15:33
All instances of mujoco_test in the code base were followed by
a call to  target_link_libraries(<testname> fixture gmock).

As anyhow mujoco_test already was calling target_link_libraries
to some predefined list of targets (mujoco and gtest_main),
this PR adds to the list of default linked targets also fixture
and gmock, to reduce the boilerplate.

Furthermore, to completly remove the need for calling
target_link_libraries after a call to mujoco_test, this PR also
add to the mujoco_test macro the ADDITIONAL_LINK_LIBRARIES
argument, that can be used if a given test needs to link some
additional targets beside the default ones.

To permit to use these new features also for mujoco benchmarks,
this PR adds a MAIN_TARGET parameter to mujoco_test, to select
if gtest_main or another target is used to provide the main
entry point to the test executable.
@traversaro traversaro force-pushed the reducetestboilerplate branch from 8b68d27 to 756a8d7 Compare December 7, 2024 16:14
@traversaro
Copy link
Contributor Author

traversaro commented Dec 7, 2024

If CI fails on the macos-12 test, it will be due to the reason discussed in #2277 .

@copybara-service copybara-service bot merged commit 526637f into google-deepmind:main Dec 18, 2024
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants