30#ifndef LIB_TEST_TEST_HELPER_H
31#define LIB_TEST_TEST_HELPER_H
41#include <boost/lexical_cast.hpp>
64 template<
typename F,
typename N>
70 return abs (val - target) < limit * abs(target);
80 const int exp = val < std::numeric_limits<F>::min()
81 ? std::numeric_limits<F>::min_exponent - 1
83 auto scaledUlp = std::ldexp (std::numeric_limits<F>::epsilon(), exp);
84 ENSURE (F(0) < scaledUlp);
88 template<
typename F,
typename N>
93 return abs (val - target) < ulps * ulp<F> (target);
100 showSizeof (
size_t siz,
string name);
110 return showSizeof (obj?
sizeof(*obj) :
sizeof(T),
111 name? name : util::typeStr(obj));
126 return showSizeof<T> (
nullptr, name);
136 return std::is_lvalue_reference<R>::value?
"REF"
137 : std::is_rvalue_reference<R>::value?
"MOV"
152 static_assert (not
sizeof(
X),
"### Type Debugging ###");
159 static_assert (not
sizeof(
X),
"### Type Debugging ###");
172 static constexpr auto prefix =
"";
173 static constexpr auto postfix =
"";
179 static constexpr auto prefix =
"const ";
180 static constexpr auto postfix =
"";
186 static constexpr auto prefix =
"";
187 static constexpr auto postfix =
"&";
193 static constexpr auto prefix =
"";
194 static constexpr auto postfix =
" &&";
200 static constexpr auto prefix =
"";
201 static constexpr auto postfix =
" const&";
207 static constexpr auto prefix =
"const ";
208 static constexpr auto postfix =
" &&";
214 static constexpr auto prefix =
"";
215 static constexpr auto postfix =
" *";
221 static constexpr auto prefix =
"const ";
222 static constexpr auto postfix =
" *";
228 static constexpr auto prefix =
"const ";
229 static constexpr auto postfix =
" * const";
235 static constexpr auto prefix =
"";
236 static constexpr auto postfix =
" * const";
242 static constexpr auto prefix =
"";
243 static constexpr auto postfix =
" * const *";
259 using Case = TypeDiagnostics<X>;
260 using Type = Case::Type;
267 template<
typename...TS>
271 return "<| " + ((showType<TS>()+
", ") + ... +
"|>");
283 template<
typename... EMPTY>
290 template<
typename XX,
typename... XS>
296 +
" -- Type: " + showType<XX&&>()
317 string randStr (
size_t len);
332 using std::string::string;
343 return expected.
verify (actual);
351 return expected.
verify (actual);
360 bool verify (std::string
const& actual)
const;
378operator""_expect (
CStr lit,
size_t siz)
393#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT) \
396 ERRONEOUS_STATEMENT ; \
397 NOTREACHED("expected »%s« failure in: %s", \
398 #ERROR_ID, #ERRONEOUS_STATEMENT); \
400 catch (lumiera::Error& ex) \
403 == lib::test::ExpectString{LUMIERA_ERROR_##ERROR_ID} );\
408 CHECK (lumiera_error_peek() \
409 == lib::test::ExpectString{LUMIERA_ERROR_##ERROR_ID} ); \
417#define VERIFY_FAIL(FAILURE_MSG, ERRONEOUS_STATEMENT) \
420 ERRONEOUS_STATEMENT ; \
421 NOTREACHED("expected »%s«-failure in: %s" \
422 , FAILURE_MSG, #ERRONEOUS_STATEMENT);\
424 catch (std::exception& sex) \
426 CHECK (util::contains (sex.what(), FAILURE_MSG) \
427 ,"expected failure with »%s« -- but got: %s" \
428 ,FAILURE_MSG, sex.what()); \
433 NOTREACHED("expected »%s«-failure, " \
434 "yet something scary happened instead...", \
443#define MARK_TEST_FUN \
444 cout << "|" << endl << "| »"<<__FUNCTION__<<"«" <<endl;
Helper to produce better diagnostic messages when comparing to an expected result string.
ExpectString(std::string const &s)
ExpectString(std::string &&s)
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 showSizeof(size_t siz, string name)
for printing sizeof().
string showType()
diagnostic type output, including const and similar adornments
lib::time::Time randTime()
create a random but not insane Time value between 1s ... 10min + 500ms
constexpr auto EPSILON_ULP
constexpr auto ROUGH_PRECISION
constexpr meta::enable_if< std::is_floating_point< F >, F > ulp(F val)
constexpr meta::enable_if< std::is_floating_point< F >, bool > roughEQ(F val, N target, F limit=ROUGH_PRECISION)
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)
Helper to show types involved in metaprogramming.
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.