Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
45 changes: 42 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ SpaceBeforeParensOptions:
AfterFunctionDeclarationName: false
AfterFunctionDefinitionName: false
AfterIfMacros: false
AfterOverloadedOperator: true
AfterOverloadedOperator: false
AfterRequiresInClause: true
AfterRequiresInExpression: false
BeforeNonEmptyParentheses: false
Expand All @@ -93,11 +93,50 @@ SpacesInParensOptions:

SpacesInSquareBrackets: false

WrapNamespaceBodyWithEmptyLines: Always
# Order
QualifierAlignment: Custom
QualifierOrder: ["constexpr", "const", "inline", "static", "type"]
SortIncludes: Never
SortIncludes: true
SortUsingDeclarations: Never
IncludeBlocks: Merge
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^["<](spdlog|toml\+\+|coraing|cpptrace|flatbuffers)/'
Priority: 30
SortPriority: 31

- Regex: '^["<](llvm)/'
Priority: 30
SortPriority: 32

- Regex: '^["<](clang)/'
Priority: 30
SortPriority: 33

- Regex: '^["<](clang-tidy)/'
Priority: 30
SortPriority: 34

- Regex: '^["<](Test)/'
Priority: 20
SortPriority: 22

- Regex: "^<.*"
Priority: 10
SortPriority: 10

- Regex: '^".*/.*"'
Priority: 20
SortPriority: 23

- Regex: ".*"
Priority: 20
SortPriority: 21

ForEachMacros: ["REFLECTABLE_RECORD"]
NamespaceMacros: [TEST_SUITE]

KeepEmptyLines:
AtEndOfFile: false
AtStartOfBlock: false
AtStartOfFile: false
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()
8 changes: 4 additions & 4 deletions bin/clice.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "Server/Version.h"
#include "Server/Server.h"
#include "Support/Logging.h"
#include "Server/Version.h"
#include "Support/Format.h"
#include "Support/Logging.h"

#include "llvm/Support/InitLLVM.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/Process.h"
#include "llvm/ADT/StringSwitch.h"

namespace cl = llvm::cl;
using namespace clice;
Expand Down
152 changes: 2 additions & 150 deletions bin/unit_tests.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Test/Test.h"
#include "Support/Logging.h"
#include "Support/GlobPattern.h"
#include "Support/Logging.h"

#include "llvm/ADT/SmallString.h"
#include "llvm/Support/CommandLine.h"
Expand All @@ -9,11 +9,6 @@
using namespace clice;
using namespace clice::testing;

constexpr static std::string_view GREEN = "\033[32m";
constexpr static std::string_view YELLOW = "\033[33m";
constexpr static std::string_view RED = "\033[31m";
constexpr static std::string_view CLEAR = "\033[0m";

namespace {

namespace cl = llvm::cl;
Expand All @@ -40,163 +35,20 @@ cl::opt<bool> enable_example{
cl::cat(unittest_category),
};

std::optional<GlobPattern> pattern;

} // namespace

namespace clice::testing {

Runner& Runner::instance() {
static Runner runner;
return runner;
}

void Runner::add_suite(std::string_view name, Suite suite) {
suites[name].emplace_back(suite);
}

void Runner::on_test(std::string_view name, Test test, bool skipped) {
std::string full_name = std::format("{}.{}", curr_suite_name, name);

/// If this test if filter, directly return.
if(pattern && !pattern->match(full_name)) {
return;
}

/// If there is any test in the suite, we print the suite start info.
if(all_skipped) {
std::println("{}[----------] tests from {}{}", GREEN, curr_suite_name, CLEAR);
all_skipped = false;
}

if(skipped) {
/// If this test is marked as skipped, only print skip information.
std::println("{}[ SKIPPED ] {}{}", YELLOW, full_name, CLEAR);
return;
}

/// Reset whether this test is failed or fatal.
curr_failed = false;
curr_fatal = false;

using namespace std::chrono;

std::println("{}[ RUN ] {}.{}{}", GREEN, curr_suite_name, name, CLEAR);
auto begin = system_clock::now();

test();

auto duration = duration_cast<milliseconds>(system_clock::now() - begin);
std::println("{}[ {} ] {} ({} ms){}",
curr_failed ? RED : GREEN,
curr_failed ? "FAILED" : " OK",
full_name,
duration.count(),
CLEAR);

/// Update test information.
curr_tests_count += 1;
total_tests_count += 1;

curr_test_duration += duration;
total_test_duration += duration;

if(curr_failed) {
curr_failed_tests_count += 1;
total_failed_tests_count += 1;
}
}

void Runner::fail(const may_failure& failure) {
if(failure.failed) {
curr_failed = true;
std::println("{}Failure at {}:{}:{}! [{}]{}",
RED,
failure.location.file_name(),
failure.location.line(),
failure.location.column(),
failure.expression,
CLEAR);
std::println("{}", failure.message);
}

if(failure.fatal) {
curr_fatal = true;
std::println("{}--> Test stopped due to fatal error.{}", RED, CLEAR);
std::exit(1);
}
}

int Runner::run_tests() {
/// Register all tests.
std::println("{}[----------] Global test environment set-up.{}", GREEN, CLEAR);

for(auto& [suite_name, suite]: suites) {
if(!enable_example && suite_name == "TEST.Example") {
continue;
}

if(!test_filter.empty()) {
auto pos = test_filter.find_first_of('.');
if(pos != std::string::npos && test_filter.substr(0, pos) != suite_name) {
continue;
}
}

curr_fatal = false;
all_skipped = true;
curr_suite_name = suite_name;
curr_tests_count = 0;
curr_failed_tests_count = 0;
curr_test_duration = std::chrono::milliseconds();

for(auto& callback: suite) {
callback();
}

/// If there is any test in the suite, we print the suite info.
if(!all_skipped) {
total_suites_count += 1;
std::println("{}[----------] {} tests from {} ({} ms total)\n{}",
GREEN,
curr_tests_count,
suite_name,
total_test_duration.count(),
CLEAR);
}
}

std::println("{}[----------] Global test environment tear-down{}", GREEN, CLEAR);
std::println("{}[==========] {} tests from {} test suites ran. ({} ms total){}",
GREEN,
total_tests_count,
total_suites_count,
total_test_duration.count(),
CLEAR);

return total_failed_tests_count != 0;
}

} // namespace clice::testing

int main(int argc, const char* argv[]) {
llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
llvm::cl::HideUnrelatedOptions(unittest_category);
llvm::cl::ParseCommandLineOptions(argc, argv, "clice test\n");

logging::stderr_logger("clice", logging::options);

if(!test_filter.empty()) {
if(auto result = GlobPattern::create(test_filter)) {
pattern.emplace(std::move(*result));
}
}

if(auto result = fs::init_resource_dir(argv[0]); !result) {
std::println("Failed to get resource directory, because {}", result.error());
return 1;
}

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: 1 addition & 1 deletion include/AST/Context.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <string>
#include <cstdint>
#include <string>

namespace clice {

Expand Down
1 change: 1 addition & 0 deletions include/AST/FilterASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "AST/SourceCode.h"
#include "Compiler/CompilationUnit.h"

#include "clang/AST/RecursiveASTVisitor.h"

namespace clice {
Expand Down
2 changes: 1 addition & 1 deletion include/AST/Resolver.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "clang/AST/Type.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/Type.h"

namespace clang {

Expand Down
10 changes: 6 additions & 4 deletions include/AST/Selection.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#pragma once

#include <stack>

#include "SourceCode.h"

#include "llvm/ADT/SmallVector.h"
#include "clang/AST/ASTTypeTraits.h"
#include "clang/AST/PrettyPrinter.h"
#include "clang/Tooling/Syntax/Tokens.h"
#include "llvm/ADT/SmallVector.h"

namespace clice {

Expand Down Expand Up @@ -57,11 +59,11 @@ class SelectionTree {

/// Copies are no good - contain pointers to other nodes.
SelectionTree(const SelectionTree&) = delete;
SelectionTree& operator= (const SelectionTree&) = delete;
SelectionTree& operator=(const SelectionTree&) = delete;

/// Moves are OK though - internal storage is pointer-stable when moved.
SelectionTree(SelectionTree&&) = default;
SelectionTree& operator= (SelectionTree&&) = default;
SelectionTree& operator=(SelectionTree&&) = default;

// Describes to what extent an AST node is covered by the selection.
enum SelectionKind : unsigned char {
Expand Down Expand Up @@ -129,7 +131,7 @@ class SelectionTree {

void print(llvm::raw_ostream& os, const Node& node, int indent) const;

friend llvm::raw_ostream& operator<< (llvm::raw_ostream& os, const SelectionTree& tree) {
friend llvm::raw_ostream& operator<<(llvm::raw_ostream& os, const SelectionTree& tree) {
tree.print(os, tree.root(), 1);
return os;
}
Expand Down
7 changes: 3 additions & 4 deletions include/AST/Semantic.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once

#include "Utility.h"
#include "FilterASTVisitor.h"
#include "RelationKind.h"
#include "Resolver.h"
#include "SymbolKind.h"
#include "RelationKind.h"
#include "FilterASTVisitor.h"
#include "Utility.h"

namespace clice {

Expand Down Expand Up @@ -637,7 +637,6 @@ class SemanticVisitor : public FilteredASTVisitor<SemanticVisitor<Derived>> {
}

bool VisitAttr(clang::Attr* attr) {

getDerived().handleAttrOccurrence(attr, attr->getRange());
return true;
}
Expand Down
Loading