Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
property_macros.hpp File Reference

Go to the source code of this file.

Macro Definition Documentation

◆ ARENE_INTERNAL_PROPERTY2

#define ARENE_INTERNAL_PROPERTY2 ( TestSuite,
TestCase )
Value:
ARENE_INTERNAL_PROPERTY3(TestSuite, TestCase, ())
#define ARENE_INTERNAL_PROPERTY3(TestSuite, TestCase, Params)
three-argument form of ARENE_PROPERTY
Definition property_macros.hpp:38

two-argument form of ARENE_PROPERTY

Parameters
TestSuitetest suite name
TestCasetest case name

Forwards to ARENE_INTERNAL_PROPERTY3 with an empty parameter list, producing a property whose body takes no generated arguments.

◆ ARENE_INTERNAL_PROPERTY3

#define ARENE_INTERNAL_PROPERTY3 ( TestSuite,
TestCase,
Params )
Value:
struct ARENE_INTERNAL_PROPERTY_CLOSURE_NAME(TestSuite, TestCase) { \
::arene::base::testing::detail::any_prng_ref prng; \
auto operator() Params const -> void; \
}; \
TEST(TestSuite, TestCase) { \
auto const summary = ::arene::base::testing::run_property( \
::arene::base::testing::detail::property_trampoline< \
ARENE_INTERNAL_PROPERTY_CLOSURE_NAME(TestSuite, TestCase)>{}, \
::arene::base::testing::read_property_config() \
); \
if (summary.failed) { \
FAIL() << summary; \
} \
} \
auto ARENE_INTERNAL_PROPERTY_CLOSURE_NAME(TestSuite, TestCase)::operator() Params const -> void
auto run_property(Callable callable, property_config const config) -> property_summary
run a property callable against a battery of trials with generated arguments
Definition run_property.hpp:74
#define ARENE_INTERNAL_PROPERTY_CLOSURE_NAME(TestSuite, TestCase)
unique closure type name for a property test
Definition property_macros.hpp:25

three-argument form of ARENE_PROPERTY

Parameters
TestSuitetest suite name
TestCasetest case name
Paramsparenthesized parameter list for the property body

Generates the closure type, the GoogleTest/Minitest TEST registration, and the out-of-class definition stub of the property's operator(). The user's braced block that follows the macro invocation becomes the body of that operator().

◆ ARENE_INTERNAL_PROPERTY_CLOSURE_NAME

#define ARENE_INTERNAL_PROPERTY_CLOSURE_NAME ( TestSuite,
TestCase )
Value:
ARENE_CONCATENATE(ARENE_CONCATENATE(property_closure_, TestSuite), ARENE_CONCATENATE(_, TestCase))
#define ARENE_CONCATENATE(left, right)
Concatenate two tokens together, similar to ## except that arguments are replaced before concatenatio...
Definition concatenate.hpp:34

unique closure type name for a property test

Parameters
TestSuitetest suite name
TestCasetest case name
Returns
property_closure_<TestSuite>_<TestCase>

◆ ARENE_INTERNAL_PROPERTY_PICK

#define ARENE_INTERNAL_PROPERTY_PICK ( _1,
_2,
_3,
NAME,
... )
Value:
NAME

helper macro to dispatch to the correct internal property macro

Parameters
_1first positional slot (unused)
_2second positional slot (unused)
_3third positional slot (unused)
NAMEthe selected macro name to return
...any trailing tokens (ignored)

Used as an argument-count dispatcher for ARENE_PROPERTY or ARENE_TYPED_PROPERTY. The positional arguments _1, _2, _3, NAME capture tokens from the caller, and the selected NAME is returned. The variadic tail (...) absorbs any additional tokens so that the dispatch works regardless of overall argument count.

◆ ARENE_INTERNAL_TYPED_PROPERTY2

#define ARENE_INTERNAL_TYPED_PROPERTY2 ( TestSuite,
TestCase )
Value:
ARENE_INTERNAL_TYPED_PROPERTY3(TestSuite, TestCase, ())
#define ARENE_INTERNAL_TYPED_PROPERTY3(TestSuite, TestCase, Params)
three-argument form of ARENE_TYPED_PROPERTY
Definition property_macros.hpp:126

two-argument form of ARENE_TYPED_PROPERTY

Parameters
TestSuitetyped test suite name
TestCasetest case name

Forwards to ARENE_INTERNAL_TYPED_PROPERTY3 with an empty parameter list, producing a typed property whose body takes no generated arguments.

◆ ARENE_INTERNAL_TYPED_PROPERTY3

#define ARENE_INTERNAL_TYPED_PROPERTY3 ( TestSuite,
TestCase,
Params )
Value:
template <class TypeParam> \
struct ARENE_INTERNAL_PROPERTY_CLOSURE_NAME(TestSuite, TestCase) { \
::arene::base::testing::detail::any_prng_ref prng; \
auto operator() Params const -> void; \
}; \
TYPED_TEST(TestSuite, TestCase) { \
auto const summary = ::arene::base::testing::run_property( \
::arene::base::testing::detail::property_trampoline < \
ARENE_INTERNAL_PROPERTY_CLOSURE_NAME(TestSuite, TestCase) < TypeParam >> {}, \
::arene::base::testing::read_property_config() \
); \
if (summary.failed) { \
FAIL() << summary; \
} \
} \
template <class TypeParam> \
auto ARENE_INTERNAL_PROPERTY_CLOSURE_NAME(TestSuite, TestCase)<TypeParam>::operator() Params const -> void

three-argument form of ARENE_TYPED_PROPERTY

