36#if !defined(LUTOK_TEST_UTILS_HPP)
37# define LUTOK_TEST_UTILS_HPP
39# error "test_utils.hpp can only be included once"
61#define REQUIRE_API_ERROR(exp_api_function, statement) \
65 ATF_FAIL("api_error not raised by " #statement); \
66 } catch (const lutok::api_error& api_error) { \
67 ATF_REQUIRE_EQ(exp_api_function, api_error.api_function()); \
79static inline lua_State*
111 const bool with_sentinel_ =
true) :
113 _with_sentinel(with_sentinel_),
114 _old_count(_state.get_top())
126 if (_with_sentinel) {
128 ATF_FAIL(
"Stack corrupted: sentinel not found");
132 unsigned int new_count = _state.
get_top();
133 if (_old_count != new_count)
136 ATF_FAIL(
"Stack not balanced");
Provides direct access to the C state of the Lua wrappers.
Exception types raised by lutok.
Provides the state wrapper class for the Lua C state.
static lua_State * raw(lutok::state &state)
Gets the pointer to the internal lua_State of a state object.
Definition test_utils.hpp:80
Gateway to the raw C state of Lua.
Definition c_gate.hpp:55
lua_State * c_state(void)
Returns the C native Lua state.
Definition c_gate.cpp:73
A RAII model for the Lua state.
Definition state.hpp:76
void push_integer(const int)
Wrapper around lua_pushinteger.
Definition state.cpp:709
void pop(const int)
Wrapper around lua_pop.
Definition state.cpp:654
bool is_number(const int)
Wrapper around lua_isnumber.
Definition state.cpp:442
long to_integer(const int)
Wrapper around lua_tointeger.
Definition state.cpp:838
int get_top(void)
Wrapper around lua_gettop.
Definition state.cpp:384
Ensures that the Lua stack maintains its original height upon exit.
Definition test_utils.hpp:92
stack_balance_checker(lutok::state &state_, const bool with_sentinel_=true)
Constructs a new stack balance checker.
Definition test_utils.hpp:110
~stack_balance_checker(void)
Destructor for the object.
Definition test_utils.hpp:124
lutok::state & _state
The Lua state.
Definition test_utils.hpp:94
unsigned int _old_count
The height of the stack on creation.
Definition test_utils.hpp:100
bool _with_sentinel
Whether to install a sentinel on the stack for balance enforcement.
Definition test_utils.hpp:97