## 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>
194 lines
3.2 KiB
C++
194 lines
3.2 KiB
C++
#include <optional>
|
|
|
|
#include "test/test.h"
|
|
#include "test/tester.h"
|
|
#include "feature/feature.h"
|
|
|
|
namespace clice::testing {
|
|
|
|
namespace {
|
|
|
|
namespace protocol = eventide::ipc::protocol;
|
|
|
|
TEST_SUITE(Hover, Tester) {
|
|
|
|
std::optional<protocol::Hover> result;
|
|
|
|
void run(llvm::StringRef code) {
|
|
add_main("main.cpp", code);
|
|
ASSERT_TRUE(compile());
|
|
|
|
auto points = nameless_points();
|
|
ASSERT_EQ(points.size(), 1U);
|
|
auto offset = points[0];
|
|
result = feature::hover(*unit, offset, {}, feature::PositionEncoding::UTF8);
|
|
}
|
|
|
|
void compile_only(llvm::StringRef code) {
|
|
add_main("main.cpp", code);
|
|
ASSERT_TRUE(compile());
|
|
}
|
|
|
|
TEST_CASE(Namespace) {
|
|
run(R"cpp(
|
|
namespace $A {
|
|
}
|
|
)cpp");
|
|
|
|
ASSERT_TRUE(result.has_value());
|
|
auto* content = std::get_if<protocol::MarkupContent>(&result->contents);
|
|
ASSERT_TRUE(content != nullptr);
|
|
ASSERT_TRUE(content->value.find("namespace") != std::string::npos);
|
|
}
|
|
|
|
TEST_CASE(FunctionReference) {
|
|
run(R"cpp(
|
|
int foo() { return 0; }
|
|
int x = $foo();
|
|
)cpp");
|
|
|
|
ASSERT_TRUE(result.has_value());
|
|
auto* content = std::get_if<protocol::MarkupContent>(&result->contents);
|
|
ASSERT_TRUE(content != nullptr);
|
|
ASSERT_TRUE(content->value.find("foo") != std::string::npos);
|
|
}
|
|
|
|
TEST_CASE(RecordScope) {
|
|
compile_only(R"cpp(
|
|
typedef struct A {
|
|
struct B {
|
|
struct C {};
|
|
};
|
|
|
|
struct {
|
|
struct D {};
|
|
} _;
|
|
} T;
|
|
|
|
struct FORWARD_STRUCT;
|
|
struct FORWARD_CLASS;
|
|
|
|
void f() {
|
|
struct X {};
|
|
class Y {};
|
|
|
|
struct {
|
|
struct Z {};
|
|
} _;
|
|
}
|
|
|
|
namespace n1 {
|
|
namespace n2 {
|
|
struct NA {
|
|
struct NB {};
|
|
};
|
|
}
|
|
|
|
namespace {
|
|
struct NC {};
|
|
}
|
|
}
|
|
|
|
namespace out {
|
|
namespace in {
|
|
struct M {
|
|
int x;
|
|
double y;
|
|
char z;
|
|
T a, b;
|
|
};
|
|
}
|
|
}
|
|
)cpp");
|
|
}
|
|
|
|
TEST_CASE(EnumStyle) {
|
|
compile_only(R"cpp(
|
|
enum Free {
|
|
A = 1,
|
|
B = 2,
|
|
C = 999,
|
|
};
|
|
|
|
enum class Scope: long {
|
|
A = -8,
|
|
B = 2,
|
|
C = 100,
|
|
};
|
|
)cpp");
|
|
}
|
|
|
|
TEST_CASE(FunctionStyle) {
|
|
compile_only(R"cpp(
|
|
typedef long long ll;
|
|
|
|
ll f(int x, int y, ll z = 1) { return 0; }
|
|
|
|
template<typename T, typename S>
|
|
T t(T a, T b, int c, ll d, S s) { return a; }
|
|
|
|
namespace {
|
|
constexpr static const char* g() { return "hello"; }
|
|
}
|
|
|
|
namespace test {
|
|
namespace {
|
|
[[deprecated("test deprecate message")]] consteval int h() { return 1; }
|
|
}
|
|
}
|
|
|
|
struct A {
|
|
constexpr static A m(int left, double right) { return A(); }
|
|
};
|
|
)cpp");
|
|
}
|
|
|
|
TEST_CASE(VariableStyle) {
|
|
compile_only(R"cpp(
|
|
void f() {
|
|
constexpr static auto x1 = 1;
|
|
}
|
|
)cpp");
|
|
}
|
|
|
|
TEST_CASE(AutoAndDecltype) {
|
|
compile_only(R"cpp(
|
|
$(a1)aut$(a2)o$(a3) i = -1;
|
|
|
|
$(d1)dec$(d2)ltype$(d3)(i) j = 2;
|
|
|
|
struct A { int x; };
|
|
|
|
aut$(a4)o va$(a5)r = A{};
|
|
|
|
a$(fa)uto f1() { return 1; }
|
|
|
|
de$(fn_decltype)cltype(au$(fn_decltype_auto)to) f2() {}
|
|
|
|
int f3(au$(fn_para_auto)to x) {}
|
|
)cpp");
|
|
}
|
|
|
|
TEST_CASE(Expr) {
|
|
compile_only(R"cpp(
|
|
int xxxx = 1;
|
|
int yyyy = xx$(e1)xx;
|
|
|
|
struct A {
|
|
int function(int param) {
|
|
return thi$(e2)s$(e3)->$(e4)funct$(e5)ion(para$(e6)m);
|
|
}
|
|
|
|
int fn(int param) {
|
|
return static$(e7)_cast<A*>(nul$(e8)lptr)->function(par$(e9)am);
|
|
}
|
|
};
|
|
)cpp");
|
|
}
|
|
|
|
}; // TEST_SUITE(Hover)
|
|
|
|
} // namespace
|
|
|
|
} // namespace clice::testing
|