TTS v3.0.0
The Tiny Test System
Loading...
Searching...
No Matches
Exception Tests Macros

Macros for performing checks related to exceptions handling. More...

Macros

#define TTS_NO_THROW(EXPR, ...)
 Checks if a given expression throws no exception.
#define TTS_THROW(EXPR, EXCEPTION, ...)
 Checks if a given expression throws an exception of a given type.

Macro Definition Documentation

◆ TTS_NO_THROW

#define TTS_NO_THROW ( EXPR,
... )

#include <tts/test/exceptions.hpp>

Checks if a given expression throws no exception.

Parameters
EXPRExpression to evaluate.
...Optional tag. If equals to REQUIRED, this test will stop the program if it fails.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
void bar()
{
// This function is marked as noexcept, so it should not throw any exceptions.
// If it does, the test framework should detect this and report it as a failure.
// In this case, we are not throwing anything, so the test should pass.
}
TTS_CASE("Check that nothrow function are detected as such")
{
TTS_NO_THROW(bar());
};

◆ TTS_THROW

#define TTS_THROW ( EXPR,
EXCEPTION,
... )

#include <tts/test/exceptions.hpp>

Checks if a given expression throws an exception of a given type.

Parameters
EXPRExpression to evaluate.
EXCEPTIONExpected exception type to be thrown.
...Optional tag. If equals to REQUIRED, this test will stop the program if it fails.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
struct some_exception_type
{
};
void foo()
{
throw some_exception_type();
}
TTS_CASE("Check that we can capture thrown exceptions")
{
TTS_THROW(foo(), some_exception_type);
};