Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ SpacesInParensOptions:

SpacesInSquareBrackets: false

WrapNamespaceBodyWithEmptyLines: Always
# Order
QualifierAlignment: Custom
QualifierOrder: ["constexpr", "const", "inline", "static", "type"]
Expand All @@ -101,3 +102,4 @@ SortUsingDeclarations: Never
IncludeBlocks: Merge

ForEachMacros: ["REFLECTABLE_RECORD"]
NamespaceMacros: [TEST_SUITE]
1 change: 1 addition & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ jobs:
shell: bash
run: |
if [[ "${{ runner.os }}" == "macOS" ]]; then
export SDKROOT=$(xcrun --show-sdk-path)
export PATH="/opt/homebrew/opt/llvm@20/bin:/opt/homebrew/opt/lld@20/bin:$PATH"
fi

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,5 @@ if(CLICE_ENABLE_TEST)
"${PROJECT_SOURCE_DIR}/bin/unit_tests.cc"
)
target_include_directories(unit_tests PUBLIC "${PROJECT_SOURCE_DIR}")
target_link_libraries(unit_tests PRIVATE clice-core)
target_link_libraries(unit_tests PRIVATE clice-core cpptrace::cpptrace)
endif()
3 changes: 2 additions & 1 deletion bin/unit_tests.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Test/Test.h"
#include "Test/Test2.h"
#include "Support/Logging.h"
#include "Support/GlobPattern.h"

Expand Down Expand Up @@ -198,5 +199,5 @@ int main(int argc, const char* argv[]) {
}

using namespace clice::testing;
return Runner::instance().run_tests();
return Runner2::instance().run_tests(test_filter);
}
10 changes: 9 additions & 1 deletion cmake/package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ FetchContent_Declare(
GIT_TAG v4.4.2
)
set(ENABLE_ROARING_TESTS OFF CACHE INTERNAL "" FORCE)
set(ENABLE_ROARING_MICROBENCHMARKS OFF CACHE INTERNAL "" FORCE)

