Repository navigation
refactor: tests and format the world #314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2413135
introduce `cpptrace`
16bit-ykiko 73a0d35
fix macos build
16bit-ykiko 4a88025
some update
16bit-ykiko 394567b
Merge branch 'main' of https://github.com/clice-io/clice into refacto…
16bit-ykiko e8c57b0
some update
16bit-ykiko cf2a96b
some update
16bit-ykiko d93503d
refactor `async` tests
16bit-ykiko 6397d9e
refactor `Compiler`
16bit-ykiko 55448c6
refactor `Feature`
16bit-ykiko 3e0369b
refactor `Index`
16bit-ykiko 846df3e
refactor others
16bit-ykiko 45f0db5
fix tests
16bit-ykiko bfd2156
fix tests
16bit-ykiko 777c5fa
clear unused code
16bit-ykiko 70bbe23
some update
16bit-ykiko 980060d
format the world
16bit-ykiko 7efcadc
add focus mode
16bit-ykiko 4f316bb
some format
16bit-ykiko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,4 +58,5 @@ struct Widget { | |
|
|
||
| template <typename T> | ||
| Widget(T) -> Widget<typename T::value_type>; | ||
|
|
||
| } // namespace foo | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,9 @@ | |
| #include "Support/FileSystem.h" | ||
|
|
||
| namespace clang { | ||
|
|
||
| class CodeCompleteConsumer; | ||
|
|
||
| } | ||
|
|
||
| namespace clice { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,9 @@ | |
| #include "clang/Basic/Diagnostic.h" | ||
|
|
||
| namespace clang { | ||
|
|
||
| class DiagnosticConsumer; | ||
|
|
||
| } | ||
|
|
||
| namespace clice { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,9 @@ | |
| #include <memory> | ||
|
|
||
| namespace clang { | ||
|
|
||
| class CompilerInstance; | ||
|
|
||
| } | ||
|
|
||
| namespace clice::tidy { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,9 @@ | |
| #include "llvm/ADT/DenseMap.h" | ||
|
|
||
| namespace clice { | ||
|
|
||
| class CompilationUnit; | ||
|
|
||
| } | ||
|
|
||
| namespace clice::index { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()); | ||
| } | ||
|
|
||
| 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(); | ||
| } | ||
|
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() | ||
|
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(); \ | ||
| } | ||
|
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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.