user defined literal for expected result strings.
user defined literal for expected result strings.On equality comparison to any other string convertible object, the difference to this expected string is printed to STDERR
#ifndef LIB_TEST_TEST_HELPER_H
#define LIB_TEST_TEST_HELPER_H
#include <boost/lexical_cast.hpp>
#include <typeinfo>
#include <cstdlib>
#include <utility>
#include <limits>
#include <string>
#include <cmath>
using std::string;
template<typename F, typename N>
bool >
{
REQUIRE (0 < limit);
return abs (val - target) < limit * abs(target);
}
template<typename F>
F >
{
val = fabs (val);
const int exp = val < std::numeric_limits<F>::min()
? std::numeric_limits<F>::min_exponent - 1
: std::ilogb (val);
auto scaledUlp = std::ldexp (std::numeric_limits<F>::epsilon(), exp);
ENSURE (F(0) < scaledUlp);
return scaledUlp;
}
template<typename F, typename N>
bool >
{
return abs (val - target) < ulps * ulp<F> (target);
}
string
showSizeof (size_t siz, string name);
template<typename T>
inline string
showSizeof (T
const* obj =0,
CStr name =0)
{
return showSizeof (obj? sizeof(*obj) : sizeof(T),
name? name : util::typeStr(obj));
}
template<typename T>
string >
showSizeof (T
const& obj,
CStr name =
nullptr)
{
return showSizeof (&obj, name);
}
template<typename T>
inline string
{
return showSizeof<T> (nullptr, name);
}
template<typename R>
string
{
return std::is_lvalue_reference<R>::value? "REF"
: std::is_rvalue_reference<R>::value? "MOV"
: "VAL";
}
template<typename X>
struct TypeDebugger
{
static_assert (not sizeof(X), "### Type Debugging ###");
};
template<typename X>
void
{
static_assert (not sizeof(X), "### Type Debugging ###");
}
namespace {
template<typename X>
struct TypeDiagnostics
{
static constexpr auto prefix = "";
static constexpr auto postfix = "";
};
template<typename X>
struct TypeDiagnostics<const X>
{
static constexpr auto prefix = "const ";
static constexpr auto postfix = "";
};
template<typename X>
struct TypeDiagnostics<X&>
{
static constexpr auto prefix = "";
static constexpr auto postfix = "&";
};
template<typename X>
struct TypeDiagnostics<X&&>
{
static constexpr auto prefix = "";
static constexpr auto postfix = " &&";
};
template<typename X>
struct TypeDiagnostics<X const&>
{
static constexpr auto prefix = "";
static constexpr auto postfix = " const&";
};
template<typename X>
struct TypeDiagnostics<X const&&>
{
static constexpr auto prefix = "const ";
static constexpr auto postfix = " &&";
};
template<typename X>
struct TypeDiagnostics<X *>
{
static constexpr auto prefix = "";
static constexpr auto postfix = " *";
};
template<typename X>
struct TypeDiagnostics<const X *>
{
static constexpr auto prefix = "const ";
static constexpr auto postfix = " *";
};
template<typename X>
struct TypeDiagnostics<const X * const>
{
static constexpr auto prefix = "const ";
static constexpr auto postfix = " * const";
};
template<typename X>
struct TypeDiagnostics<X * const>
{
static constexpr auto prefix = "";
static constexpr auto postfix = " * const";
};
template<typename X>
struct TypeDiagnostics<X * const *>
{
static constexpr auto prefix = "";
static constexpr auto postfix = " * const *";
};
}
template<typename X>
inline string
{
using Case = TypeDiagnostics<X>;
return Case::prefix
+ Case::postfix;
}
template<typename...TS>
string
{
return "<| " + ((showType<TS>()+", ") + ... + "|>");
}
template<typename... EMPTY>
inline string
{
return " :.";
}
template<typename XX, typename... XS>
inline string
{
return " :---#"
+ " -- Type: " + showType<XX&&>()
+ "\n"
}
randTime ()
{
}
string randStr (size_t len);
class ExpectString
: public std::string
{
public:
using std::string::string;
ExpectString(std::string && s) : std::string{std::move(s)}{ }
ExpectString(std::string const& s) : std::string{s} { }
template<typename X>
friend bool
operator== (X
const& x, ExpectString
const& expected)
{
return expected.verify (actual);
}
template<typename X>
friend bool
operator== (ExpectString
const& expected, X
const& x)
{
return expected.verify (actual);
}
friend ExpectString
operator+ (std::string&& l, ExpectString&& r)
{
return ExpectString{(l+r).c_str()};
}
bool verify (std::string
const& actual)
const;
};
}}
operator""_expect (
CStr lit,
size_t siz)
{
}
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT) \
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(); \
}
#define VERIFY_FAIL(FAILURE_MSG, ERRONEOUS_STATEMENT) \
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); \
}
#define MARK_TEST_FUN \
cout << "|" << endl << "| »"<<__FUNCTION__<<"«" <<endl;
#endif
Helper to produce better diagnostic messages when comparing to an expected result string.
friend bool operator==(X const &x, ExpectString const &expected)
bool verify(std::string const &actual) const
friend ExpectString operator+(std::string &&l, ExpectString &&r)
Lumiera's internal time value datatype.
string showType()
diagnostic type output, including const and similar adornments
constexpr auto EPSILON_ULP
constexpr auto ROUGH_PRECISION
constexpr meta::enable_if< std::is_floating_point< F >, F > ulp(F val)
string showVariadicTypes()
helper for investigating a variadic argument pack
string showRefKind()
helper to discern the kind of reference of the argument type
constexpr meta::enable_if< std::is_floating_point< F >, bool > epsEQ(F val, N target, uint ulps=EPSILON_ULP)
Implementation namespace for support and library code.
int rani(uint bound=_iBOUND())
Test runner and basic definitions for tests.
ostream & showAdr(ostream &stream, void const *addr)
preconfigured format for pretty-printing of addresses
std::string toString(TY const &val) noexcept
get some string representation of any object, reliably.
Generating (pseudo) random numbers with controlled seed.
static std::string invoke(X const &x) noexcept
Marker types to indicate a literal string and a Symbol.
a family of time value like entities and their relationships.
Helpers for type detection, type rewriting and metaprogramming.
Test helper to perform temporary manipulations within a test scope.