Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
test-helper.hpp File Reference

A collection of frequently used helper functions to support unit testing. More...

Go to the source code of this file.

Description

A collection of frequently used helper functions to support unit testing.

Some are test data generators, some are diagnostics helpers to produce readable output. Some of these support meta programming to figure out the actual reference kind (value, lvalue, rvalue) of a template parameter instantiation. For GNU compatible compilers, we expose also the interface to the internal ABI for demangling type names.

Note
this header is included into a large number of tests.
See also
TestHelper_test
TestHelperDemangling_test

Definition in file test-helper.hpp.

#include "lib/symbol.hpp"
#include "lib/meta/trait.hpp"
#include "lib/time/timevalue.hpp"
#include "lib/test/transiently.hpp"
#include "lib/format-obj.hpp"
#include "lib/random.hpp"
#include <boost/lexical_cast.hpp>
#include <typeinfo>
#include <cstdlib>
#include <utility>
#include <limits>
#include <string>
#include <cmath>

Namespaces

namespace  lib
 Implementation namespace for support and library code.
 
namespace  lib::test
 Unit tests for the Lumiera support library.
 
namespace  lib::test::anonymous_namespace{test-helper.hpp}
 

Macros

#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
 Macro to verify that a statement indeed raises an exception.
 
#define VERIFY_FAIL(FAILURE_MSG, ERRONEOUS_STATEMENT)
 Macro to verify that a statement indeed raises a std::exception, which additionally contains some FAILURE_MSG in its description.
 
#define MARK_TEST_FUN    cout << "|" << endl << "| »"<<__FUNCTION__<<"«" <<endl;
 Macro to mark the current test function in STDOUT.
 

Classes

struct  TypeDebugger< X >
 Helper to show types involved in metaprogramming. More...
 
struct  TypeDiagnostics< X >
 
struct  TypeDiagnostics< const X >
 
struct  TypeDiagnostics< X & >
 
struct  TypeDiagnostics< X && >
 
struct  TypeDiagnostics< X const & >
 
struct  TypeDiagnostics< X const && >
 
struct  TypeDiagnostics< X * >
 
struct  TypeDiagnostics< const X * >
 
struct  TypeDiagnostics< const X *const >
 
struct  TypeDiagnostics< X *const >
 
struct  TypeDiagnostics< X *const * >
 
class  ExpectString
 Helper to produce better diagnostic messages when comparing to an expected result string. More...
 

Functions

template<typename F , typename N >
constexpr meta::enable_if< std::is_floating_point< F >, bool > roughEQ (F val, N target, F limit=ROUGH_PRECISION)
 
template<typename F >
constexpr meta::enable_if< std::is_floating_point< F >, F > ulp (F val)
 
template<typename F , typename N >
constexpr meta::enable_if< std::is_floating_point< F >, bool > epsEQ (F val, N target, uint ulps=EPSILON_ULP)
 
string showSizeof (size_t siz, string name)
 for printing sizeof().
 
template<typename T >
string showSizeof (T const *obj=0, CStr name=0)
 for printing sizeof(), possibly figuring out the type name automatically
 
template<typename T >
meta::disable_if< std::is_pointer< T >, string > showSizeof (T const &obj, CStr name=nullptr)
 
template<typename T >
string showSizeof (CStr name)
 
template<typename R >
string showRefKind ()
 helper to discern the kind of reference of the argument type
 
template<typename X >
void typeDebugger (X &&x)
 
template<typename X >
string showType ()
 diagnostic type output, including const and similar adornments
 
template<typename... TS>
string showTypes ()
 
template<typename... EMPTY>
string showVariadicTypes ()
 helper for investigating a variadic argument pack
 
template<typename XX , typename... XS>
string showVariadicTypes (XX &&x, XS &&... xs)
 
lib::time::Time randTime ()
 create a random but not insane Time value between 1s ... 10min + 500ms
 
string randStr (size_t len)
 create garbage string of given length
 
lib::test::ExpectString operator""_expect (CStr lit, size_t siz)
 

Variables

constexpr auto ROUGH_PRECISION = pow (10, -3)
 
constexpr auto EPSILON_ULP = 5
 

Macro Definition Documentation

◆ VERIFY_ERROR

#define VERIFY_ERROR (   ERROR_ID,
  ERRONEOUS_STATEMENT 
)
Value:
try \
{ \
ERRONEOUS_STATEMENT ; \
NOTREACHED("expected »%s« failure in: %s", \
#ERROR_ID, #ERRONEOUS_STATEMENT); \
} \
catch (lumiera::Error& ex) \
{ \
CHECK (ex.getID() \
== lib::test::ExpectString{LUMIERA_ERROR_##ERROR_ID} );\
lumiera_error(); \
} \
catch (...) \
{ \
CHECK (lumiera_error_peek() \
== lib::test::ExpectString{LUMIERA_ERROR_##ERROR_ID} ); \
lumiera_error(); \
}
Helper to produce better diagnostic messages when comparing to an expected result string.
Interface and Base definition for all Lumiera Exceptions.
Definition error.hpp:65
lumiera_err lumiera_error_peek(void)
Check current error state without clearing it Please avoid this function and use lumiera_error() if p...

Macro to verify that a statement indeed raises an exception.

If no exception is thrown, the #NOTREACHED macro will trigger an assertion failure. In case of exception, the lumiera_error state is checked, cleared and verified.

Definition at line 393 of file test-helper.hpp.

◆ VERIFY_FAIL

#define VERIFY_FAIL (   FAILURE_MSG,
  ERRONEOUS_STATEMENT 
)
Value:
try \
{ \
ERRONEOUS_STATEMENT ; \
NOTREACHED("expected »%s«-failure in: %s" \
, FAILURE_MSG, #ERRONEOUS_STATEMENT);\
} \
catch (std::exception& sex) \
{ \
CHECK (util::contains (sex.what(), FAILURE_MSG) \
,"expected failure with »%s« -- but got: %s" \
,FAILURE_MSG, sex.what()); \
lumiera_error(); \
} \
catch (...) \
{ \
NOTREACHED("expected »%s«-failure, " \
"yet something scary happened instead...", \
FAILURE_MSG); \
}
bool contains(MAP &map, typename MAP::key_type const &key)
shortcut for containment test on a map
Definition util.hpp:230

Macro to verify that a statement indeed raises a std::exception, which additionally contains some FAILURE_MSG in its description.

Definition at line 417 of file test-helper.hpp.

◆ MARK_TEST_FUN

#define MARK_TEST_FUN    cout << "|" << endl << "| »"<<__FUNCTION__<<"«" <<endl;

Macro to mark the current test function in STDOUT.

This can be helpful to digest a long test output dump

Definition at line 443 of file test-helper.hpp.


Class Documentation

◆ lib::test::TypeDebugger

struct lib::test::TypeDebugger
+ Collaboration diagram for TypeDebugger< X >:

Function Documentation

◆ operator""_expect()

lib::test::ExpectString operator""_expect ( CStr  lit,
size_t  siz 
)
inline

Definition at line 378 of file test-helper.hpp.