Remove the two old FSMs ahead of the inheritance-based rewrite
Deletes the compile-time Void::StateMachine and the builder-based runtime Void::Fsm (Definition/Machine/Event/PluginBehavior + their standalone tests, the FSM behaviour plugins, and the FSM x Plugin integration test and its CMake wiring). The general-purpose Plugin module and its stateful hot-reload tests are untouched. Both are being replaced by a single inheritance + coroutine workflow FSM (next phase). 936 tests green (51 old FSM/StateMachine tests removed). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6b5f61f00a
commit
04cf1998bd
20 files changed
+3
-3793
No files matched your search
@@ -1,247 +0,0 @@
|
||||
#include <Void/Fsm/Definition.hpp>
|
||||
#include <Void/Fsm/Machine.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace Void::Fsm;
|
||||
|
||||
namespace
|
||||
{
|
||||
// Embedder-driven machine (no worker thread): post + run_pending make
|
||||
// the tests fully deterministic.
|
||||
struct Bench {
|
||||
std::shared_ptr<const MachineDef> def;
|
||||
std::unique_ptr<Machine> machine;
|
||||
std::vector<std::string> log;
|
||||
|
||||
explicit Bench(Builder& b)
|
||||
{
|
||||
auto built = b.build();
|
||||
Void::Testing::expect(built.has_value());
|
||||
def = *built;
|
||||
machine = std::make_unique<Machine>(
|
||||
def, MachineOptions{.own_worker = false});
|
||||
}
|
||||
|
||||
SendResult step(EventId ev)
|
||||
{
|
||||
machine->post(Event{ev, {}});
|
||||
machine->run_pending();
|
||||
return SendResult::Handled; // result checked via send paths
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
Void::Testing::Test basic_initial_state_entered_on_start()
|
||||
{
|
||||
Builder b;
|
||||
auto idle = b.state("idle");
|
||||
auto run = b.state("running");
|
||||
b.initial(idle);
|
||||
(void)run;
|
||||
|
||||
Bench bench{b};
|
||||
bench.machine->start();
|
||||
Void::Testing::expect(bench.machine->is_in("idle"));
|
||||
Void::Testing::expect(!bench.machine->is_in("running"));
|
||||
Void::Testing::expect(bench.machine->running());
|
||||
}
|
||||
|
||||
Void::Testing::Test basic_transition_changes_state()
|
||||
{
|
||||
Builder b;
|
||||
auto idle = b.state("idle");
|
||||
auto run = b.state("running");
|
||||
b.initial(idle);
|
||||
const auto go = b.event("go");
|
||||
b.transition(idle, go, run);
|
||||
|
||||
Bench bench{b};
|
||||
bench.machine->start();
|
||||
bench.machine->post(Event{go, {}});
|
||||
bench.machine->run_pending();
|
||||
|
||||
Void::Testing::expect(bench.machine->is_in("running"));
|
||||
Void::Testing::expect(!bench.machine->is_in("idle"));
|
||||
}
|
||||
|
||||
Void::Testing::Test basic_entry_exit_and_action_ordering()
|
||||
{
|
||||
std::vector<std::string> log;
|
||||
Builder b;
|
||||
auto a = b.state("a");
|
||||
auto c = b.state("c");
|
||||
b.initial(a);
|
||||
const auto go = b.event("go");
|
||||
b.on_entry(a, SyncAction{[&](Machine&, const Event&) {
|
||||
log.push_back("enter a");
|
||||
}});
|
||||
b.on_exit(a, SyncAction{[&](Machine&, const Event&) {
|
||||
log.push_back("exit a");
|
||||
}});
|
||||
b.on_entry(c, SyncAction{[&](Machine&, const Event&) {
|
||||
log.push_back("enter c");
|
||||
}});
|
||||
b.transition(a, go, c).action(SyncAction{
|
||||
[&](Machine&, const Event&) { log.push_back("action"); }});
|
||||
|
||||
Bench bench{b};
|
||||
bench.machine->start();
|
||||
bench.machine->post(Event{go, {}});
|
||||
bench.machine->run_pending();
|
||||
|
||||
const std::vector<std::string> expected{"enter a", "exit a", "action",
|
||||
"enter c"};
|
||||
Void::Testing::expect(log == expected);
|
||||
}
|
||||
|
||||
Void::Testing::Test basic_guard_blocks_and_allows()
|
||||
{
|
||||
Builder b;
|
||||
auto a = b.state("a");
|
||||
auto c = b.state("c");
|
||||
b.initial(a);
|
||||
const auto go = b.event("go");
|
||||
bool open = false;
|
||||
b.transition(a, go, c).guard(
|
||||
[&](const Machine&, const Event&) { return open; });
|
||||
|
||||
Bench bench{b};
|
||||
bench.machine->start();
|
||||
|
||||
bench.machine->post(Event{go, {}});
|
||||
bench.machine->run_pending();
|
||||
Void::Testing::expect(bench.machine->is_in("a"));
|
||||
|
||||
open = true;
|
||||
bench.machine->post(Event{go, {}});
|
||||
bench.machine->run_pending();
|
||||
Void::Testing::expect(bench.machine->is_in("c"));
|
||||
}
|
||||
|
||||
Void::Testing::Test basic_internal_transition_no_exit_entry()
|
||||
{
|
||||
std::vector<std::string> log;
|
||||
Builder b;
|
||||
auto a = b.state("a");
|
||||
b.initial(a);
|
||||
const auto tick = b.event("tick");
|
||||
b.on_entry(a, SyncAction{[&](Machine&, const Event&) {
|
||||
log.push_back("enter");
|
||||
}});
|
||||
b.on_exit(a, SyncAction{[&](Machine&, const Event&) {
|
||||
log.push_back("exit");
|
||||
}});
|
||||
b.internal(a, tick).action(SyncAction{
|
||||
[&](Machine&, const Event&) { log.push_back("internal"); }});
|
||||
|
||||
Bench bench{b};
|
||||
bench.machine->start();
|
||||
bench.machine->post(Event{tick, {}});
|
||||
bench.machine->run_pending();
|
||||
|
||||
const std::vector<std::string> expected{"enter", "internal"};
|
||||
Void::Testing::expect(log == expected);
|
||||
Void::Testing::expect(bench.machine->is_in("a"));
|
||||
}
|
||||
|
||||
Void::Testing::Test basic_self_transition_exits_and_reenters()
|
||||
{
|
||||
std::vector<std::string> log;
|
||||
Builder b;
|
||||
auto a = b.state("a");
|
||||
b.initial(a);
|
||||
const auto reset = b.event("reset");
|
||||
b.on_entry(a, SyncAction{[&](Machine&, const Event&) {
|
||||
log.push_back("enter");
|
||||
}});
|
||||
b.on_exit(a, SyncAction{[&](Machine&, const Event&) {
|
||||
log.push_back("exit");
|
||||
}});
|
||||
b.transition(a, reset, a);
|
||||
|
||||
Bench bench{b};
|
||||
bench.machine->start();
|
||||
bench.machine->post(Event{reset, {}});
|
||||
bench.machine->run_pending();
|
||||
|
||||
const std::vector<std::string> expected{"enter", "exit", "enter"};
|
||||
Void::Testing::expect(log == expected);
|
||||
}
|
||||
|
||||
Void::Testing::Test basic_payload_reaches_action()
|
||||
{
|
||||
int received = 0;
|
||||
Builder b;
|
||||
auto a = b.state("a");
|
||||
auto c = b.state("c");
|
||||
b.initial(a);
|
||||
const auto go = b.event("go");
|
||||
b.transition(a, go, c).action(
|
||||
SyncAction{[&](Machine&, const Event& e) {
|
||||
received = std::any_cast<int>(e.payload);
|
||||
}});
|
||||
|
||||
Bench bench{b};
|
||||
bench.machine->start();
|
||||
bench.machine->post(Event{go, 42});
|
||||
bench.machine->run_pending();
|
||||
Void::Testing::expect_eq(received, 42);
|
||||
}
|
||||
|
||||
Void::Testing::Test basic_unhandled_event_keeps_state()
|
||||
{
|
||||
Builder b;
|
||||
auto a = b.state("a");
|
||||
b.initial(a);
|
||||
const auto noop = b.event("noop");
|
||||
(void)noop;
|
||||
|
||||
Bench bench{b};
|
||||
bench.machine->start();
|
||||
bench.machine->post(Event{noop, {}});
|
||||
bench.machine->run_pending();
|
||||
Void::Testing::expect(bench.machine->is_in("a"));
|
||||
}
|
||||
|
||||
Void::Testing::Test basic_post_rejected_before_start_and_after_stop()
|
||||
{
|
||||
Builder b;
|
||||
auto a = b.state("a");
|
||||
b.initial(a);
|
||||
const auto go = b.event("go");
|
||||
|
||||
Bench bench{b};
|
||||
Void::Testing::expect(!bench.machine->post(Event{go, {}}));
|
||||
bench.machine->start();
|
||||
Void::Testing::expect(bench.machine->post(Event{go, {}}));
|
||||
bench.machine->run_pending();
|
||||
bench.machine->stop();
|
||||
Void::Testing::expect(!bench.machine->post(Event{go, {}}));
|
||||
Void::Testing::expect(!bench.machine->running());
|
||||
}
|
||||
|
||||
Void::Testing::Test builder_rejects_composite_without_initial()
|
||||
{
|
||||
Builder b;
|
||||
auto parent = b.state("parent");
|
||||
(void)b.state("c1", parent);
|
||||
(void)b.state("c2", parent);
|
||||
b.initial(parent); // parent initial of root, but no initial child
|
||||
auto built = b.build();
|
||||
Void::Testing::expect(!built.has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test builder_defaults_first_top_level_as_initial()
|
||||
{
|
||||
Builder b;
|
||||
(void)b.state("first");
|
||||
(void)b.state("second");
|
||||
|
||||
Bench bench{b};
|
||||
bench.machine->start();
|
||||
Void::Testing::expect(bench.machine->is_in("first"));
|
||||
}
|
||||
Reference in new issue
Block a user