diff --git a/diagnostic_aggregator/CMakeLists.txt b/diagnostic_aggregator/CMakeLists.txt index 2af6b867..87e74593 100644 --- a/diagnostic_aggregator/CMakeLists.txt +++ b/diagnostic_aggregator/CMakeLists.txt @@ -89,7 +89,8 @@ if(BUILD_TESTING) "primitive_analyzers" "all_analyzers" "analyzer_group" - "empty_root_path") + "empty_root_path" + "expected_only_analyzer") foreach(test_name ${create_analyzers_tests}) file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/test/${test_name}.yaml" PARAMETER_FILE) diff --git a/diagnostic_aggregator/src/generic_analyzer.cpp b/diagnostic_aggregator/src/generic_analyzer.cpp index 3965b226..580b6c4a 100644 --- a/diagnostic_aggregator/src/generic_analyzer.cpp +++ b/diagnostic_aggregator/src/generic_analyzer.cpp @@ -113,7 +113,8 @@ bool GenericAnalyzer::init( RCLCPP_DEBUG( rclcpp::get_logger("GenericAnalyzer"), "GenericAnalyzer '%s' found expected: %s", nice_name_.c_str(), pvalue.value_to_string().c_str()); - for (auto exp : pvalue.as_string_array()) { + expected_ = pvalue.as_string_array(); + for (const auto & exp : expected_) { auto item = std::make_shared(exp); this->addItem(exp, item); } diff --git a/diagnostic_aggregator/test/expected_only_analyzer.yaml b/diagnostic_aggregator/test/expected_only_analyzer.yaml new file mode 100644 index 00000000..c0945652 --- /dev/null +++ b/diagnostic_aggregator/test/expected_only_analyzer.yaml @@ -0,0 +1,11 @@ +/**: + ros__parameters: + log_level: debug + # Regression test for the `expected` matcher: an analyzer whose ONLY matcher + # is `expected` must still initialise. Prior to the fix this failed because + # the `expected` parameter populated the base-class items_ map but never the + # expected_ vector that the init guard checks, so the analyzer was dropped. + expected_only: + type: 'diagnostic_aggregator/GenericAnalyzer' + path: ExpectedOnly + expected: [ 'some/expected/status' ] diff --git a/diagnostic_aggregator/test/expected_output/create_expected_only_analyzer.txt b/diagnostic_aggregator/test/expected_output/create_expected_only_analyzer.txt new file mode 100644 index 00000000..9e56ce19 --- /dev/null +++ b/diagnostic_aggregator/test/expected_output/create_expected_only_analyzer.txt @@ -0,0 +1,2 @@ +diagnostic_aggregator/GenericAnalyzer 'ExpectedOnly' +/ExpectedOnly