–event-handlers console_direct+ … test 1 Start 1: test_success 1: Test command: /usr/bin/bash “-c” “exit 0” 1: Test timeout computed to be: 1500 1/2 Test #1: test_success ..................... Passed 0.00 sec test 2 Start 2: test_failure 2: Test command: /usr/bin/bash "-c" "exit 1" 2: Test timeout computed to be: 1500 2/2 Test #2: test_failure .....................***Failed 0.00 sec 50% tests passed, 1 tests failed out of 2 Total Test time (real) = 0.00 sec The following tests FAILED: 2 - test_failure (Failed) Errors while running CTest … 31 ←成功 ←失敗
example_ament_cmake_gmock … $ colcon test-result --verbose build/example_ament_cmake_gmock/Testing/20221113-1555/Test.xml: 1 test, 0 errors, 1 failure, 0 skipped - my_ament_cmake_gmock <<< failure message -- run_test.py: invoking following command in '/workspaces/test-methodlogy/build/example_ament_cmake_gmock': - /workspaces/test-methodlogy/build/example_ament_cmake_gmock/my_ament_cmake_gmock --gtest_output=xml:/workspaces/test- methodlogy/build/example_ament_cmake_gmock/test_results/example_ament_cmake_gmock/my_ament_cmake_gmock.gtest.xml Running main() from gmock_main.cc [==========] Running 2 tests from 1 test suite. [----------] Global test environment set-up. [----------] 2 tests from bar [ RUN ] bar.success [ OK ] bar.success (0 ms) [ RUN ] bar.failure /workspaces/test-methodlogy/src/one-by-one/05_example_ament_cmake_gmock/test/foo_mock.cpp:23: Failure Actual function call count doesn't match EXPECT_CALL(mock_foo, func(0))... Expected: to be called twice Actual: called once - unsatisfied and active [ FAILED ] bar.failure (0 ms) [----------] 2 tests from bar (0 ms total) 失敗するケースも追加 EXPECT_CALL(mock_foo, func(0)) .Times(2) // 2回呼ばれること .WillRepeatedly(Return(true));
[launch]: All log files can be found below /home/vscode/.ros/log/2022-11-14-15-24-26-445770-62e34440bc2c-2166924 [INFO] [launch]: Default logging verbosity is set to INFO test_failure (test_twice_launch.TestTwice) ... [INFO] [twice-1]: process started with pid [2166932] FAIL test_success (test_twice_launch.TestTwice) ... ok test_success2 (test_twice_launch.TestTwice) ... ok ====================================================================== FAIL: test_failure (test_twice_launch.TestTwice) ---------------------------------------------------------------------- Traceback (most recent call last): File "/workspaces/test-methodlogy/src/one-by- one/10_example_launch_testing_ament_cmake/test/test_twice_launch.py", line 77, in test_failure self.assertEqual(ans, Int32(data=3)) AssertionError: std_msgs.msg.Int32(data=2) != std_msgs.msg.Int32(data=3) ---------------------------------------------------------------------- Ran 3 tests in 0.471s FAILED (failures=1) [INFO] [twice-1]: sending signal 'SIGINT' to process[twice-1] [twice-1] [INFO] [1668439466.941480504] [rclcpp]: signal_handler(signum=2) [INFO] [twice-1]: process has finished cleanly [pid 2166932] ---------------------------------------------------------------------- Ran 0 tests in 0.000s OK コマンドラインツールの launch_test を使用
style divergence in file 'include/example_ament_cmake_lint/add.hpp' Code style divergence in file 'src/add.cpp': --- src/add.cpp +++ src/add.cpp.uncrustify @@ -8 +8 @@ -int add(int a, int b) {return a + b;} +int add(int a, int b) {return a + b;} 1 files with code style divergence $ ament_uncrustify --reformat No code style divergence in file 'include/example_ament_cmake_lint/add.hpp' Code style divergence in file 'src/add.cpp': reformatted file 1 files with code style divergence 解析だけでなくコード修正可能 なものもある
は無効 ⚫ 今回は使用したいので有効化 117 if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) # the following line skips the linter which checks for copyrights # comment the line when a copyright and license is added to all source files set(ament_cmake_copyright_FOUND TRUE) # the following line skips cpplint (only works in a git repo) # comment the line when this package is in a git repo and when # a copyright and license is added to all source files set(ament_cmake_cpplint_FOUND TRUE) ament_lint_auto_find_test_dependencies() endif() 削除 CMakeLists.txt
Copyright (c) 2022 Fixstars inc. // // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. #pragma once #include <cstdint> namespace cpp_calc { int32_t do_twice(int32_t v); } // namespace cpp_calc // Copyright (c) 2022 Fixstars inc. // // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. #include "cpp_calc/twice.hpp" namespace cpp_calc { int32_t do_twice(int32_t v) { return v * 2; } } // namespace cpp_calc include/cpp_calc/twice.hpp src/twice.cpp
// Copyright (c) 2022 Fixstars inc. // // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. #include <cpp_calc/twice.hpp> #include <gtest/gtest.h> TEST(do_twice, two_sohuld_be_four) { ASSERT_EQ(cpp_calc::do_twice(2), 4); } find_package(ament_cmake_auto REQUIRED) ament_auto_find_build_dependencies() ament_auto_add_library(twice_lib SHARED src/twice.cpp ) if(BUILD_TESTING) ament_auto_find_test_dependencies() ament_auto_add_gtest(twice_test test/unittest/twice_test.cpp ) endif() test/unittest/twice_test.cpp CMakeLists.txt
⚫ copyright は無効になっているので有効化する 129 from ament_copyright.main import main import pytest # Remove the `skip` decorator once the source file(s) have a copyright header @pytest.mark.skip(reason='No copyright header has been placed in the generated source file.') @pytest.mark.copyright @pytest.mark.linter def test_copyright(): rc = main(argv=['.', 'test']) assert rc == 0, 'Found errors' 削除 test/test_copyright.py
from launch import LaunchDescription from launch.actions import IncludeLaunchDescription, ExecuteProcess from launch.launch_description_sources import AnyLaunchDescriptionSource from ament_index_python import get_package_share_directory from pathlib import Path import rclpy import rclpy.node from std_msgs.msg import Int32 from threading import Thread
をPythonライブラリとして使う形になりそう ◦ 以下のようなコードを最初に書く 152 import domain_coordinator import contextlib import os stack = contextlib.ExitStack() if "ROS_DOMAIN_ID" not in os.environ and "DISABLE_ROS_ISOLATION" not in os.environ: domain_id = stack.enter_context(domain_coordinator.domain_id()) os.environ["ROS_DOMAIN_ID"] = str(domain_id) test/launch/test_twice_launch.py