TTS v4.1.0
The Tiny Test System
Loading...
Searching...
No Matches
Customization Points

Macros

#define TTS_CUSTOM_DRIVER_FUNCTION
 Names the function that runs the tests when main comes from elsewhere.
#define TTS_MAIN
 Defines the entry point of the test program in the translation unit that defines it.

Functions

void tts::initialize (int argc, char const **argv)
 Initializes a TTS test suite.
int tts::report (counter fails, counter invalids)
 Test reporting customization point.
template<typename Handler>
tts_implementation_defined tts::set_abort_handler (Handler h)
 Run termination customization point.

Macro Definition Documentation

◆ TTS_CUSTOM_DRIVER_FUNCTION

#define TTS_CUSTOM_DRIVER_FUNCTION

#include <tts/engine/main.hpp>

Names the function that runs the tests when main comes from elsewhere.

A program that writes its own main defines TTS_MAIN and TTS_CUSTOM_DRIVER_FUNCTION before including tts/tts.hpp. Its main calls tts::initialize, the function of that name with argc and argv, then tts::report.

Example

#define TTS_MAIN
#define TTS_CUSTOM_DRIVER_FUNCTION my_test_main
#include <tts/tts.hpp>
#include <iostream>
TTS_CASE("Some test")
{
// This test will be counted as invalid because it does not contain any assertion.
};
int main(int argc, char const** argv)
{
std::cout << "Initializing tests...\n";
::tts::initialize(argc, argv);
std::cout << "Running tests...\n";
my_test_main(argc, argv);
std::cout << "Finalizing tests...\n";
return ::tts::report(0, 1);
}
See also
TTS_MAIN
tts::initialize
tts::report

◆ TTS_MAIN

#define TTS_MAIN

#include <tts/engine/main.hpp>

Defines the entry point of the test program in the translation unit that defines it.

A program split over several translation units defines TTS_MAIN in a single unit, before including tts/tts.hpp.

Function Documentation

◆ initialize()

void tts::initialize ( int argc,
char const ** argv )
inline

#include <tts/tools/options.hpp>

Initializes a TTS test suite.

This function is to be called when writing a custom entry point.

Parameters
argcNumber of command line argument fetched from main
argvCommand line arguments pointer fetched from main
See also
TTS_CUSTOM_DRIVER_FUNCTION

◆ report()

int tts::report ( counter fails,
counter invalids )
inline

#include <tts/engine/environment.hpp>

Test reporting customization point.

Aggregates test results and validate the whole test suite with respect to expect numbers of failures and invalids.

Parameters
failsNumber of expected failures.
invalidsNumber of expected invalid tests.
Returns
0 if all tests passed and 1 otherwise.

◆ set_abort_handler()

template<typename Handler>
tts_implementation_defined tts::set_abort_handler ( Handler h)
inline

#include <tts/engine/abort.hpp>

Run termination customization point.

Runs just before TTS exits a crashed or timed out run, with the signal that brought it down or 0 when nothing did. TTS exits once it returns, with 1, or with 0 when the case that brought the run down was tagged TTS_XFAIL or TTS_MAYFAIL.

Useful when a test binary has to handle an abrupt stop in its own way.

Parameters
hAny callable taking an int.
Returns
The handler installed before this call, empty if there was none.
See also
TTS_CUSTOM_DRIVER_FUNCTION

Example

TTS_CASE("Choosing what a crashed or stuck run does before exiting")
{
auto previous = tts::set_abort_handler(
[](int reason) { std::cout << "tearing down after signal " << reason << "\n"; });
TTS_EXPECT_NOT(previous);
};