# flatbuffers
FetchContent_Declare(
Expand All @@ -128,7 +129,14 @@ set(FLATBUFFERS_BUILD_GRPC OFF CACHE BOOL "" FORCE)
set(FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(FLATBUFFERS_BUILD_FLATHASH OFF CACHE BOOL "" FORCE)

FetchContent_MakeAvailable(libuv spdlog tomlplusplus croaring flatbuffers)
# cpptrace
FetchContent_Declare(
cpptrace
GIT_REPOSITORY https://github.com/jeremy-rifkin/cpptrace.git
GIT_TAG v1.0.4
)

FetchContent_MakeAvailable(libuv spdlog tomlplusplus croaring flatbuffers cpptrace)

if(WIN32)
target_compile_definitions(uv_a PRIVATE _CRT_SECURE_NO_WARNINGS)
Expand Down
1 change: 1 addition & 0 deletions docs/semantic-tokens-example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ struct Widget {

template <typename T>
Widget(T) -> Widget<typename T::value_type>;

} // namespace foo
2 changes: 2 additions & 0 deletions include/Compiler/Compilation.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include "Support/FileSystem.h"

namespace clang {

class CodeCompleteConsumer;

}

namespace clice {
Expand Down
2 changes: 2 additions & 0 deletions include/Compiler/Diagnostic.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#include "clang/Basic/Diagnostic.h"

namespace clang {

class DiagnosticConsumer;

}

namespace clice {
Expand Down
2 changes: 2 additions & 0 deletions include/Compiler/Tidy.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include <memory>

namespace clang {

class CompilerInstance;

}

namespace clice::tidy {
Expand Down
2 changes: 2 additions & 0 deletions include/Index/IncludeGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include "llvm/ADT/DenseMap.h"

namespace clice {

class CompilationUnit;

}

namespace clice::index {
Expand Down
1 change: 1 addition & 0 deletions include/Test/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ constexpr inline bool CIEnvironment = true;
#else
constexpr inline bool CIEnvironment = false;
#endif

} // namespace clice::testing
45 changes: 45 additions & 0 deletions include/Test/Runner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

#include <vector>
#include <string>
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/FunctionExtras.h"

namespace clice::testing {

enum class TestState {
Passed,
Skipped,
Failed,
Fatal,
};

struct TestAttrs {
bool skip = false;
bool focus = false;
};

struct TestCase {
std::string name;
llvm::unique_function<TestState()> test;
TestAttrs attrs;
};

struct TestSuite {
std::string name;
std::vector<TestCase> (*cases)();
};

class Runner2 {
public:
static Runner2& instance();

void add_suite(std::string_view suite, std::vector<TestCase> (*cases)());

int run_tests(llvm::StringRef filter);

private:
std::vector<TestSuite> suites;
};

} // namespace clice::testing
2 changes: 2 additions & 0 deletions include/Test/TExpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ decltype(auto) compute(const Expr& expr) {

#define BINARY_PREDICATE(name, op) \
namespace clice::testing { \
\
decltype(auto) name##_impl(auto&& lhs, auto&& rhs); \
\
template <typename LHS, typename RHS> \
Expand All @@ -55,6 +56,7 @@ decltype(auto) compute(const Expr& expr) {
\
template <typename LHS, typename RHS> \
name(const LHS&, const RHS&) -> name<LHS, RHS>; \
\
} \
\
template <typename LHS, typename RHS> \
Expand Down
1 change: 1 addition & 0 deletions include/Test/Test.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "Support/FileSystem.h"
#include "Support/FixedString.h"
#include "llvm/ADT/FunctionExtras.h"
#include "Test2.h"

namespace clice::testing {

Expand Down
180 changes: 180 additions & 0 deletions include/Test/Test2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
#pragma once

#include <source_location>
#include <string>
#include <print>
#include <vector>
#include "Support/FixedString.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/FunctionExtras.h"
#include "Runner.h"
#include "cpptrace/cpptrace.hpp"

namespace clice::testing {

template <fixed_string TestName, typename Derived>
struct TestSuiteDef {
private:
struct TestCaseDef {
std::string name;
TestState (Derived::*func)();
};

TestState state = TestState::Passed;

public:
using Self = Derived;

void failure() {
state = TestState::Failed;
}

void pass() {
state = TestState::Passed;
}

void skip() {
state = TestState::Skipped;
}

constexpr inline static auto& test_cases() {
static std::vector<TestCase> instance;
return instance;
}

constexpr inline static auto suites() {
return std::move(test_cases());
}
Comment thread
16bit-ykiko marked this conversation as resolved.
Resolved

template <typename T = void>
inline static bool _register_suites = [] {
Runner2::instance().add_suite(TestName.data(), &suites);
return true;
}();

template <fixed_string CaseName, auto Case, TestAttrs attrs = {}>
inline static bool _register_test_case = [] {
auto run_test = +[] -> TestState {
Derived test;
if constexpr(requires { test.setup(); }) {
test.setup();
}

(test.*Case)();

if constexpr(requires { test.teardown(); }) {
test.teardown();
}

return test.state;
};

test_cases().emplace_back(CaseName.data(), run_test, attrs);
return true;
}();
};

inline void print_trace(cpptrace::stacktrace& trace, std::source_location location) {
auto& frames = trace.frames;
auto it = std::ranges::find_if(frames, [&](cpptrace::stacktrace_frame& frame) {
return frame.filename != location.file_name();
});
frames.erase(it, frames.end());
trace.print();
}
Comment thread
16bit-ykiko marked this conversation as resolved.
Resolved

#define TEST_SUITE(name) struct name##TEST : TestSuiteDef<#name, name##TEST>

#define TEST_CASE(name, ...) \
void _register_##name() { \
(void)_register_suites<>; \
(void)_register_test_case<#name, &Self::test_##name __VA_OPT__(, ) __VA_ARGS__>; \
} \
void test_##name()
Comment thread
16bit-ykiko marked this conversation as resolved.
Resolved

#define EXPECT_TRUE(expr) \
if(expr) { \
auto trace = cpptrace::generate_trace(); \
print_trace(trace, std::source_location::current()); \
failure(); \
}
Comment thread
16bit-ykiko marked this conversation as resolved.
Resolved

#define EXPECT_EQ(lhs, rhs) \
if(lhs != rhs) { \
auto trace = cpptrace::generate_trace(); \
print_trace(trace, std::source_location::current()); \
failure(); \
}

#define ASSERT_TRUE(expr) \
if(!(expr)) { \
auto trace = cpptrace::generate_trace(); \
print_trace(trace, std::source_location::current()); \
return failure(); \
}

#define ASSERT_FALSE(expr) \
if((expr)) { \
auto trace = cpptrace::generate_trace(); \
print_trace(trace, std::source_location::current()); \
return failure(); \
}

#define ASSERT_EQ(lhs, rhs) \
if(lhs != rhs) { \
auto trace = cpptrace::generate_trace(); \
print_trace(trace, std::source_location::current()); \
return failure(); \
}

#ifndef ASSERT_NE
#define ASSERT_NE(lhs, rhs) \
if((lhs) == (rhs)) { \
auto trace = cpptrace::generate_trace(); \
clice::testing::print_trace(trace, std::source_location::current()); \
return failure(); \
}
#endif

#ifndef EXPECT_NE
#define EXPECT_NE(lhs, rhs) \
if((lhs) == (rhs)) { \
auto trace = cpptrace::generate_trace(); \
clice::testing::print_trace(trace, std::source_location::current()); \
failure(); \
}
#endif

#define CO_ASSERT_TRUE(expr) \
if(!(expr)) { \
auto trace = cpptrace::generate_trace(); \
print_trace(trace, std::source_location::current()); \
failure(); \
co_return; \
}

#define CO_ASSERT_FALSE(expr) \
if((expr)) { \
auto trace = cpptrace::generate_trace(); \
print_trace(trace, std::source_location::current()); \
failure(); \
co_return; \
}

#define CO_ASSERT_EQ(lhs, rhs) \
if((lhs) != (rhs)) { \
auto trace = cpptrace::generate_trace(); \
print_trace(trace, std::source_location::current()); \
failure(); \
co_return; \
}

#define CO_ASSERT_NE(lhs, rhs) \
if((lhs) == (rhs)) { \
auto trace = cpptrace::generate_trace(); \
print_trace(trace, std::source_location::current()); \
failure(); \
co_return; \
}

} // namespace clice::testing
8 changes: 6 additions & 2 deletions src/AST/Resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,14 @@ class PseudoInstantiator : public clang::TreeTransform<PseudoInstantiator> {

/// SomeAllocator<U, Args> -> SomeAllocator<T, Args>
if(auto TST = Alloc->getAs<clang::TemplateSpecializationType>()) {
llvm::SmallVector<clang::TemplateArgument, 4> replaceArguments = {T};
llvm::SmallVector<clang::TemplateArgument, 1> replaceArguments = {T};
llvm::SmallVector<clang::TemplateArgument, 1> canonicalArguments;
for(auto& arg: replaceArguments) {
canonicalArguments.emplace_back(context.getCanonicalTemplateArgument(arg));
}
return context.getTemplateSpecializationType(TST->getTemplateName(),
replaceArguments,
replaceArguments);
canonicalArguments);
}
Comment thread
16bit-ykiko marked this conversation as resolved.
Resolved
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Index/MergedIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ struct DenseMapInfo<clice::index::Relation> {
lhs.target_symbol == rhs.target_symbol;
}
};

} // namespace llvm

namespace clice::index {
Expand Down
Loading