diff --git a/.github/workflows/clang-tidy.yaml b/.github/workflows/clang-tidy.yaml index 4123329d86..e7b4495a44 100644 --- a/.github/workflows/clang-tidy.yaml +++ b/.github/workflows/clang-tidy.yaml @@ -17,9 +17,9 @@ jobs: matrix: include: - cmake_options: all-options-abiv1-preview - warning_limit: 309 + warning_limit: 278 - cmake_options: all-options-abiv2-preview - warning_limit: 319 + warning_limit: 288 env: CC: /usr/bin/clang-22 CXX: /usr/bin/clang++-22 diff --git a/CHANGELOG.md b/CHANGELOG.md index 895cb6d37e..1b860c68d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ Increment the: ## [Unreleased] +* [CODE HEALTH] Move api/test and sdk/test classes into anonymous namespace + [#4217](https://github.com/open-telemetry/opentelemetry-cpp/pull/4217) + * [CMAKE] Fix and test WITH_API_ONLY option [#4201](https://github.com/open-telemetry/opentelemetry-cpp/pull/4201) diff --git a/api/test/nostd/shared_ptr_test.cc b/api/test/nostd/shared_ptr_test.cc index de57293e09..782eb193f4 100644 --- a/api/test/nostd/shared_ptr_test.cc +++ b/api/test/nostd/shared_ptr_test.cc @@ -13,6 +13,9 @@ using opentelemetry::nostd::shared_ptr; +namespace +{ + class A { public: @@ -237,3 +240,5 @@ TEST(SharedPtrTest, Sort) { SharedPtrTest_Sort(); } + +} // namespace diff --git a/api/test/nostd/unique_ptr_test.cc b/api/test/nostd/unique_ptr_test.cc index 8307135355..83562092cc 100644 --- a/api/test/nostd/unique_ptr_test.cc +++ b/api/test/nostd/unique_ptr_test.cc @@ -10,6 +10,9 @@ using opentelemetry::nostd::unique_ptr; +namespace +{ + class A { public: @@ -174,3 +177,5 @@ TEST(UniquePtrTest, Comparison) EXPECT_EQ(ptr3, nullptr); EXPECT_EQ(nullptr, ptr3); } + +} // namespace diff --git a/api/test/nostd/variant_test.cc b/api/test/nostd/variant_test.cc index 5ebadd6eac..220f5b4bed 100644 --- a/api/test/nostd/variant_test.cc +++ b/api/test/nostd/variant_test.cc @@ -8,6 +8,9 @@ namespace nostd = opentelemetry::nostd; +namespace +{ + class DestroyCounter { public: @@ -120,3 +123,5 @@ TEST(VariantTest, Construction) nostd::variant v{"abc"}; EXPECT_EQ(v.index(), 1); } + +} // namespace diff --git a/api/test/singleton/singleton_test.cc b/api/test/singleton/singleton_test.cc index 66722fe96f..944f0d6b83 100644 --- a/api/test/singleton/singleton_test.cc +++ b/api/test/singleton/singleton_test.cc @@ -163,6 +163,9 @@ static void reset_counts() unknown_span_count = 0; } +namespace +{ + class MyTracer : public trace::Tracer { public: @@ -458,3 +461,5 @@ TEST(SingletonTest, Uniqueness) EXPECT_EQ(span_h_f2_count, 0); EXPECT_EQ(unknown_span_count, 0); } + +} // namespace diff --git a/sdk/test/common/global_log_handle_test.cc b/sdk/test/common/global_log_handle_test.cc index 59d2c85fe4..6cbedd1392 100644 --- a/sdk/test/common/global_log_handle_test.cc +++ b/sdk/test/common/global_log_handle_test.cc @@ -10,6 +10,9 @@ #include "opentelemetry/sdk/common/attribute_utils.h" #include "opentelemetry/sdk/common/global_log_handler.h" +namespace +{ + class CustomLogHandler : public opentelemetry::sdk::common::internal_log::LogHandler { public: @@ -76,3 +79,5 @@ TEST(GlobalLogHandleTest, CustomLogHandler) opentelemetry::sdk::common::internal_log::GlobalLogHandler::SetLogHandler(backup_log_handle); opentelemetry::sdk::common::internal_log::GlobalLogHandler::SetLogLevel(backup_log_level); } + +} // namespace diff --git a/sdk/test/logs/batch_log_record_processor_test.cc b/sdk/test/logs/batch_log_record_processor_test.cc index 7bbbab93a1..ad868bae6f 100644 --- a/sdk/test/logs/batch_log_record_processor_test.cc +++ b/sdk/test/logs/batch_log_record_processor_test.cc @@ -36,6 +36,9 @@ using namespace opentelemetry::sdk::common; namespace nostd = opentelemetry::nostd; +namespace +{ + class MockLogRecordable final : public opentelemetry::sdk::logs::Recordable { public: @@ -474,3 +477,5 @@ TEST_F(BatchLogRecordProcessorTest, TestOptionsReadFromMultipleEnvVars) unsetenv("OTEL_BLRP_EXPORT_TIMEOUT"); unsetenv("OTEL_BLRP_MAX_EXPORT_BATCH_SIZE"); } + +} // namespace diff --git a/sdk/test/logs/log_record_test.cc b/sdk/test/logs/log_record_test.cc index 02c0921fe5..2283fc1dc7 100644 --- a/sdk/test/logs/log_record_test.cc +++ b/sdk/test/logs/log_record_test.cc @@ -85,6 +85,9 @@ TEST(ReadWriteLogRecord, SetAndGet) ASSERT_EQ(record.GetTimestamp().time_since_epoch(), now.time_since_epoch()); } +namespace +{ + // Define a basic Logger class class TestBodyLogger : public opentelemetry::logs::Logger { @@ -343,3 +346,5 @@ TEST(LogBody, BodyConversation) } } } + +} // namespace diff --git a/sdk/test/logs/logger_config_test.cc b/sdk/test/logs/logger_config_test.cc index af9b1fdfa9..f6bdedf944 100644 --- a/sdk/test/logs/logger_config_test.cc +++ b/sdk/test/logs/logger_config_test.cc @@ -89,6 +89,9 @@ const std::array instrumentati &test_scope_1, &test_scope_2, &test_scope_3, &test_scope_4, &test_scope_5, }; +namespace +{ + // Test fixture for VerifyDefaultConfiguratorBehavior class DefaultLoggerConfiguratorTestFixture : public ::testing::TestWithParam @@ -125,3 +128,5 @@ TEST(LoggerConfig, ScopeConfiguratorPreservesCustomConfig) INSTANTIATE_TEST_SUITE_P(InstrumentationScopes, DefaultLoggerConfiguratorTestFixture, ::testing::ValuesIn(instrumentation_scopes)); + +} // namespace diff --git a/sdk/test/metrics/attributes_hashmap_test.cc b/sdk/test/metrics/attributes_hashmap_test.cc index bd243fd3f2..04ccd4fe48 100644 --- a/sdk/test/metrics/attributes_hashmap_test.cc +++ b/sdk/test/metrics/attributes_hashmap_test.cc @@ -82,6 +82,9 @@ TEST(AttributesHashMap, BasicTests) EXPECT_EQ(count, hash_map.Size()); } +namespace +{ + class MetricAttributeMapHashForCollision { public: @@ -223,3 +226,5 @@ TEST(AttributesHashMap, OverflowCardinalityLimitBehavior) EXPECT_NE(map_copy.Get(attr), nullptr); } } + +} // namespace diff --git a/sdk/test/metrics/cardinality_limit_test.cc b/sdk/test/metrics/cardinality_limit_test.cc index 01aaf79b0a..4770ad7d74 100644 --- a/sdk/test/metrics/cardinality_limit_test.cc +++ b/sdk/test/metrics/cardinality_limit_test.cc @@ -101,6 +101,9 @@ TEST(CardinalityLimit, AttributesHashMapBasicTests) } } +namespace +{ + class WritableMetricStorageCardinalityLimitTestFixture : public ::testing::TestWithParam {}; @@ -183,3 +186,5 @@ TEST(CardinalityLimitOverflowAttribute, MatchesSpecLiteral) EXPECT_EQ(entry.first, "otel.metric.overflow"); EXPECT_EQ(nostd::get(entry.second), true); } + +} // namespace diff --git a/sdk/test/metrics/circular_buffer_counter_test.cc b/sdk/test/metrics/circular_buffer_counter_test.cc index d98077c9bc..b79289563d 100644 --- a/sdk/test/metrics/circular_buffer_counter_test.cc +++ b/sdk/test/metrics/circular_buffer_counter_test.cc @@ -10,6 +10,9 @@ using namespace opentelemetry::sdk::metrics; +namespace +{ + class AdaptingIntegerArrayTest : public testing::TestWithParam {}; @@ -149,3 +152,5 @@ TEST(AdaptingCircularBufferCounterTest, Clear) counter.Clear(); EXPECT_TRUE(counter.Empty()); } + +} // namespace diff --git a/sdk/test/metrics/meter_config_test.cc b/sdk/test/metrics/meter_config_test.cc index a13db6e3e2..bdc737063d 100644 --- a/sdk/test/metrics/meter_config_test.cc +++ b/sdk/test/metrics/meter_config_test.cc @@ -71,6 +71,9 @@ const std::array instrumentati &test_scope_1, &test_scope_2, &test_scope_3, &test_scope_4, &test_scope_5, }; +namespace +{ + // Test fixture for VerifyDefaultConfiguratorBehavior class DefaultMeterConfiguratorTestFixture : public ::testing::TestWithParam @@ -91,3 +94,5 @@ TEST_P(DefaultMeterConfiguratorTestFixture, VerifyDefaultConfiguratorBehavior) INSTANTIATE_TEST_SUITE_P(InstrumentationScopes, DefaultMeterConfiguratorTestFixture, ::testing::ValuesIn(instrumentation_scopes)); + +} // namespace diff --git a/sdk/test/metrics/metric_test_stress.cc b/sdk/test/metrics/metric_test_stress.cc index 3673af988e..0a4ac6faac 100644 --- a/sdk/test/metrics/metric_test_stress.cc +++ b/sdk/test/metrics/metric_test_stress.cc @@ -35,6 +35,9 @@ using namespace opentelemetry; using namespace opentelemetry::sdk::instrumentationscope; using namespace opentelemetry::sdk::metrics; +namespace +{ + class MockMetricExporterForStress : public opentelemetry::sdk::metrics::PushMetricExporter { public: @@ -175,3 +178,5 @@ TEST(HistogramStress, UnsignedInt64) ASSERT_EQ(expected_count, collected_count); ASSERT_EQ(*expected_sum, collected_sum); } + +} // namespace diff --git a/sdk/test/metrics/multi_metric_storage_test.cc b/sdk/test/metrics/multi_metric_storage_test.cc index 5c1a284e57..3168f54c1d 100644 --- a/sdk/test/metrics/multi_metric_storage_test.cc +++ b/sdk/test/metrics/multi_metric_storage_test.cc @@ -14,6 +14,9 @@ using namespace opentelemetry; using namespace opentelemetry::sdk::metrics; +namespace +{ + class TestMetricStorage : public SyncWritableMetricStorage { public: @@ -62,3 +65,5 @@ TEST(MultiMetricStorageTest, BasicTests) EXPECT_EQ(static_cast(storage.get())->num_calls_long, 3); EXPECT_EQ(static_cast(storage.get())->num_calls_double, 1); } + +} // namespace diff --git a/sdk/test/metrics/periodic_exporting_metric_reader_test.cc b/sdk/test/metrics/periodic_exporting_metric_reader_test.cc index 5ac001b0a8..134e67c834 100644 --- a/sdk/test/metrics/periodic_exporting_metric_reader_test.cc +++ b/sdk/test/metrics/periodic_exporting_metric_reader_test.cc @@ -29,6 +29,9 @@ using namespace opentelemetry; using namespace opentelemetry::sdk::instrumentationscope; using namespace opentelemetry::sdk::metrics; +namespace +{ + class MockPushMetricExporter : public PushMetricExporter { public: @@ -168,3 +171,5 @@ TEST(PeriodicExportingMetricReaderOptions, UsesDefault) EXPECT_EQ(options.export_interval_millis, std::chrono::milliseconds(60000)); EXPECT_EQ(options.export_timeout_millis, std::chrono::milliseconds(30000)); } + +} // namespace diff --git a/sdk/test/metrics/sum_aggregation_test.cc b/sdk/test/metrics/sum_aggregation_test.cc index 99aa5df6d5..1a4e9c2545 100644 --- a/sdk/test/metrics/sum_aggregation_test.cc +++ b/sdk/test/metrics/sum_aggregation_test.cc @@ -414,6 +414,9 @@ TEST(CounterToSumFilterAttributesWithCardinalityLimit, Double) } } +namespace +{ + class UpDownCounterToSumFixture : public ::testing::TestWithParam {}; @@ -471,3 +474,5 @@ INSTANTIATE_TEST_SUITE_P(UpDownCounterToSum, UpDownCounterToSumFixture, ::testing::Values(true, false)); #endif + +} // namespace diff --git a/sdk/test/metrics/sync_metric_storage_histogram_test.cc b/sdk/test/metrics/sync_metric_storage_histogram_test.cc index 9f608bcd16..ee3af6e8c4 100644 --- a/sdk/test/metrics/sync_metric_storage_histogram_test.cc +++ b/sdk/test/metrics/sync_metric_storage_histogram_test.cc @@ -34,6 +34,9 @@ using namespace opentelemetry::sdk::metrics; using namespace opentelemetry::common; +namespace +{ + class WritableMetricStorageHistogramTestFixture : public ::testing::TestWithParam {}; @@ -538,3 +541,5 @@ INSTANTIATE_TEST_SUITE_P(WritableMetricStorageHistogramTestBase2ExponentialDoubl WritableMetricStorageHistogramTestFixture, ::testing::Values(AggregationTemporality::kCumulative, AggregationTemporality::kDelta)); + +} // namespace diff --git a/sdk/test/resource/resource_test.cc b/sdk/test/resource/resource_test.cc index 696509f892..101a7a5a32 100644 --- a/sdk/test/resource/resource_test.cc +++ b/sdk/test/resource/resource_test.cc @@ -27,6 +27,9 @@ using namespace opentelemetry::sdk::resource; namespace nostd = opentelemetry::nostd; namespace semconv = opentelemetry::semconv; +namespace +{ + class TestResource : public Resource { public: @@ -292,3 +295,5 @@ TEST(ResourceTest, DerivedResourceDetector) EXPECT_EQ(resource.GetSchemaURL(), detector.schema_url); EXPECT_TRUE(received_attributes.find("key") != received_attributes.end()); } + +} // namespace diff --git a/sdk/test/trace/simple_processor_test.cc b/sdk/test/trace/simple_processor_test.cc index 755fd483e8..b88e89eb72 100644 --- a/sdk/test/trace/simple_processor_test.cc +++ b/sdk/test/trace/simple_processor_test.cc @@ -42,6 +42,9 @@ TEST(SimpleProcessor, ToInMemorySpanExporter) EXPECT_TRUE(processor.Shutdown()); } +namespace +{ + // An exporter that does nothing but record (and give back ) the # of times Shutdown was called. class RecordShutdownExporter final : public SpanExporter { @@ -141,3 +144,5 @@ TEST(SimpleSpanProcessor, ForceFlushFail) std::unique_ptr{new FailShutDownForceFlushExporter()}); EXPECT_EQ(false, processor.ForceFlush()); } + +} // namespace diff --git a/sdk/test/trace/tracer_config_test.cc b/sdk/test/trace/tracer_config_test.cc index 4f342ba11c..6f849bc94b 100644 --- a/sdk/test/trace/tracer_config_test.cc +++ b/sdk/test/trace/tracer_config_test.cc @@ -71,6 +71,9 @@ const std::array instrumentati &test_scope_1, &test_scope_2, &test_scope_3, &test_scope_4, &test_scope_5, }; +namespace +{ + // Test fixture for VerifyDefaultConfiguratorBehavior class DefaultTracerConfiguratorTestFixture : public ::testing::TestWithParam @@ -91,3 +94,5 @@ TEST_P(DefaultTracerConfiguratorTestFixture, VerifyDefaultConfiguratorBehavior) INSTANTIATE_TEST_SUITE_P(InstrumentationScopes, DefaultTracerConfiguratorTestFixture, ::testing::ValuesIn(instrumentation_scopes)); + +} // namespace