## 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>
97 lines
2.2 KiB
C++
97 lines
2.2 KiB
C++
#include <vector>
|
|
|
|
#include "test/test.h"
|
|
#include "test/tester.h"
|
|
#include "feature/feature.h"
|
|
#include "support/filesystem.h"
|
|
|
|
namespace clice::testing {
|
|
|
|
namespace {
|
|
|
|
namespace protocol = eventide::ipc::protocol;
|
|
|
|
TEST_SUITE(DocumentLink, Tester) {
|
|
|
|
std::vector<protocol::DocumentLink> links;
|
|
|
|
void run(llvm::StringRef source) {
|
|
add_files("main.cpp", source);
|
|
ASSERT_TRUE(compile());
|
|
links = feature::document_links(*unit, feature::PositionEncoding::UTF8);
|
|
}
|
|
|
|
auto to_local_range(const protocol::Range& range) -> LocalSourceRange {
|
|
feature::PositionMapper converter(unit->interested_content(), feature::PositionEncoding::UTF8);
|
|
return LocalSourceRange(*converter.to_offset(range.start), *converter.to_offset(range.end));
|
|
}
|
|
|
|
void EXPECT_LINK(std::size_t index, llvm::StringRef name, llvm::StringRef path) {
|
|
auto& link = links[index];
|
|
auto expected = range(name, "main.cpp");
|
|
auto actual = to_local_range(link.range);
|
|
|
|
ASSERT_EQ(actual.begin, expected.begin);
|
|
ASSERT_EQ(actual.end, expected.end);
|
|
ASSERT_TRUE(link.target.has_value());
|
|
|
|
llvm::SmallString<128> target(link.target->begin(), link.target->end());
|
|
path::remove_dots(target);
|
|
ASSERT_EQ(target, path);
|
|
}
|
|
|
|
TEST_CASE(Include) {
|
|
run(R"cpp(
|
|
#[test.h]
|
|
|
|
#[pragma_once.h]
|
|
#pragma once
|
|
|
|
#[guard_macro.h]
|
|
#ifndef TEST3_H
|
|
#define TEST3_H
|
|
#endif
|
|
|
|
#[main.cpp]
|
|
#include @0["test.h"$]
|
|
#include @1["test.h"$]
|
|
#include @2["pragma_once.h"$]
|
|
#include @3["pragma_once.h"$]
|
|
#include @4["guard_macro.h"$]
|
|
#include @5["guard_macro.h"$]
|
|
)cpp");
|
|
|
|
ASSERT_EQ(links.size(), 6U);
|
|
EXPECT_LINK(0, "0", TestVFS::path("test.h"));
|
|
EXPECT_LINK(1, "1", TestVFS::path("test.h"));
|
|
EXPECT_LINK(2, "2", TestVFS::path("pragma_once.h"));
|
|
EXPECT_LINK(3, "3", TestVFS::path("pragma_once.h"));
|
|
EXPECT_LINK(4, "4", TestVFS::path("guard_macro.h"));
|
|
EXPECT_LINK(5, "5", TestVFS::path("guard_macro.h"));
|
|
}
|
|
|
|
TEST_CASE(HasInclude) {
|
|
run(R"cpp(
|
|
#[test.h]
|
|
|
|
#[main.cpp]
|
|
#include @0["test.h"]
|
|
|
|
#if __has_include(@1["test.h"])
|
|
#endif
|
|
|
|
#if __has_include("test2.h")
|
|
#endif
|
|
)cpp");
|
|
|
|
ASSERT_EQ(links.size(), 2U);
|
|
EXPECT_LINK(0, "0", TestVFS::path("test.h"));
|
|
EXPECT_LINK(1, "1", TestVFS::path("test.h"));
|
|
}
|
|
|
|
}; // TEST_SUITE(DocumentLink)
|
|
|
|
} // namespace
|
|
|
|
} // namespace clice::testing
|