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:
@@ -1,3 +1,4 @@
|
||||
#include "test/cdb_helper.h"
|
||||
#include "test/temp_dir.h"
|
||||
#include "test/test.h"
|
||||
#include "command/command.h"
|
||||
@@ -194,53 +195,6 @@ void write_cdb(TempDir& tmp, CompilationDatabase& cdb, llvm::StringRef json_cont
|
||||
cdb.load(tmp.path("compile_commands.json"));
|
||||
}
|
||||
|
||||
/// Helper: build a compile_commands.json array from entries.
|
||||
/// Uses "arguments" array form to avoid platform-specific tokenization issues
|
||||
/// (e.g. TokenizeGNUCommandLine treating backslashes as escape characters).
|
||||
struct CDBEntry {
|
||||
llvm::StringRef dir;
|
||||
std::string file;
|
||||
std::vector<std::string> extra_args;
|
||||
};
|
||||
|
||||
/// Escape backslashes and quotes for JSON string values.
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
TEST_SUITE(ScanDependencyGraph) {
|
||||
|
||||
TEST_CASE(EmptyCDB) {
|
||||
|
||||
Reference in New Issue
Block a user