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
17 changes: 17 additions & 0 deletions include/eventide/zest/detail/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ struct TestSuite {
std::vector<TestCase> (*cases)();
};

inline TestState& current_test_state() {
thread_local TestState state = TestState::Passed;
return state;
}

inline void failure() {
current_test_state() = TestState::Failed;
}

inline void pass() {
current_test_state() = TestState::Passed;
}

inline void skip() {
current_test_state() = TestState::Skipped;
}

class Runner {
public:
static Runner& instance();
Expand Down
19 changes: 2 additions & 17 deletions include/eventide/zest/detail/suite.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,8 @@ namespace eventide::zest {

template <fixed_string TestName, typename Derived>
struct TestSuiteDef {
private:
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;
Expand All @@ -47,6 +31,7 @@ struct TestSuiteDef {
TestAttrs attrs = {}>
inline static bool _register_test_case = [] {
auto run_test = +[] -> TestState {
current_test_state() = TestState::Passed;
Derived test;
if constexpr(requires { test.setup(); }) {
test.setup();
Expand All @@ -58,7 +43,7 @@ struct TestSuiteDef {
test.teardown();
}

return test.state;
return current_test_state();
};

test_cases().emplace_back(case_name.data(), path.data(), line, attrs, run_test);
Expand Down
5 changes: 3 additions & 2 deletions include/eventide/zest/macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include "eventide/zest/detail/suite.h"
#include "eventide/zest/detail/trace.h"

#define TEST_SUITE(name) struct name##TEST : ::eventide::zest::TestSuiteDef<#name, name##TEST>
#define TEST_SUITE(name, ...) \
struct name##TEST : __VA_OPT__(__VA_ARGS__, )::eventide::zest::TestSuiteDef<#name, name##TEST>

#define TEST_CASE(name, ...) \
void _register_##name() { \
Expand All @@ -23,7 +24,7 @@
do { \
if(condition) [[unlikely]] { \
::eventide::zest::print_trace(std::source_location::current()); \
failure(); \
::eventide::zest::failure(); \
return_action; \
} \
} while(0)
Expand Down
35 changes: 8 additions & 27 deletions tests/unit/async/build_system_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <chrono>

#include "compile_graph.h"
#include "loop_fixture.h"
#include "eventide/zest/zest.h"
#include "eventide/async/async.h"

namespace eventide {

Expand All @@ -26,10 +26,9 @@ static CompileGraph make_test_graph() {
return graph;
}

TEST_SUITE(build_system) {
TEST_SUITE(build_system, loop_fixture) {

TEST_CASE(normal_compilation_completes) {
event_loop loop;
auto graph = make_test_graph();

auto test = [&]() -> task<> {
Expand All @@ -39,12 +38,10 @@ TEST_CASE(normal_compilation_completes) {
};

auto t = test();
loop.schedule(t);
loop.run();
schedule_all(t);
}

TEST_CASE(update_cancels_in_flight) {
event_loop loop;
auto graph = make_test_graph();
bool compile_cancelled = false;

Expand All @@ -60,16 +57,12 @@ TEST_CASE(update_cancels_in_flight) {

auto c = compiler();
auto u = updater();

loop.schedule(c);
loop.schedule(u);
loop.run();
schedule_all(c, u);

EXPECT_TRUE(compile_cancelled);
}

TEST_CASE(chain_cancel_propagates) {
event_loop loop;
auto graph = make_test_graph();
bool compile_cancelled = false;

Expand All @@ -85,16 +78,12 @@ TEST_CASE(chain_cancel_propagates) {

auto c = compiler();
auto u = updater();

loop.schedule(c);
loop.schedule(u);
loop.run();
schedule_all(c, u);

EXPECT_TRUE(compile_cancelled);
}

TEST_CASE(recompile_after_update) {
event_loop loop;
auto graph = make_test_graph();

auto test = [&]() -> task<> {
Expand All @@ -109,12 +98,10 @@ TEST_CASE(recompile_after_update) {
};

auto t = test();
loop.schedule(t);
loop.run();
schedule_all(t);
}

TEST_CASE(independent_compilations_unaffected) {
event_loop loop;
auto graph = make_test_graph();
bool parser_cancelled = false;
bool codegen_ok = false;
Expand All @@ -137,18 +124,13 @@ TEST_CASE(independent_compilations_unaffected) {
auto cp = compile_parser();
auto cc = compile_codegen();
auto u = updater();

loop.schedule(cp);
loop.schedule(cc);
loop.schedule(u);
loop.run();
schedule_all(cp, cc, u);

EXPECT_TRUE(parser_cancelled);
EXPECT_TRUE(codegen_ok);
}

TEST_CASE(shared_dependency_compiled_once) {
event_loop loop;
int compile_count = 0;

// Use a side-effecting delay_fn to count actual compilations
Expand All @@ -168,8 +150,7 @@ TEST_CASE(shared_dependency_compiled_once) {
};

auto t = test();
loop.schedule(t);
loop.run();
schedule_all(t);

// common.h (1) + a.cpp (1) + b.cpp (1) = 3
// Without dedup this would be 4 (common.h compiled twice).
Expand Down
Loading
Loading