Files
clice/tests/unit/test/cdb_helper.h
ykiko 0a891d8b4a 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>
2026-03-31 10:29:49 +08:00

59 lines
1.4 KiB
C++

#pragma once
#include <cstddef>
#include <string>
#include <vector>
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
namespace clice::testing {
struct CDBEntry {
llvm::StringRef dir;
std::string file;
std::vector<std::string> extra_args;
};
/// Escape backslashes and quotes for JSON string values.
inline std::string json_escape(llvm::StringRef s) {
std::string result;
result.reserve(s.size());
for(char c: s) {
if(c == '\\' || c == '"') {
result += '\\';
}
result += c;
}
return result;
}
/// Build a compile_commands.json array from entries.
/// Uses "arguments" array form to avoid platform-specific tokenization issues.
inline std::string build_cdb_json(llvm::ArrayRef<CDBEntry> entries) {
std::string json = "[\n";
for(std::size_t i = 0; i < entries.size(); ++i) {
auto& e = entries[i];
if(i > 0) {
json += ",\n";
}
json += R"( {"directory": ")";
json += json_escape(e.dir);
json += R"(", "file": ")";
json += json_escape(e.file);
json += R"(", "arguments": ["clang++", "-std=c++20")";
for(auto& arg: e.extra_args) {
json += R"(, ")";
json += json_escape(arg);
json += R"(")";
}
json += R"(, ")";
json += json_escape(e.file);
json += R"("]})";
}
json += "\n]";
return json;
}
} // namespace clice::testing