Lutok: test_utils.hpp File Reference

Lutok 0.4

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Macros
Classes | Namespaces | Macros | Functions
test_utils.hpp File Reference

Utilities for tests of the lua modules. More...

`#include <atf-c++.hpp>`
`#include "c_gate.hpp"`
`#include "exceptions.hpp"`
`#include "state.hpp"`

Go to the source code of this file.

## Classes
class | anonymous_namespace{test_utils.hpp}::stack_balance_checker
| Ensures that the Lua stack maintains its original height upon exit. More...

## Namespaces
namespace | anonymous_namespace{test_utils.hpp}

## Macros
#define | REQUIRE_API_ERROR(exp_api_function, statement)
| Checks that a given expression raises a particular lutok::api_error.

## Functions
static lua_State * | anonymous_namespace{test_utils.hpp}::raw (lutok::state &state)
| Gets the pointer to the internal lua_State of a state object.

## Detailed Description

Utilities for tests of the lua modules.

This file is intended to be included once, and only once, for every test program that needs it. All the code is herein contained to simplify the dependency chain in the build rules.

## Macro Definition Documentation

#define REQUIRE_API_ERROR | ( |  | exp_api_function,
|  |  | statement
| ) |  |

Value:
do { \
try { \
statement; \
ATF_FAIL("api_error not raised by " #statement); \
} catch (const lutok::api_error& api_error) { \
ATF_REQUIRE_EQ(exp_api_function, api_error.api_function()); \
} \
} while (0)

Checks that a given expression raises a particular lutok::api_error.

We cannot make any assumptions regarding the error text provided by Lua, so we resort to checking only which API function raised the error (because our code is the one hardcoding these strings).

Parameters:

  exp_api_function | The name of the Lua C API function that causes the error.
  statement | The statement to execute.