Ensures that the Lua stack maintains its original height upon exit. More...
#include <test_utils.hpp>
Public Member Functions | |
stack_balance_checker (lutok::state &state_, const bool with_sentinel_=true) | |
Constructs a new stack balance checker. | |
~stack_balance_checker (void) | |
Destructor for the object. | |
Private Attributes | |
lutok::state & | _state |
The Lua state. | |
bool | _with_sentinel |
Whether to install a sentinel on the stack for balance enforcement. | |
unsigned int | _old_count |
The height of the stack on creation. |
Ensures that the Lua stack maintains its original height upon exit.
Use an instance of this class to check that a piece of code does not have side-effects on the Lua stack.
To be used within a test case only.
anonymous_namespace{test_utils.hpp}::stack_balance_checker::stack_balance_checker | ( | lutok::state & | state_, |
const bool | with_sentinel_ = true |
||
) | [inline] |
Constructs a new stack balance checker.
state_ | The Lua state to validate. |
with_sentinel_ | If true, insert a sentinel item into the stack and validate upon exit that the item is still there. This is an attempt to ensure that already-existing items are not removed from the stack by the code under test. |
anonymous_namespace{test_utils.hpp}::stack_balance_checker::~stack_balance_checker | ( | void | ) | [inline] |
Destructor for the object.
If the stack height does not match the height when the instance was created, this fails the test case.