39 #ifndef LIB_TEST_TEST_HELPER_H 40 #define LIB_TEST_TEST_HELPER_H 49 #include <boost/lexical_cast.hpp> 67 constexpr
auto ROUGH_PRECISION = pow (10, -3);
68 constexpr
auto EPSILON_ULP = 5;
71 template<
typename F,
typename N>
72 constexpr
inline meta::enable_if< std::is_floating_point<F>,
74 roughEQ (F val, N target, F limit =ROUGH_PRECISION)
77 return abs (val/target - F(1)) < limit;
82 constexpr
inline meta::enable_if< std::is_floating_point<F>,
87 const int exp = val < std::numeric_limits<F>::min()
88 ? std::numeric_limits<F>::min_exponent - 1
90 auto scaledUlp = std::ldexp (std::numeric_limits<F>::epsilon(), exp);
91 ENSURE (F(0) < scaledUlp);
95 template<
typename F,
typename N>
96 constexpr
inline meta::enable_if< std::is_floating_point<F>,
98 epsEQ (F val, N target, uint ulps =EPSILON_ULP)
100 return abs (val - target) < ulps * ulp<F> (target);
117 return showSizeof (obj?
sizeof(*obj) :
sizeof(T),
122 inline meta::disable_if<std::is_pointer<T>,
133 return showSizeof<T> (
nullptr,
name);
143 return std::is_lvalue_reference<R>::value?
"REF" 144 : std::is_rvalue_reference<R>::value?
"MOV" 155 template<
typename... EMPTY>
162 template<
typename X,
typename... XS>
167 + boost::lexical_cast<
string>(1 +
sizeof...(xs))
168 +
" -- Type: " + util::typeStr(x)
169 +
" " + showRefKind<X>()
170 +
" Address* " + boost::lexical_cast<string>(&x)
186 static_assert (not
sizeof(
X),
"### Type Debugging ###");
193 static_assert (not
sizeof(
X),
"### Type Debugging ###");
204 static constexpr
auto prefix =
"";
205 static constexpr
auto postfix =
"";
211 static constexpr
auto prefix =
"const ";
212 static constexpr
auto postfix =
"";
218 static constexpr
auto prefix =
"";
219 static constexpr
auto postfix =
"&";
225 static constexpr
auto prefix =
"";
226 static constexpr
auto postfix =
" &&";
232 static constexpr
auto prefix =
"";
233 static constexpr
auto postfix =
" const&";
239 static constexpr
auto prefix =
"const ";
240 static constexpr
auto postfix =
" &&";
246 static constexpr
auto prefix =
"";
247 static constexpr
auto postfix =
" *";
253 static constexpr
auto prefix =
"const ";
254 static constexpr
auto postfix =
" *";
260 static constexpr
auto prefix =
"const ";
261 static constexpr
auto postfix =
" * const";
267 static constexpr
auto prefix =
"";
268 static constexpr
auto postfix =
" * const";
274 static constexpr
auto prefix =
"";
275 static constexpr
auto postfix =
" * const *";
291 using Case = TypeDiagnostics<X>;
292 using Type =
typename Case::Type;
295 + meta::humanReadableTypeID (
typeid(Type).
name())
326 using std::string::string;
333 return expected.
verify (actual);
341 return expected.
verify (actual);
350 bool verify (std::string
const& actual)
const;
368 operator""_expect (
const char* lit,
size_t siz)
383 #define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT) \ 386 ERRONEOUS_STATEMENT ; \ 387 NOTREACHED("expected »%s« failure in: %s", \ 388 #ERROR_ID, #ERRONEOUS_STATEMENT); \ 390 catch (lumiera::Error& ex) \ 393 == lib::test::ExpectString{LUMIERA_ERROR_##ERROR_ID} );\ 398 CHECK (lumiera_error_peek() \ 399 == lib::test::ExpectString{LUMIERA_ERROR_##ERROR_ID} ); \ 407 #define VERIFY_FAIL(FAILURE_MSG, ERRONEOUS_STATEMENT) \ 410 ERRONEOUS_STATEMENT ; \ 411 NOTREACHED("expected »%s«-failure in: %s" \ 412 , FAILURE_MSG, #ERRONEOUS_STATEMENT);\ 414 catch (std::exception& sex) \ 416 CHECK (util::contains (sex.what(), FAILURE_MSG) \ 417 ,"expected failure with »%s« -- but got: %s" \ 418 ,FAILURE_MSG, sex.what()); \ 423 NOTREACHED("expected »%s«-failure, " \ 424 "yet something scary happened instead...", \ 433 #define MARK_TEST_FUN \ 434 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
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
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.