Parameters
TestSuitetyped test suite name
TestCasetest case name
Paramsparenthesized parameter list for the property body

Generates the closure type template (parameterized by the GoogleTest TypeParam), the TYPED_TEST registration, and the out-of-class definition stub of the property's operator(). The user's braced block that follows the macro invocation becomes the body of that operator(). Inside the body, TypeParam refers to the current type from the type list bound to the typed test suite.

◆ ARENE_PROP_CHECK

#define ARENE_PROP_CHECK ( Description,
Params,
... )
Value:
[] { \
struct local_proprety_closure { \
::arene::base::testing::detail::any_prng_ref prng; \
auto operator() Params const -> void __VA_ARGS__ \
}; \
return ::arene::base::testing::run_property( \
::arene::base::testing::detail::property_trampoline<local_proprety_closure>{}, \
::arene::base::testing::read_property_config() \
); \
}()
Definition accumulate.hpp:36

run an inline property check

Parameters
Descriptionstring literal describing the property. Currently unused by the expansion; reserved for future labeling and reporting.
Paramsparenthesized parameter list for the property body, e.g. (int a, int b). Use () for a property that takes no generated arguments.
...braced block forming the body of the property's operator(). The block is passed through as variadic tokens so that it may contain commas (e.g. inside initializer lists or template arguments).
Returns
proprety_summary of the run

Runs the property body repeatedly with pseudorandom arguments drawn according to arene::base::testing::read_property_config, and yields the resulting property_summary.

Unlike ARENE_PROPERTY and ARENE_TYPED_PROPERTY, this macro does not register a test case. It is intended for use inside an existing test body or other context where the caller wants direct access to the summary, for example to inspect statistics or to assert custom conditions on the outcome.

Inside the body, the identifier prng refers to a type-erased PRNG, which may be used to manually produce additional random values if needed.

Example:

auto const summary = ARENE_PROP_CHECK(
"addition commutes",
(int a, int b),
{
ARENE_PROP_ASSERT(a + b == b + a);
}
);
std::cerr << summary << "\n";

◆ ARENE_PROPERTY

#define ARENE_PROPERTY ( ...)
Value:
__VA_ARGS__, \
unused_token_to_match_ellipses \
) \
(__VA_ARGS__)
#define ARENE_INTERNAL_PROPERTY2(TestSuite, TestCase)
two-argument form of ARENE_PROPERTY
Definition property_macros.hpp:62
#define ARENE_INTERNAL_PROPERTY_PICK(_1, _2, _3, NAME,...)
helper macro to dispatch to the correct internal property macro
Definition property_macros.hpp:77

define a property-based test Arguments: test suite name, test case name, and an optional parenthesized parameter list for the property body, e.g. (int a, int b). When omitted, the body takes no generated arguments.

Expands to a TEST case whose body is executed many times by arene::base::testing::run_property, with pseudorandom arguments drawn according to arene::base::testing::read_property_config.

The macro has two forms:

ARENE_PROPERTY(TestSuite, TestCase) { /* body */ }
ARENE_PROPERTY(TestSuite, TestCase, Params) { /* body */ }
#define ARENE_PROPERTY(...)
define a property-based test Arguments: test suite name, test case name, and an optional parenthesize...
Definition property_macros.hpp:105

The first form declares a property with no generated arguments. The second form accepts a parenthesized parameter list Params that specifies the types (and optional names) of the values the framework should generate and pass into the body each iteration.

Inside the body, the identifier prng refers to a type-erased PRNG, which may be used to manually produce additional random values if needed.

Example:

ARENE_PROPERTY(Arithmetic, AddCommutes, (int a, int b)) {
ARENE_PROP_ASSERT(a + b == b + a);
}

◆ ARENE_TYPED_PROPERTY

#define ARENE_TYPED_PROPERTY ( ...)
Value:
__VA_ARGS__, \
unused_token_to_match_ellipses \
) \
(__VA_ARGS__)
#define ARENE_INTERNAL_TYPED_PROPERTY2(TestSuite, TestCase)
two-argument form of ARENE_TYPED_PROPERTY
Definition property_macros.hpp:152

define a typed property-based test Arguments: typed test suite name, test case name, and an optional parenthesized parameter list for the property body, e.g. (TypeParam a, TypeParam b). When omitted, the body takes no generated arguments.

Expands to a TYPED_TEST case whose body is executed many times by arene::base::testing::run_property, with pseudorandom arguments drawn according to arene::base::testing::read_property_config. The body is instantiated for each type in the type list bound to TestSuite.

The macro has two forms:

ARENE_TYPED_PROPERTY(TestSuite, TestCase) { /* body */ }
ARENE_TYPED_PROPERTY(TestSuite, TestCase, Params) { /* body */ }
#define ARENE_TYPED_PROPERTY(...)
define a typed property-based test Arguments: typed test suite name, test case name,...
Definition property_macros.hpp:185

The first form declares a typed property with no generated arguments. The second form accepts a parenthesized parameter list Params that specifies the types (and optional names) of the values the framework should generate and pass into the body each iteration. The identifier TypeParam is available inside Params and the body, referring to the current type under test.

Inside the body, the identifier prng refers to a type-erased PRNG, which may be used to manually produce additional random values if needed.

Example:

template <class T>
struct Arithmetic : ::testing::Test {};
using arithmetic_types = ::testing::Types<int, double>;
TYPED_TEST_SUITE(Arithmetic, arithmetic_types, );
ARENE_TYPED_PROPERTY(Arithmetic, AddCommutes, (TypeParam a, TypeParam b)) {
ARENE_PROP_ASSERT(a + b == b + a);
}