[CODE HEALTH] Move remaining API test helpers into anonymous namespaces#4301
Draft
thc1006 wants to merge 3 commits into
Draft
[CODE HEALTH] Move remaining API test helpers into anonymous namespaces#4301thc1006 wants to merge 3 commits into
thc1006 wants to merge 3 commits into
Conversation
Six misc-use-internal-linkage sites, continuing from open-telemetry#4217 and open-telemetry#4286. logger_test.cc had an anonymous namespace already, with TestLogger just above it and TestProvider just below, so the existing namespace is extended to cover both rather than adding two more. string_test.cc is the same shape: its namespace closed immediately before SplitStringTestFixture, so the closing brace moves to the end of the file. The two provider_test.cc files get a namespace around the test body. In the logs one that puts the deprecated-declaration pragma push and pop pair inside the namespace, which is fine since both ends stay on the same side of the boundary. Worth noting that api/test/logs holds two different classes both named TestProvider, in logger_test.cc and provider_test.cc. They are in the same Bazel package, so giving them internal linkage also removes a latent one definition rule hazard. Part of open-telemetry#4196 Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
abiv1 goes from 151 to 145. abiv2 goes from 161 to 156, five rather than six, because TestEventLoggerProvider sits behind deprecated-API pragmas and is only reported on abiv1. Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4301 +/- ##
==========================================
- Coverage 81.31% 81.30% -0.01%
==========================================
Files 445 445
Lines 18859 18859
==========================================
- Hits 15333 15331 -2
- Misses 3526 3528 +2 🚀 New features to boost your workflow:
|
This was referenced Jul 24, 2026
thc1006
added a commit
to thc1006/opentelemetry-cpp
that referenced
this pull request
Jul 25, 2026
…namespaces Nine misc-use-internal-linkage sites, the last of three batches after open-telemetry#4301 and open-telemetry#4302. tracer_test.cc had an anonymous namespace holding only initTracer(), with the three mock classes above it, so that namespace is extended over them rather than joined by a second one. measurements_benchmark.cc is the same shape, with MockMetricExporter pulled into the existing namespace. The other three get a namespace around the test body. batch_span_processor_test.cc already sits inside a named namespace via OPENTELEMETRY_BEGIN_NAMESPACE; the anonymous namespace nests inside it and covers every class and TEST in the file. Its BatchSpanProcessorTestPeer and the metrics file's AlignedHistogramBucketExemplarReservoirTestPeer are the only TEST_F suite names here, and each is unique to its file, so this does not repeat the all_tests redefinition from open-telemetry#4217. The warning limit drops by nine on both presets, 151 to 142 and 161 to 152. None of these are ABI gated. This branch is cut from main. If open-telemetry#4301 or open-telemetry#4302 merge first, the limit needs recomputing down by their counts as well. Part of open-telemetry#4196 Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #4196
Draft while CI runs. Ready for review from my side.
Six
misc-use-internal-linkagesites in the API tests, continuing from #4217 and #4286. This is the first of three batches; the other two cover the SDK tests.api/test/logs/logger_test.ccTestLogger,TestProviderapi/test/logs/provider_test.ccTestProvider,TestEventLoggerProviderapi/test/trace/propagation/detail/string_test.ccSplitStringTestFixtureapi/test/trace/provider_test.ccTestProviderShape of the change
logger_test.ccandstring_test.ccalready had an anonymous namespace that stopped just short of the flagged classes, so those namespaces are extended rather than joined by a second one. Inlogger_test.ccthat means moving the opening up pastTestLoggerand the closing down to the end of the file, sinceTestProvidersat below it.The two
provider_test.ccfiles get a namespace around the test body. In the logs one that places the deprecated-declaration pragma push and pop pair inside the namespace, which is fine because both ends stay on the same side of the boundary. Both ABI settings compile, which exercises that.Worth flagging:
api/test/logscontains two different classes both namedTestProvider, one inlogger_test.ccand one inprovider_test.cc. They currently build into separate test executables (a distinct Bazelcc_testand a distinct CMake target each), so there is no present link-time conflict; being in the same Bazel package does not put them in the same binary. Giving them internal linkage nevertheless prevents an ODR hazard if these sources are ever combined into one test binary.Warning limit
151 to 145 on abiv1, and 161 to 156 on abiv2. The abiv2 delta is five rather than six because
TestEventLoggerProvidersits behind deprecated-API pragmas and is only reported on abiv1. That single site is also the entire difference between the 25 and 24 totals I posted on #4196. If the artifact disagrees with those numbers I will correct them from it.Verification
-DOPENTELEMETRY_ABI_VERSION_NO=1and=2.TEST,TEST_F, orTEST_Psuite name that would map to different fixture types is shared across translation units in any combined test target.string_test.ccusesTEST_P/INSTANTIATE_TEST_SUITE_P, and its fixture and parameter type are both in the anonymous namespace now; neitherapi/test/logsnorapi/test/tracehas a combined test target. So this should not repeat theall_testsredefinition that [CODE HEALTH] Move api/test and sdk/test classes into anonymous namespace #4217 ran into, which was the main thing I wanted to rule out before sending this.One honest gap: I could not re-run the check itself locally.
misc-use-internal-linkageonly reports classes from llvm-22 onward, which is what CI uses; clang-tidy 18, 20 and 21 report functions and variables only, so a local run returns zero both before and after the change and proves nothing. I checked that rather than assuming it. The site list therefore comes from the CI log artifact for main atde8fa515, and CI is the authority on the resulting count.