refactor(tests): use Tester fixture, normalize helpers, add index tests (#377)

## Summary

- **Use `Tester` as fixture base** for all test suites that need
compilation, replacing `TesterFixture` and removing redundant
`tester.clear()` calls (eventide zest now creates fresh instances per
TEST_CASE)
- **Remove local `Tester` variables** in `compilation_tests`,
`template_resolver_tests`, `selection_tests` — use inherited fixture
members directly
- **Normalize helper naming**: `expect_xxx` → `EXPECT_XXX`,
`go_to_definition` → `GO_TO_DEFINITION` for consistency
- **Extract shared `test/cdb_helper.h`**: deduplicate `CDBEntry`,
`json_escape`, `build_cdb_json` from `dependency_graph_tests` and
`compile_graph_integration_tests`
- **Add new test files/cases**: `project_index_tests.cpp`, expanded
`tu_index_tests`, `merged_index_tests`, `compilation_tests`

## Test plan

- [x] All existing unit tests pass
- [x] New index tests (TUIndex, MergedIndex, ProjectIndex) pass
- [x] Compilation tests (PCH, PCM, stop) pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Tests**
* Standardized test fixtures and helper naming, moved suites to a shared
fixture, and unified in-memory VFS and compile flows.
* Added broad new coverage: indexing, project indexing, compilation/PCH,
diagnostics, semantic features, and many targeted unit cases.
* Introduced a small compile-database helper and improved driver-style
test compilation paths.

* **Chores**
* Consolidated and reorganized test utilities and tester APIs for easier
maintenance and reuse.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
ykiko
2026-03-31 10:29:49 +08:00
committed by GitHub
parent 6d3b6acc82
commit 0a891d8b4a
27 changed files with 1895 additions and 968 deletions

View File

@@ -23,7 +23,7 @@ CommandOptions quiet_options() {
TEST_SUITE(Command) {
void expect_strip(llvm::StringRef argv, llvm::StringRef result) {
void EXPECT_STRIP(llvm::StringRef argv, llvm::StringRef result) {
CompilationDatabase database;
llvm::StringRef file = "main.cpp";
database.add_command("fake/", file, argv);
@@ -32,21 +32,21 @@ void expect_strip(llvm::StringRef argv, llvm::StringRef result) {
TEST_CASE(DefaultFilters) {
/// Filter -c, -o and input file.
expect_strip("g++ main.cpp", "g++ main.cpp");
expect_strip("clang++ -c main.cpp", "clang++ main.cpp");
expect_strip("clang++ -o main.o main.cpp", "clang++ main.cpp");
expect_strip("clang++ -c -o main.o main.cpp", "clang++ main.cpp");
expect_strip("cl.exe /c /Fomain.cpp.o main.cpp", "cl.exe main.cpp");
EXPECT_STRIP("g++ main.cpp", "g++ main.cpp");
EXPECT_STRIP("clang++ -c main.cpp", "clang++ main.cpp");
EXPECT_STRIP("clang++ -o main.o main.cpp", "clang++ main.cpp");
EXPECT_STRIP("clang++ -c -o main.o main.cpp", "clang++ main.cpp");
EXPECT_STRIP("cl.exe /c /Fomain.cpp.o main.cpp", "cl.exe main.cpp");
/// Filter PCH related.
/// CMake
expect_strip("g++ -std=gnu++20 -Winvalid-pch -include cmake_pch.hxx -o main.cpp.o -c main.cpp",
EXPECT_STRIP("g++ -std=gnu++20 -Winvalid-pch -include cmake_pch.hxx -o main.cpp.o -c main.cpp",
"g++ -std=gnu++20 -Winvalid-pch -include cmake_pch.hxx main.cpp");
expect_strip(
EXPECT_STRIP(
"clang++ -Winvalid-pch -Xclang -include-pch -Xclang cmake_pch.hxx.pch -Xclang -include -Xclang cmake_pch.hxx -o main.cpp.o -c main.cpp",
"clang++ -Winvalid-pch -Xclang -include -Xclang cmake_pch.hxx main.cpp");
expect_strip("cl.exe /Yufoo.h /FIfoo.h /Fpfoo.h_v143.pch /c /Fomain.cpp.o main.cpp",
EXPECT_STRIP("cl.exe /Yufoo.h /FIfoo.h /Fpfoo.h_v143.pch /c /Fomain.cpp.o main.cpp",
"cl.exe -include foo.h main.cpp");
/// TODO: Test more commands from other build system.
@@ -232,9 +232,9 @@ TEST_CASE(DependencyScanFilter) {
TEST_CASE(ModuleFilter) {
/// Module-related options should be stripped.
expect_strip("clang++ -std=c++20 -fmodule-file=mod.pcm main.cpp",
EXPECT_STRIP("clang++ -std=c++20 -fmodule-file=mod.pcm main.cpp",
"clang++ -std=c++20 main.cpp");
expect_strip("clang++ -std=c++20 -fprebuilt-module-path=/tmp main.cpp",
EXPECT_STRIP("clang++ -std=c++20 -fprebuilt-module-path=/tmp main.cpp",
"clang++ -std=c++20 main.cpp");
};
@@ -305,9 +305,9 @@ TEST_CASE(IncludePathAbsolutize) {
TEST_CASE(SemanticOptionsPreserved) {
/// Flags that affect semantics must survive.
expect_strip("clang++ -std=c++20 -fno-exceptions -fno-rtti -pedantic main.cpp",
EXPECT_STRIP("clang++ -std=c++20 -fno-exceptions -fno-rtti -pedantic main.cpp",
"clang++ -std=c++20 -fno-exceptions -fno-rtti -pedantic main.cpp");
expect_strip("clang++ -std=c++20 -Wall -Werror main.cpp",
EXPECT_STRIP("clang++ -std=c++20 -Wall -Werror main.cpp",
"clang++ -std=c++20 -Wall -Werror main.cpp");
};