Repository navigation
fix(c,cpp): a file in a unittests/ or foo_unittest/ folder is a test - #2484
Merged
Merged
Conversation
isTestPath knew `tests/`, `test/`, `__tests__/`, CamelCase source sets and `foo-test/` modules, but not the folders LLVM, Clang, clangd, lldb, offload and Breakpad keep their unit tests in (`unittests/`), nor glog's `dcheck_unittest/`-style test programs: `/unittests/` holds `tests/` only after a `t`, and the `foo_test/` form wants a separator right before `test`. So a helper there with no test-like name (LLVM's CountCopyAndMove.h, SelectionDAGTestBase.h, Breakpad's dump_analysis.cc) read as production code. isTestPath now also counts a `unittests/` folder and a `foo_unittest/` or `foo-unittests/` one. A bare `unittest/` stays production: CPython's `Lib/unittest/` is the framework, and LLVM vendors googletest under `third-party/unittest/`. isTestSuitePath counts the same folders as suites, as it counts `tests/`: their files build into test binaries and never link into the program, and glog builds each `foo_unittest/` folder as a test program of its own (a `foo-test/` module stays out, as shipped test support). That matters for C/C++ because the suite rule's CamelCase file names skip `.cpp`, so on main none of LLVM's `*Test.cpp` files were suites and production locals named `Ctx`, `KV`, `V` or `OpInfo` linked to what a unit test declares. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
What
isTestPath(src/search/query-utils.ts) recognizedtests/,test/,__tests__/,spec/,e2e/, CamelCase source sets likejvmTest/, andfoo-test//foo_testing/modules. It did not recognize the folders LLVM, Clang, clangd, lldb, offload and Breakpad keep their unit tests in (unittests/), or glog'sfoo_unittest/test programs:/unittests/containstests/only after at;[\w.]+[-_]test(?:s|ing)?form needs a separator right beforetest.So a helper there with no test-like name read as production code. Examples: LLVM's
llvm/unittests/ADT/CountCopyAndMove.handllvm/unittests/CodeGen/SelectionDAGTestBase.h, Breakpad'ssrc/client/windows/unittests/dump_analysis.cc, glog'ssrc/includes_unittest/glog_includes_logging.cc.isTestPathnow also matches aunittests/folder, and afoo_unittest/orfoo-unittests/one ((?:^|\/)(?:unittests|[\w.]+[-_]unittests?)\/).unittest/stays production. CPython'sLib/unittest/is the framework, and LLVM vendors googletest underthird-party/unittest/.cmd/promtool/unittest.gois a file, untouched here; fix(c,cpp): a file named like a Google unittest, foo_unittest.cc, is a test #2434 already keeps it production.isTestSuitePath(src/resolution/name-matcher.ts) counts the same folders as suites, as it countstests/.Built on #2434 (the
foo_unittest.ccfile-name rule, merged as 1fb8691) and rebased onto main 1ce1167.The suite decision
unittests/counts as a suite:foo_unittest/folder as a test program of its own (ctest --build-and-test);foo-test/module stays out of the suite rule, as shipped test support.There's a C/C++-specific reason this matters. The suite rule's CamelCase file names (
FooTest.java,BarTests.swift, …) skip.cpp. On main, none of LLVM's*Test.cppfiles were suites, so production locals namedCtx,KV,VorOpInfolinked to what a unit test declares for itself. The suite rule moves 728 such files in llvm/, 286 in clang/, 244 in lldb/ and 103 in clangd.A middle arm (the
isTestPathrule alone) isolates each half. The suite rule alone removed 3,625 edges across the five LLVM samples. All were wrong except lldb's 60 SWIG stand-ins (below), so it is in.Validation (main 1ce1167, three arms: base /
isTestPathonly / both)Each edge is keyed by its site (kind, source, line, col, refName); every removed, retargeted and added edge was bucketed by how the arms classify its source and target files, then checked by reading the code.
LLVM samples are subtrees of llvm-project 22d7058, copied into plain repos:
llvm/{include,lib,unittests,tools,utils/TableGen}+third-party/unittest, 9,373 files;clang/{include,lib,unittests,tools}as the root, so the path starts withunittests/;lldb/{include,source,unittests,tools};The two earlier mains (ed199e6 + #2434, then b635dd4) gave the same categories in each step; LLVM's suite step removed 2,682 and 2,762 edges there.
Removed (3,647)
Ctx.TTIin VPlanRecipes.cpp linked toLLVMContext Ctx;in RandomIRBuilderTest.cpp (578Ctxsites),KV.secondto BLAKE3Test.cpp'susing KV = std::pair<…>(452),OpInfo.ConstraintVTto X86MCDisassemblerTest.cpp'sstruct OpInfo(332),V.secondto a YAMLIOTest.cppstruct V(397). Also clangd'sSto TraceTests.cpp (248) and itsDto a test-modelTestEnum::D(147), offload'sDevice->Deviceto a conformance-teststruct Device, and lldb'sgetBufferandstatusto FileSystemTest.cpp'sDummyFile.lib/,include/,tools/,source/, …).StringTypetemplate parameter linked to SmallStringTest.cpp's alias.isTestPathhalf also stops production method guesses from landing on a unittests helper:Pair.getKey()→ FoldingSet.cpp'sKeyedPair::getKey, and clangd'sOutputBuffer.clear()→ ConfigTesting.h'sCapturedDiags::clear.SWIGBridge::LLDBSwigPythonBreakpointCallbackFunction,python::LLDBSWIGPython_CastPyObjectToSBValueandluaopen_lldbhad linked to the stubs inunittests/ScriptInterpreter/{Python/PythonTestSuite.cpp,Lua/LuaTests.cpp}. Those are the only bodies in the repository: the real ones are generated by SWIG at build time, and the unit tests link the stubs in their place. The class body inSWIGLuaBridge.his not a node (C++ in-class declarations without a body aren't extracted), so these calls now link nothing. That's the same as for a stub in atests/folder today, and better than pointing an agent at areturn false;stub as the code production runs.Added (164)
TLI.getTypeToTransformTo(…)in LegalizeFloatTypes.cpp and friends →TargetLoweringBase::getTypeToTransformTo; SelectionDAGTestBase.h had a method of that name. The other 7 areKeyInfo::getLatticeKeyFromValuein SparsePropagation.h → the only productionLatticeKeyInfospecialization, in CalledValuePropagation.cpp.::testing::Values→ googletest, and 3TmpFile.path()→llvm::unittest::TempFile::path.TestType::create→GpuMathTest::create, and itsExpectedTest->runmoves fromRPCServerTy::ServerThread::runtoGpuMathTest::run.TestTypedefaults toGpuMathTest<Func>.ol_init_args_t Argslocal → a C test program'sstruct Args(21), LLVM'sfs::statusandfs::openFileForRead→ VirtualFileSystemTest.cpp'sInterceptorFS(17), clang'sVisitor→ another test's class.WorkList.top()→interp::InterpStack::top. The same mechanism produced LLVM's 92 rightgetTypeToTransformTolinks.Controls
Lib/unittest/keeps all 37,820 edges into it from outside, including the 13 fromLib/doctest.py.Query time
glog's and Breakpad's graphs are identical, but their unit-test folders now count as tests:
codegraph affected src/glog/logging.hgoes from 12 to 17 tests: thedcheck_unittest/,includes_unittest/,log_severity_unittest/andpackage_config_unittest/programs.affectedon minidump_format.h now listsunittests/dump_analysis.h.Tests
__tests__/is-test-file.test.ts:unittests/andfoo_unittest/paths are tests. A bareunittest/is not (Lib/unittest/*,third-party/unittest/googletest/…,unittest2/).__tests__/unittests-directories.test.ts(new):Ctx/Severitylocals no longer link to aunittests/orfoo_unittest/declaration (the suite rule);TLI.getTypeToTransformToresolves despite SelectionDAGTestBase.h's namesake (theisTestPathrule).__tests__/cli-affected-test-conventions.test.ts:codegraph affectedlistsunittests/ADT/FoldingSet.cpp.isTestPathrule alone, the suite test still fails and the fixture-method test passes, so each rule has its own pin.Full suite on Windows (main 1ce1167 + this change): 6,897 passed, 0 failed, 82 skipped.
🤖 Generated with Claude Code