36 #define TESTGRP(name) \
37 typedef test_group<name ## _shar> tg; \
38 typedef tg::object to; \
39 tg name ## _tg (#name);
45 #define WIBBLE_TESTS_ALWAYS_THROWS __attribute__ ((noreturn))
60 Location(
const char* file,
int line,
const char* args);
62 Location(
const Location& parent,
const char* file,
int line,
const char* args);
65 std::string
locstr()
const;
66 std::string
msg(
const std::string m)
const;
93 #define WIBBLE_TEST_LOCPRM wibble::tests::Location wibble_test_location
97 #define WIBBLE_TEST_INFO(name) \
98 wibble::tests::LocationInfo wibble_test_location_info; \
99 wibble::tests::LocationInfo& name = wibble_test_location_info
101 #define ensure(x) wibble::tests::impl_ensure(wibble::tests::Location(__FILE__, __LINE__, #x), (x))
102 #define inner_ensure(x) wibble::tests::impl_ensure(wibble::tests::Location(loc, __FILE__, __LINE__, #x), (x))
105 #define ensure_equals(x, y) wibble::tests::impl_ensure_equals(wibble::tests::Location(__FILE__, __LINE__, #x " == " #y), (x), (y))
106 #define inner_ensure_equals(x, y) wibble::tests::impl_ensure_equals(wibble::tests::Location(loc, __FILE__, __LINE__, #x " == " #y), (x), (y))
108 template <
class Actual,
class Expected>
111 if( expected != actual )
113 std::stringstream ss;
114 ss <<
"expected '" << expected <<
"' actual '" << actual <<
"'";
119 #define ensure_similar(x, y, prec) wibble::tests::impl_ensure_similar(wibble::tests::Location(__FILE__, __LINE__, #x " == " #y), (x), (y), (prec))
120 #define inner_ensure_similar(x, y, prec) wibble::tests::impl_ensure_similar(wibble::tests::Location(loc, __FILE__, __LINE__, #x " == " #y), (x), (y), (prec))
122 template <
class Actual,
class Expected,
class Precision>
125 if( actual < expected - precision || expected + precision < actual )
127 std::stringstream ss;
128 ss <<
"expected '" << expected <<
"' actual '" << actual <<
"'";
133 #define ensure_contains(x, y) wibble::tests::impl_ensure_contains(wibble::tests::Location(__FILE__, __LINE__, #x " == " #y), (x), (y))
134 #define inner_ensure_contains(x, y) wibblwibblempl_ensure_contains(wibble::tests::Location(loc, __FILE__, __LINE__, #x " == " #y), (x), (y))
137 #define ensure_not_contains(x, y) wibble::tests::impl_ensure_not_contains(wibble::tests::Location(__FILE__, __LINE__, #x " == " #y), (x), (y))
138 #define inner_ensure_not_contains(x, y) wibble::tests::impl_ensure_not_contains(wibble::tests::Location(loc, __FILE__, __LINE__, #x " == " #y), (x), (y))
156 wibble_test_location.
fail_test(
"actual value is false");
159 wibble_test_location.
fail_test(
"actual value is true");
164 template<
typename A,
typename E>
179 std::stringstream ss;
180 ss <<
"value '" <<
actual <<
"' is different than the expected '" <<
expected <<
"'";
181 wibble_test_location.
fail_test(ss.str());
184 std::stringstream ss;
185 ss <<
"value '" <<
actual <<
"' is not different than the expected '" <<
expected <<
"'";
186 wibble_test_location.
fail_test(ss.str());
191 template<
typename A,
typename E>
206 std::stringstream ss;
207 ss <<
"value '" <<
actual <<
"' is not less than the expected '" <<
expected <<
"'";
208 wibble_test_location.
fail_test(ss.str());
211 std::stringstream ss;
212 ss <<
"value '" <<
actual <<
"' is less than the expected '" <<
expected <<
"'";
213 wibble_test_location.
fail_test(ss.str());
218 template<
typename A,
typename E>
232 std::stringstream ss;
233 ss <<
"value '" <<
actual <<
"' is not less than or equals to the expected '" <<
expected <<
"'";
234 wibble_test_location.
fail_test(ss.str());
237 std::stringstream ss;
238 ss <<
"value '" <<
actual <<
"' is less than or equals to the expected '" <<
expected <<
"'";
239 wibble_test_location.
fail_test(ss.str());
244 template<
typename A,
typename E>
258 std::stringstream ss;
259 ss <<
"value '" <<
actual <<
"' is not greater than the expected '" <<
expected <<
"'";
260 wibble_test_location.
fail_test(ss.str());
263 std::stringstream ss;
264 ss <<
"value '" <<
actual <<
"' is greater than the expected '" <<
expected <<
"'";
265 wibble_test_location.
fail_test(ss.str());
270 template<
typename A,
typename E>
284 std::stringstream ss;
285 ss <<
"value '" <<
actual <<
"' is not greater than or equals to the expected '" <<
expected <<
"'";
286 wibble_test_location.
fail_test(ss.str());
289 std::stringstream ss;
290 ss <<
"value '" <<
actual <<
"' is greater than or equals to the expected '" <<
expected <<
"'";
291 wibble_test_location.
fail_test(ss.str());
400 expr.check(wibble_test_location);
404 #define wibble_test_runner(loc, func, ...) \
406 func(loc, ##__VA_ARGS__); \
407 } catch (tut::failure) { \
409 } catch (std::exception& e) { \
410 loc.fail_test(e.what()); \
413 #define wrunchecked(func) \
416 } catch (tut::failure) { \
418 } catch (std::exception& e) { \
419 wibble_test_location.fail_test(wibble_test_location_info, __FILE__, __LINE__, #func, e.what()); \
423 #define wruntest(test, ...) wibble_test_runner(wibble_test_location.nest(wibble_test_location_info, __FILE__, __LINE__, "function: " #test "(" #__VA_ARGS__ ")"), test, ##__VA_ARGS__)
425 #define wassert(...) wibble_test_runner(wibble_test_location.nest(wibble_test_location_info, __FILE__, __LINE__, #__VA_ARGS__), _wassert, ##__VA_ARGS__)