Skip to content

Commit

Permalink
Default ROS_HOME and ROS_LOG_DIR env vars in ros2_cpp_test to TEST_UN…
Browse files Browse the repository at this point in the history
…DECLARED_OUTPUTS_DIR
  • Loading branch information
lalten committed Apr 21, 2023
1 parent 03c895e commit c345187
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ros2/cc_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,7 @@ def ros2_cpp_test(name, ros2_package_name = None, set_up_ament = False, **kwargs
set_up_ament: If true, sets up ament file tree for the test target.
**kwargs: https://bazel.build/reference/be/common-definitions#common-attributes-tests
"""
_ros2_cpp_exec(cc_test, name, ros2_package_name, set_up_ament, **kwargs)
env = kwargs.pop("env", {})
env["ROS_HOME"] = env.get("ROS_HOME", "$TEST_UNDECLARED_OUTPUTS_DIR")
env["ROS_LOG_DIR"] = env.get("ROS_LOG_DIR", "$TEST_UNDECLARED_OUTPUTS_DIR")
_ros2_cpp_exec(cc_test, name, ros2_package_name, set_up_ament, env = env, **kwargs)
8 changes: 8 additions & 0 deletions ros2/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ load(
"py_ros2_interface_library",
"ros2_interface_library",
)
load("@com_github_mvukov_rules_ros2//ros2:cc_defs.bzl", "ros2_cpp_test")
load("@rules_python//python:defs.bzl", "py_test")

py_test(
Expand Down Expand Up @@ -45,3 +46,10 @@ py_test(
":py_test_action",
],
)

ros2_cpp_test(
name = "test_rclcpp",
size = "small",
srcs = ["test_rclcpp.cpp"],
deps = ["@ros2_rclcpp//:rclcpp"],
)
9 changes: 9 additions & 0 deletions ros2/test/test_rclcpp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <rclcpp/rclcpp.hpp>

int main(int argc, char** argv) {
// If neither $ROS_HOME nor $ROS_LOG_DIR are set to a valid directory, rclcpp:init() will fail with errors
// 'rcutils_expand_user failed, at external/ros2_rcl_logging/rcl_logging_interface/src/logging_dir.c:81'
// 'Failed to get logging directory, at external/ros2_rcl_logging/rcl_logging_spdlog/src/rcl_logging_spdlog.cpp:83'
rclcpp::init(argc, argv);
return 0;
}

0 comments on commit c345187

Please sign in to comment.