TTS v4.1.0
The Tiny Test System
Loading...
Searching...
No Matches
Basic Tests Macros

Macros for performing direct true/false checks over predicate-like expressions. More...

Informations Reporting

#define TTS_PASS(...)
 Reports a passing check with a message.
#define TTS_FAIL(...)
 Reports a failing check with a message.
#define TTS_FATAL(...)
 Reports a failing check with a message and ends the run.

Predicate Checks

#define TTS_EXPECT(EXPR, ...)
 Checks that an expression is true.
#define TTS_EXPECT_NOT(EXPR, ...)
 Checks that an expression is false.
#define TTS_CONSTEXPR_EXPECT(EXPR, ...)
 Checks at compile time that a constant expression is true.
#define TTS_CONSTEXPR_EXPECT_NOT(EXPR, ...)
 Checks at compile time that a constant expression is false.

Macro Definition Documentation

◆ TTS_CONSTEXPR_EXPECT

#define TTS_CONSTEXPR_EXPECT ( EXPR,
... )

#include <tts/test/basic.hpp>

Checks at compile time that a constant expression is true.

Evaluates the expression at compile time, so it must be a constant expression, or the test does not compile. Reports the check at run time with the others, as a pass or a failure.

Parameters
EXPRConstant expression to check, converted to bool.
...REQUIRED ends the run when the check fails.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
TTS_CASE("Check that expectation can be met")
{
constexpr int a = 42, b = 69;
};

◆ TTS_CONSTEXPR_EXPECT_NOT

#define TTS_CONSTEXPR_EXPECT_NOT ( EXPR,
... )

#include <tts/test/basic.hpp>

Checks at compile time that a constant expression is false.

Evaluates the expression at compile time, so it must be a constant expression, or the test does not compile. Reports the check at run time with the others, as a pass or a failure.

Parameters
EXPRConstant expression to check, converted to bool.
...REQUIRED ends the run when the check fails.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
TTS_CASE("Check that counter-expectation can be met")
{
constexpr int a = 42, b = 69;
};

◆ TTS_EXPECT

#define TTS_EXPECT ( EXPR,
... )

#include <tts/test/basic.hpp>

Checks that an expression is true.

Parameters
EXPRExpression to check, converted to bool.
...REQUIRED ends the run when the check fails.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
TTS_CASE("Check that expectation can be met")
{
int a = 42, b = 69;
TTS_EXPECT(a < b);
TTS_EXPECT(b > a);
TTS_EXPECT(a != b);
// This test would cause the program to stop and not run the remaining tests
// TTS_EXPECT(a == b, REQUIRED);
TTS_EXPECT(a <= b);
TTS_EXPECT(b >= a);
};

◆ TTS_EXPECT_NOT

#define TTS_EXPECT_NOT ( EXPR,
... )

#include <tts/test/basic.hpp>

Checks that an expression is false.

Parameters
EXPRExpression to check, converted to bool.
...REQUIRED ends the run when the check fails.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
TTS_CASE("Check that expectation can't be met")
{
int a = 42, b = 69;
TTS_EXPECT_NOT(a == b);
// This test would cause the program to stop and not run the remaining tests
// TTS_EXPECT_NOT(a != b, REQUIRED);
TTS_EXPECT_NOT(a >= b);
};

◆ TTS_FAIL

#define TTS_FAIL ( ...)

#include <tts/engine/info.hpp>

Reports a failing check with a message.

Parameters
...A format string and its arguments, printed with the report.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
TTS_CASE("Check that forced failure fails")
{
TTS_FAIL("Forced failure!!");
TTS_PASS("This will pass though");
};

◆ TTS_FATAL

#define TTS_FATAL ( ...)

#include <tts/engine/info.hpp>

Reports a failing check with a message and ends the run.

Skips the cases left, and reports how many were skipped.

Parameters
...A format string and its arguments, printed with the report.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
TTS_CASE("Check that forced major failure fails")
{
TTS_PASS("This will pass");
TTS_FATAL("Forced major failure!!");
TTS_PASS("This won't pass");
};

◆ TTS_PASS

#define TTS_PASS ( ...)

#include <tts/engine/info.hpp>

Reports a passing check with a message.

Parameters
...A format string and its arguments, printed with the report.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
TTS_CASE("Check that forced pass passes")
{
TTS_PASS("Forced success!!");
};