Skip to content

Commit

Permalink
feat: Assert unknown event types (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzenker authored Nov 19, 2021
1 parent 597b27e commit fe5461d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,8 @@ cmake --install build/ --prefix /tmp/
``` bash
mkdir -p build/dependencies/conan
conan install . -if build/dependencies/conan -s compiler.libcxx=libstdc++11 --build missing
cmake -S . -B build
cmake --install build/ --prefix /tmp/ -D "CMAKE_MODULE_PATH=${PWD}/build/dependencies/conan"
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -D "CMAKE_PREFIX_PATH=${PWD}/build/dependencies/conan"
cmake --install build/ --prefix /tmp/
```
### Conan [![Download](https://api.bintray.com/packages/erikzenker/conan-erikzenker/hsm%3Aerikzenker/images/download.svg) ](https://bintray.com/erikzenker/conan-erikzenker/hsm%3Aerikzenker/_latestVersion)
``` bash
Expand All @@ -416,5 +416,15 @@ cd build/test
ctest --output-on-failure
```

## Compile and Run the Tests Using Conan
``` bash
mkdir -p build/dependencies/conan
conan install . -if build/dependencies/conan -s compiler.libcxx=libstdc++11 --build missing
cmake -S test/ -B build/test -DCMAKE_BUILD_TYPE=Release -D "CMAKE_PREFIX_PATH=${PWD}/build/dependencies/conan"
cmake --build build/test/
cd build/test
ctest --output-on-failure
```

## Author
* erikzenker(at)hotmail.com
6 changes: 6 additions & 0 deletions include/hsm/details/sm.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ template <class RootState, class... OptionalParameters> class sm {

template <class Event> auto process_event(Event&& event)
{
static_assert(
bh::contains(
collect_event_typeids_recursive(rootState),
bh::type_c<typename std::remove_reference<Event>::type>),
"Processed event was not found in the transition table");

if (!process_event_internal(event)) {
call_unexpected_event_handler(event);
return;
Expand Down
6 changes: 6 additions & 0 deletions include/hsm/gen/hsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -2350,6 +2350,12 @@ template <class RootState, class... OptionalParameters> class sm {

template <class Event> auto process_event(Event&& event)
{
static_assert(
bh::contains(
collect_event_typeids_recursive(rootState),
bh::type_c<typename std::remove_reference<Event>::type>),
"Processed event was not found in the transition table");

if (!process_event_internal(event)) {
call_unexpected_event_handler(event);
return;
Expand Down
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ include(FetchContent)
FetchContent_Declare(hsm SOURCE_DIR "${PROJECT_SOURCE_DIR}/..")
FetchContent_MakeAvailable(hsm)

MESSAGE(STATUS ${CMAKE_MODULE_PATH})

find_package(GTest CONFIG REQUIRED)
include(GoogleTest)

Expand Down
1 change: 1 addition & 0 deletions test/conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[requires]
gtest/cci.20210126
boost/1.72.0

[generators]
cmake_find_package_multi

0 comments on commit fe5461d

Please sign in to comment.