Loading...
Searching...
No Matches
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"`
Include dependency graph for test_utils.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...

## 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

## REQUIRE_API_ERROR

#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)
lutok::api_error
Exception for errors raised by the Lua API library.
Definition exceptions.hpp:53
lutok::api_error::api_function
const std::string & api_function(void) const
Gets the name of the Lua API function that caused this error.
Definition exceptions.cpp:96

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.