Repository navigation
fix(c,cpp): a file named like a Google unittest, foo_unittest.cc, is a test - #2434
Merged
Merged
Conversation
…a test Google names C++ tests `foo_unittest.cc` (protobuf, Breakpad, glog, Chromium), not `foo_test.cc`. The test-file check wanted a separator right before `test`, so each one read as production code: search and explore ranked it alongside the code it tests, `codegraph affected` never listed it, and the resolver's test rules ran backwards for it. A unittest could not reach the test-suite helpers it calls (`TestUtil::SetAllFields` in test_util.h), and the receiver guess and the test-suite rule let production calls land on a unittest's own declarations (`handler_stack_->size()` on a unittest's `StackHelper`, a template's `AddressType()` on a unittest's typedef). `unittest` and `unittests` join the separator-delimited test suffixes (`foo_unittest.cc`, `foo-unittest.cpp`, `foo.unittest.js`), and a file named so is a test suite to the resolver, as `foo_test.cc` is. A bare `unittest.go` stays production code: promtool's runs rule tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…5d0ffa # Conflicts: # CHANGELOG.md
#2421 links a C/C++ unittest to the test helpers it includes, and #2413 keeps a `std::vector` receiver off project methods, so two of the regression test's cases passed on main without this change. Pin what only this change does: a Python `*_unittest.py` reaching a `tests/` fake, and production `stack_frame_entries_.size()` (`vector` through `using std::vector`) and `AddressType()` staying out of a unittest. The test covers more than C++ now, so it is renamed. The CHANGELOG entry no longer claims what #2421's entry already says, and the indexing setups get the 60 s limit the sibling C++ tests use. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 7, 2026
Merged
Merged
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.
Summary
Google names its C++ tests
foo_unittest.cc, notfoo_test.cc. That covers protocolbuffers/protobuf (62 files), google/breakpad (77), google/glog (12) and Chromium; Chromium's Python tests arefoo_unittest.py.isTestPath's separator-delimited pattern/[._-](test|tests|spec|specs)\.[a-z0-9]+$/needs a separator right beforetest, and inunittestthat position holds at. So every one of these files read as production code:codegraph_exploreranked it alongside the code it tests;codegraph affectednever listed it (glog: a change tosrc/demangle.ccreported no tests at all);stack_frame_entries_.size()onto a unittest'sStackHelper::size, a template'sAddressType()onto a unittest'stypedef);Change
isTestPath(src/search/query-utils.ts):unittestandunittestsjoin the separator-delimited suffixes, sofoo_unittest.cc,foo-unittest.cpp,foo.unittest.jsandrun_all_unittests.ccall count. A bareunittest.gostill does not. prometheus'scmd/promtool/unittest.gois the production code behindpromtool test rules, called frommain.go, so nounittest.prefix rule was added, and nounittest/directory rule either: CPython'sLib/unittest/is the framework itself.isTestSuitePath(src/resolution/name-matcher.ts): yes, these files count as test suites, likefoo_test.cc. I decided this from a middle arm (isTestPathonly) indexed next to the full fix on the pre-fix(c,cpp): a file named like a test is visible to the code that includes it #2421 main. The suite rule alone removed 130 edges (protobuf 84, Breakpad 46), and every one was a wrong production → unittest edge. It removed nothing right.Validation
Arms: main
ed199e60vsed199e60+ this change. Both use the same freshly built kernel and an identical compiled engine apart fromquery-utils.jsandname-matcher.js; the shippeddist/was checked byte-for-byte against the fix arm. Each repo was fully indexed per arm, and sites were keyed by (kind, source node, line, col, refName).Controls, byte-identical dumps: leveldb and rocksdb (C++ with
_test.cc), prometheus (Go, including the productionunittest.go), django (Python), excalidraw (TS), okhttp (Kotlin), tokio (Rust). glog's graph is byte-identical too: its unittests reach nothing new, and only the query-time behaviour below changes.Every removed and retargeted site was read against the source.
protobuf
GetField<T>(message, field)in generated_message_reflection.cc →descriptor_unittest::HasHasbitTest::GetField;f(…)(map.h, json lexer/writer, descriptor.h, field_mask_util.cc) → a test-localTEST_F::X::f;ParseFrom<kParse>(…)in message_lite.cc → a freeParseFromin lite_unittest.cc;absl::Cord(…)→ a misparsed node in lite_unittest.cc;ReadFile×2 →CommandLineInterfaceTest::ReadFile;BackUp×2 insideZeroCopy*Stream→ a test-local struct;F→ a unittest function;IsLazyField→ a unittest helper._test.ccdoes today:error_collector.last_error()in descriptor_unittest.cc →compiler::java::SimpleErrorCollector(name_resolver_test.cc). The right class is in descriptor_test_utils.h, which the file includes, butresolveMethodOnTypetakes the first indexed of five same-named classes.TestSourceDir()in the csharp/ruby generator unittests →TestUtil::TestSourceDir(test_util2.h, not included) instead of googletest.h'sgoogle::protobuf::TestSourceDir._test.ccfiles already have 48 edges into test files outside their translation unit, and rocksdb's have 23,003 (e.g.Flush()indb_compaction_test.cc, aDBTestBase, lands oncolumn_family_test.cc's fixture 1,174 times; I checked that one, and it is wrong). I filed it as a follow-up rather than widening this PR.input->Nextin importer_unittest.cc andstream_->BackUpin zero_copy_sink.h. The latter no longer points into a unittest.parser_->GetSyntaxIdentifier()andTestGenerator::GetResolvedSourceFeatureExtension. Confidence moves 0.7 → 0.65 because a unittest's call now also counts test methods as candidates.Breakpad
size()(std::vector/std::stringmembers,mapping.data.size(), …) → a unittest'sStackHelper::size;endianness()in cfi_assembler.h / synth_elf.cc → another unittest'sWithConfiguration;Range, 4× templateValueType, 4× templateAddressType,DumpSymbols→ unittest-local types;ReadFile×2;stabs.endianness()andsegment2.Size().strings_found.Size()onByteBuffer symbols_found, strings_found;(macho_reader_unittest.cc:1851, 1888). C++ receiver inference never reads the second declarator's type, so these were lucky guesses: the only productionSizeonce test methods were filtered out. Filed as a follow-up.test_assembler::Section/Labelreceivers, e.g.stack_section.GetContents,frame2_sp.Valueandfat.start. I checked the receivers' declarations:Section stack_section;,Label frame1_sp, frame2_sp, frame1_rbp;,test_assembler::Section fat;.Re-checked on the final base after two merge rounds (#2430, #2442, #2449, then #2433, #2444), on main
3de5bef0vs the squash1fb8691d. #2449 changes C++ extraction. The changed-site sets on protobuf (116) and Breakpad (111) are identical to theed199e60measurements above, compared site by site with the before/after targets, and glog is still byte-identical.Query-time effects, same arms:
codegraph affected src/demangle.cc src/demangle.hon glog: 0 → 12 tests, all*_unittest.cc.codegraph affected wire_format.cc wire_format.hon protobuf: 134 → 190 tests (+56*_unittest.cc).Overlap with #2421 (merged)
#2421 makes a test-named C/C++ file visible to the translation units that include it, and this PR fills the gap noted there:
isTestPathdidn't know*_unittest.cc. On the pre-#2421 main (e0bbb662), this change alone added 587 protobuf edges and 863 Breakpad edges, keyed by source line/col, refName and target:data()guesses onstd::string/absl::string_view) are gone through fix(cpp): a receiver declared as a std or other outside type with a lowercase name calls that type's own member #2413;The two compose without conflict: a
_unittest.his now a suite, and only unittests include one.Tests
__tests__/unittest-named-files.test.ts(new). A Pythondevice_unittest.pyreachesFakeDevice.rebootintests/; productionstack_frame_entries_.size()andAddressType()don't resolve into a unittest. A C++TestUtil::SetAllFieldsguard rides along.__tests__/is-test-file.test.ts: positive forms, pluscmd/promtool/unittest.goandLib/unittest/case.pyas negatives.__tests__/cli-affected-test-conventions.test.ts:codegraph affectedreports a C++_unittest.cc.function-refCaller/impact graph misses methods passed as first-class references (callbacks), e.g. executor.submit(obj.method, …) #1820's own 60 s limit, mcp-staleness-banner, mcp-status-freshness, mcp-writer-lock), none touching test-file naming. After merging main (ed199e60), a serial run of the 31 test files closest to the change passed 379/379. Those were the three above, prod-to-test-suite, kotlin-top-level-visibility, ui-entrypoints-api, dead-code, all 12cpp-*suites and the 15 files main's merge touched. The 4 load-sensitive tests fail the same way on main's source on this machine.Not changed
Two private copies of the pattern keep their own lists:
src/ui-server/api/search.ts(viewer unreleased);src/mcp/tools.ts, which doesn't know_test.goeither.Follow-ups (filed as tasks)
T a, b;: read every declarator's type.unittests/andfoo_unittest/directories (Breakpad'ssrc/client/windows/unittests/, glog'ssrc/dcheck_unittest/, LLVM'sunittests/).🤖 Generated with Claude Code