Skip to main content

Migrating from earlier versions

Version 6.0.0 changed the initialisation of the runner and of the top suite, and deprecated the overloaded operators, the literals, and the type wrappers, in favour of the function comparators. This page describes how to migrate the existing tests; the other changes that may break existing code are listed in the compatibility notices and, with all the details, in the release post.

From version 5.x​

The changes that most programs meet first are the following; the old names are available only with MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED (see below):

Version 5.xVersion 6.0
auto& ts = tr.initialise (argc, argv, "Main");tr.initialise (argc, argv); and auto& ts = tr.add_top_suite ("Main");
mt::runner tr{ "Main" };mt::runner tr; and tr.add_top_suite ("Main")
return tr.exit_code ();return tr.run_suites ();
tr.suite (name, function)tr.add_suite (name, function)
t.assume (...)t.require (...), which stops only the test case
mt::subtest&mt::test_case&
mt::static_suite& in the function of a suitemt::suite&

Deprecated operators, literals, and wrappers​

The overloaded operators of the operators namespace, the literals of the literals namespace, the to_* type wrappers, to_t<T>, and the approx (value, epsilon) wrapper are deprecated since 6.0.0, and will be removed in a future release.

They are available only when the macro MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED is defined, for the application and for the library sources, usually in micro-os-plus/micro-test-plus-defines.h (see Configuration). When it is defined, the compiler reports their use. Without it, a program that uses them does not compile, so define the macro first, to migrate the tests step by step, and remove it when the last use is gone.

The function comparators provide the same checks and the same reports, with plain values, so that the constants do not need a literal suffix and the expressions do not need to be cast:

DeprecatedUse
x == 42_i, mt::to_i{ x } == 42mt::eq (x, 42)
x != 42_imt::ne (x, 42)
x < 42_i, x <= 42_imt::lt (x, 42), mt::le (x, 42)
x > 42_i, x >= 42_imt::gt (x, 42), mt::ge (x, 42)
x == 1.5_d, mt::to_d{ 1.5 } == xmt::approx (x, 1.5, 0.1), or mt::eq (x, 1.5) for an exact comparison
mt::eq (x, mt::approx (1.5, 0.01))mt::approx (x, 1.5, 0.01)
a and b, a or b, not amt::all_of (a, b), mt::any_of (a, b), mt::negate (a)
"flag"_b == flagt.expect (flag) << "flag"
mt::to_t<app_type>{ x } == ymt::eq (x, y), with an operator<< for the type
warning

The overloaded and and or operators evaluate both operands before the check, so they do not short-circuit like the built-in ones; p != nullptr and p->x == 1_i dereferences a null pointer.

The floating-point literals and wrappers compare with a tolerance of one unit of the last decimal written (0.1 for 1.5_d), derived from the digits of the value. This is not always what the digits suggest: the tolerance of a whole value is 0.1, and the comparison depends on which operand is wrapped. With mt::approx (lhs, rhs, epsilon) the tolerance is explicit, and the same for both operands.

Refer to the Operators and Literals and Wrappers reference pages.