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

Macros for performing checks on types and their properties. More...

Macros

#define TTS_EXPECT_COMPILES(Symbols, Expression, ...)
 Checks that an expression on the given symbols compiles.
#define TTS_EXPECT_NOT_COMPILES(Symbols..., Expression, ...)
 Checks that an expression on the given symbols does not compile.
#define TTS_EXPR_IS(EXPR, TYPE, ...)
 Checks that an expression has the type TYPE.
#define TTS_TYPE_IS(TYPE, REF, ...)
 Checks that two types are the same.

Macro Definition Documentation

◆ TTS_EXPECT_COMPILES

#define TTS_EXPECT_COMPILES ( Symbols,
Expression,
... )

#include <tts/test/types.hpp>

Checks that an expression on the given symbols compiles.

Checks the expression in a requires expression over the symbols, so a failure to compile is reported as a failed check instead of a compiler error.

Parameters
SymbolsNames the expression uses.
ExpressionExpression to check, between braces.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
TTS_CASE("Check that expression can compile properly")
{
double d, e;
TTS_EXPECT_COMPILES(d, e, { d += 4. * e; });
};

◆ TTS_EXPECT_NOT_COMPILES

#define TTS_EXPECT_NOT_COMPILES ( Symbols...,
Expression,
... )

#include <tts/test/types.hpp>

Checks that an expression on the given symbols does not compile.

Checks the expression in a requires expression over the symbols, so a failure to compile is reported as a failed check instead of a compiler error.

Parameters
SymbolsNames the expression uses.
ExpressionExpression to check, between braces.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
TTS_CASE("Check that expression cannot compile properly")
{
double d, e;
TTS_EXPECT_NOT_COMPILES(d, e, { d.foo(e); });
};

◆ TTS_EXPR_IS

#define TTS_EXPR_IS ( EXPR,
TYPE,
... )

#include <tts/test/types.hpp>

Checks that an expression has the type TYPE.

Compares decltype(EXPR) to TYPE, so an expression that names a variable gives its declared type.

Parameters
EXPRExpression whose type is checked.
TYPEType expected.
...REQUIRED ends the run when the check fails.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
TTS_CASE("Check that expression types can be tested for equality")
{
[[maybe_unused]] double d;
TTS_EXPR_IS(&d + 5, double*);
TTS_EXPR_IS(std::move(d), double&&);
TTS_EXPR_IS(std::swap(d, d), void);
};

◆ TTS_TYPE_IS

#define TTS_TYPE_IS ( TYPE,
REF,
... )

#include <tts/test/types.hpp>

Checks that two types are the same.

Parameters
TYPEType to check.
REFType expected.
...REQUIRED ends the run when the check fails.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
#include <type_traits>
TTS_CASE("Check that types can be tested for equivalence")
{
TTS_TYPE_IS(std::add_pointer<float const>::type, float const*);
};