30 #ifndef LIB_TEST_TEST_HELPER_H 31 #define LIB_TEST_TEST_HELPER_H 41 #include <boost/lexical_cast.hpp> 59 constexpr
auto ROUGH_PRECISION = pow (10, -3);
60 constexpr
auto EPSILON_ULP = 5;
63 template<
typename F,
typename N>
64 constexpr
inline meta::enable_if< std::is_floating_point<F>,
66 roughEQ (F val, N target, F limit =ROUGH_PRECISION)
69 return abs (val - target) < limit * abs(target);
74 constexpr
inline meta::enable_if< std::is_floating_point<F>,
79 const int exp = val < std::numeric_limits<F>::min()
80 ? std::numeric_limits<F>::min_exponent - 1
82 auto scaledUlp = std::ldexp (std::numeric_limits<F>::epsilon(), exp);
83 ENSURE (F(0) < scaledUlp);
87 template<
typename F,
typename N>
88 constexpr
inline meta::enable_if< std::is_floating_point<F>,
90 epsEQ (F val, N target, uint ulps =EPSILON_ULP)
92 return abs (val - target) < ulps * ulp<F> (target);
109 return showSizeof (obj?
sizeof(*obj) :
sizeof(T),
114 inline meta::disable_if<std::is_pointer<T>,
125 return showSizeof<T> (
nullptr,
name);
135 return std::is_lvalue_reference<R>::value?
"REF" 136 : std::is_rvalue_reference<R>::value?
"MOV" 151 static_assert (not
sizeof(
X),
"### Type Debugging ###");
158 static_assert (not
sizeof(
X),
"### Type Debugging ###");
171 static constexpr
auto prefix =
"";
172 static constexpr
auto postfix =
"";
178 static constexpr
auto prefix =
"const ";
179 static constexpr
auto postfix =
"";
185 static constexpr
auto prefix =
"";
186 static constexpr
auto postfix =
"&";
192 static constexpr
auto prefix =
"";
193 static constexpr
auto postfix =
" &&";
199 static constexpr
auto prefix =
"";
200 static constexpr
auto postfix =
" const&";
206 static constexpr
auto prefix =
"const ";
207 static constexpr
auto postfix =
" &&";
213 static constexpr
auto prefix =
"";
214 static constexpr
auto postfix =
" *";
220 static constexpr
auto prefix =
"const ";
221 static constexpr
auto postfix =
" *";
227 static constexpr
auto prefix =
"const ";
228 static constexpr
auto postfix =
" * const";
234 static constexpr
auto prefix =
"";
235 static constexpr
auto postfix =
" * const";
241 static constexpr
auto prefix =
"";
242 static constexpr
auto postfix =
" * const *";
258 using Case = TypeDiagnostics<X>;
259 using Type =
typename Case::Type;
262 + meta::humanReadableTypeID (
typeid(Type).
name())
266 template<
typename...TS>
270 return "<| " + ((showType<TS>()+
", ") + ... +
"|>");
282 template<
typename... EMPTY>
289 template<
typename XX,
typename... XS>
294 + util::toString (1 +
sizeof...(xs))
295 +
" -- Type: " + showType<XX&&>()
296 +
" \tAdr" + util::showAdr (x)
330 using std::string::string;
337 return expected.
verify (actual);
345 return expected.
verify (actual);
354 bool verify (std::string
const& actual)
const;
372 operator""_expect (
const char* lit,
size_t siz)
387 #define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT) \ 390 ERRONEOUS_STATEMENT ; \ 391 NOTREACHED("expected »%s« failure in: %s", \ 392 #ERROR_ID, #ERRONEOUS_STATEMENT); \ 394 catch (lumiera::Error& ex) \ 397 == lib::test::ExpectString{LUMIERA_ERROR_##ERROR_ID} );\ 402 CHECK (lumiera_error_peek() \ 403 == lib::test::ExpectString{LUMIERA_ERROR_##ERROR_ID} ); \ 411 #define VERIFY_FAIL(FAILURE_MSG, ERRONEOUS_STATEMENT) \ 414 ERRONEOUS_STATEMENT ; \ 415 NOTREACHED("expected »%s«-failure in: %s" \ 416 , FAILURE_MSG, #ERRONEOUS_STATEMENT);\ 418 catch (std::exception& sex) \ 420 CHECK (util::contains (sex.what(), FAILURE_MSG) \ 421 ,"expected failure with »%s« -- but got: %s" \ 422 ,FAILURE_MSG, sex.what()); \ 427 NOTREACHED("expected »%s«-failure, " \ 428 "yet something scary happened instead...", \ 437 #define MARK_TEST_FUN \ 438 cout << "|" << endl << "| »"<<__FUNCTION__<<"«" <<endl;
Helper to produce better diagnostic messages when comparing to an expected result string...
bool verify(std::string const &actual) const
inline string literal This is a marker type to indicate that
int rani(uint bound=_iBOUND())
bool operator==(PtrDerefIter< I1 > const &il, PtrDerefIter< I2 > const &ir)
Supporting equality comparisons...
string showVariadicTypes()
helper for investigating a variadic argument pack
string showSizeof(size_t siz, string name)
for printing sizeof().
Implementation namespace for support and library code.
string randStr(size_t len)
create garbage string of given length
Lumiera's internal time value datatype.
std::string operator+(std::string str, Literal const &sym)
string concatenation
Marker types to indicate a literal string and a Symbol.
Test helper to perform temporary manipulations within a test scope.
Helpers for type detection, type rewriting and metaprogramming.
string showType()
diagnostic type output, including const and similar adornments
string showRefKind()
helper to discern the kind of reference of the argument type
Generating (pseudo) random numbers with controlled seed.
lib::time::Time randTime()
create a random but not insane Time value between 1s ...
a family of time value like entities and their relationships.
Helper to show types involved in metaprogramming.
failsafe invocation of custom string conversion.