TTS v3.0.0
The Tiny Test System
 
Loading...
Searching...
No Matches
Tests definition macros

Macros for defining tests scenarios. More...

Scenarios Definitions

#define TTS_CASE(ID)
 Introduces a new test scenario and registers it into the current test driver.
 
#define TTS_CASE_TPL(ID, ...)
 Introduces a template test case and registers it into the current test driver.
 
#define TTS_CASE_WITH(ID, TYPES, ...)
 Introduces a template test case providing dynamically generated data to the test code.
 

Scoped scenarios

#define TTS_WHEN(STORY)
 Start a block of scoped environment.
 
#define TTS_AND_THEN(MESSAGE)
 Add a scoped tests to current scoped environment.
 

Macro Definition Documentation

◆ TTS_AND_THEN

#define TTS_AND_THEN (   MESSAGE)

#include <tts/test/when.hpp>

Add a scoped tests to current scoped environment.

Compared to regular local scope, whenever a scoped test is run, the data defined in the enclosing TTS_WHEN are re-initialized, thus serving as a setup/tear-down system.

See also
TTS_WHEN

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
#include <iostream>
TTS_CASE("Check test with sub-test") {TTS_WHEN("We start some sub-test") {int i = 99;
TTS_AND_THEN("We increment a variable")
{
std::cout << ">> Sub-test 1: i = " << i << "\n";
TTS_EQUAL(i, 99);
i++;
TTS_EQUAL(i, 100);
}
TTS_AND_THEN("We decrement a variable")
{
std::cout << ">> Sub-test 2: i = " << i << "\n";
TTS_EQUAL(i, 99);
i--;
TTS_EQUAL(i, 98);
}
}
}
;
#define TTS_EQUAL(LHS, RHS,...)
Performs equality comparison between two expressions.
Definition relation.hpp:134
#define TTS_AND_THEN(MESSAGE)
Add a scoped tests to current scoped environment.
Definition when.hpp:112
#define TTS_WHEN(STORY)
Start a block of scoped environment.
Definition when.hpp:73
#define TTS_CASE(ID)
Introduces a new test scenario and registers it into the current test driver.
Definition case.hpp:139

◆ TTS_CASE

#define TTS_CASE (   ID)

#include <tts/engine/case.hpp>

Introduces a new test scenario and registers it into the current test driver.

The code block following TTS_CASE contains user-defined code for a given test case. Test cases performing no actual tests will be reported as invalid.

Parameters
IDA literal string describing the scenario intents.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
TTS_CASE("Check basic arithmetic") { TTS_EQUAL(2 + 2, 4); };

◆ TTS_CASE_TPL

#define TTS_CASE_TPL (   ID,
  ... 
)

#include <tts/engine/case.hpp>

Introduces a template test case and registers it into the current test driver.

The code block following TTS_CASE contains user-defined code for a given test case. Those tests are parametrized by a template type of your choice passed as lambda function parameters of the template type tts::type and instantiated for each type in the types list.

Such types list can be provided as:

  • a variadic list of types separated by commas
  • an instance of the tts::types template class
  • an instance of a Type Generator, ie a type exposing a public types_list type definition

Test cases performing no actual tests will be reported as invalid.

Parameters
IDA literal string describing the scenario intents.
...Lists of types to generate the test case from.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
#include <array>
TTS_CASE_TPL("Check types using variadic list", char, short, int, double, void*)<typename T>(
{
TTS_GREATER_EQUAL(sizeof(T), 1UL);
};
TTS_CASE_TPL("Check types using a types list", tts::types<float, double>)<typename T>(tts::type<T>)
{
TTS_EQUAL(1 / T {2}, T {0.5});
};
// A Types Generator is any type exposing a types_list internal type
// In this example we use such a type to generate the list of types:
//
// tts::types<std::array<std::byte,1>,...,std::array<std::byte,N>>>;
template<int N, typename Indexes = std::make_index_sequence<N>> struct sizes;
template<int N, std::size_t... I> struct sizes<N, std::index_sequence<I...>>
{
};
TTS_CASE_TPL("Check types using a types list generator", sizes<5>)<typename T>(tts::type<T>)
{
T x;
TTS_EQUAL(sizeof(x), x.size());
};
#define TTS_GREATER_EQUAL(LHS, RHS,...)
Performs greater-or-equal-than comparison between two expressions.
Definition relation.hpp:239
#define TTS_CASE_TPL(ID,...)
Introduces a template test case and registers it into the current test driver.
Definition case.hpp:170
Encapsulates a single type into a reusable type object.
Definition types.hpp:112
Encapsulates a variadic list of types into a reusable object.
Definition types.hpp:25

◆ TTS_CASE_WITH

#define TTS_CASE_WITH (   ID,
  TYPES,
  ... 
)

#include <tts/engine/case.hpp>

Introduces a template test case providing dynamically generated data to the test code.

The following code block will contain tests parametrized by a template type of your choice passed as lambda function parameters and generated for each type in the types list.

Such types list can be provided as:

  • a parenthesised list of types separated by comma.
  • an instance of the tts::types template class.
  • an instance of a Type Generator, ie a type exposing a public types_list type definition

Test cases performing no actual tests will be reported as invalid.

Parameters
IDA literal string describing the scenario intents.
TYPESLists of types to generate the test case from.
...Lists of generator function

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
TTS_CASE_WITH("Check behavior for scalar types",
tts::value {37},
tts::between {0, 100},
tts::randoms {0., 10.})
(auto v, auto b, auto const& r)
{
TTS_EQUAL(v, 37);
TTS_LESS_EQUAL(b, 100);
};
#define TTS_LESS_EQUAL(LHS, RHS,...)
Performs less-or-equal-than comparison between two expressions.
Definition relation.hpp:218
#define TTS_CASE_WITH(ID, TYPES,...)
Introduces a template test case providing dynamically generated data to the test code.
Definition case.hpp:201
Defines a data generator that produce values between two bounds.
Definition generator.hpp:244
Random generator between two bounds using realistic_distribution.
Definition generator.hpp:281
Defines a data generator that always return the same value.
Definition generator.hpp:137

◆ TTS_WHEN

#define TTS_WHEN (   STORY)

#include <tts/test/when.hpp>

Start a block of scoped environment.

Code in a scoped environment can contain:

  • Normal expressions.
  • scoped tests introduced by TTS_AND_THEN.
See also
TTS_AND_THEN

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
#include <iostream>
TTS_CASE("Check test with sub-test") {TTS_WHEN("We start some sub-test") {int i = 99;
TTS_AND_THEN("We increment a variable")
{
std::cout << ">> Sub-test 1: i = " << i << "\n";
TTS_EQUAL(i, 99);
i++;
TTS_EQUAL(i, 100);
}
TTS_AND_THEN("We decrement a variable")
{
std::cout << ">> Sub-test 2: i = " << i << "\n";
TTS_EQUAL(i, 99);
i--;
TTS_EQUAL(i, 98);
}
}
}
;