Skip to content

[CODE HEALTH] Move remaining API test helpers into anonymous namespaces#4301

Draft
thc1006 wants to merge 3 commits into
open-telemetry:mainfrom
thc1006:codehealth/api-test-internal-linkage-4196
Draft

[CODE HEALTH] Move remaining API test helpers into anonymous namespaces#4301
thc1006 wants to merge 3 commits into
open-telemetry:mainfrom
thc1006:codehealth/api-test-internal-linkage-4196

Conversation

@thc1006

@thc1006 thc1006 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Part of #4196

Draft while CI runs. Ready for review from my side.

Six misc-use-internal-linkage sites in the API tests, continuing from #4217 and #4286. This is the first of three batches; the other two cover the SDK tests.

file classes
api/test/logs/logger_test.cc TestLogger, TestProvider
api/test/logs/provider_test.cc TestProvider, TestEventLoggerProvider
api/test/trace/propagation/detail/string_test.cc SplitStringTestFixture
api/test/trace/provider_test.cc TestProvider

Shape of the change

logger_test.cc and string_test.cc already had an anonymous namespace that stopped just short of the flagged classes, so those namespaces are extended rather than joined by a second one. In logger_test.cc that means moving the opening up past TestLogger and the closing down to the end of the file, since TestProvider sat below it.

The two provider_test.cc files 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/logs contains two different classes both named TestProvider, one in logger_test.cc and one in provider_test.cc. They currently build into separate test executables (a distinct Bazel cc_test and 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 TestEventLoggerProvider sits 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

  • All six classes are inside an anonymous namespace after the change, checked by walking the namespace depth rather than by eye, and every file has balanced open and close.
  • All four files compile with -DOPENTELEMETRY_ABI_VERSION_NO=1 and =2.
  • clang-format 18 clean.
  • No TEST, TEST_F, or TEST_P suite name that would map to different fixture types is shared across translation units in any combined test target. string_test.cc uses TEST_P/INSTANTIATE_TEST_SUITE_P, and its fixture and parameter type are both in the anonymous namespace now; neither api/test/logs nor api/test/trace has a combined test target. So this should not repeat the all_tests redefinition 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-linkage only 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 at de8fa515, and CI is the authority on the resulting count.

thc1006 added 3 commits July 25, 2026 02:03
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

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.30%. Comparing base (d3c7a47) to head (9b588cd).

Additional details and impacted files

Impacted file tree graph

@@            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     

see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant