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;
69 void backtrace(std::ostream& out)
const;
89 std::ostream& operator()();
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)) 147 TestBool(
const A& actual,
bool inverted=
false) : actual(actual), inverted(inverted) {}
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>
170 TestEquals(
const A& actual,
const E& expected,
bool inverted=
false)
171 : actual(actual), expected(expected), inverted(inverted) {}
178 if (actual == expected)
return;
179 std::stringstream ss;
180 ss <<
"value '" << actual <<
"' is different than the expected '" << expected <<
"'";
181 wibble_test_location.
fail_test(ss.str());
183 if (actual != expected)
return;
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>
197 TestIsLt(
const A& actual,
const E& expected,
bool inverted=
false)
198 : actual(actual), expected(expected), inverted(inverted) {}
205 if (actual < expected)
return;
206 std::stringstream ss;
207 ss <<
"value '" << actual <<
"' is not less than the expected '" << expected <<
"'";
208 wibble_test_location.
fail_test(ss.str());
210 if (!(actual < expected))
return;
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>
224 TestIsLte(
const A& actual,
const E& expected,
bool inverted=
false) : actual(actual), expected(expected), inverted(inverted) {}
231 if (actual <= expected)
return;
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());
236 if (!(actual <= expected))
return;
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>
250 TestIsGt(
const A& actual,
const E& expected,
bool inverted=
false) : actual(actual), expected(expected), inverted(inverted) {}
257 if (actual > expected)
return;
258 std::stringstream ss;
259 ss <<
"value '" << actual <<
"' is not greater than the expected '" << expected <<
"'";
260 wibble_test_location.
fail_test(ss.str());
262 if (!(actual > expected))
return;
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>
276 TestIsGte(
const A& actual,
const E& expected,
bool inverted=
false) : actual(actual), expected(expected), inverted(inverted) {}
283 if (actual >= expected)
return;
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());
288 if (!(actual >= expected))
return;
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());
301 TestStartsWith(
const std::string& actual,
const std::string& expected,
bool inverted=
false) : actual(actual), expected(expected), inverted(inverted) {}
312 TestEndsWith(
const std::string& actual,
const std::string& expected,
bool inverted=
false) : actual(actual), expected(expected), inverted(inverted) {}
323 TestContains(
const std::string& actual,
const std::string& expected,
bool inverted=
false) : actual(actual), expected(expected), inverted(inverted) {}
334 TestRegexp(
const std::string& actual,
const std::string& regexp,
bool inverted=
false) : actual(actual), regexp(regexp), inverted(inverted) {}
344 TestFileExists(
const std::string& pathname,
bool inverted=
false) : pathname(pathname), inverted(inverted) {}
354 Actual(
const A& actual) : actual(actual) {}
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__) TestEquals< A, E > operator!()
Definition: tests.h:173
const wibble::tests::Location wibble_test_location
Definition: tests.cpp:16
void check(WIBBLE_TEST_LOCPRM) const
Definition: tests.h:279
void fail_test(const std::string &msg) const WIBBLE_TESTS_ALWAYS_THROWS
Definition: tests.cpp:74
TestIsLte(const A &actual, const E &expected, bool inverted=false)
Definition: tests.h:224
TestFileExists(const std::string &pathname, bool inverted=false)
Definition: tests.h:344
TestIsGte< A, E > operator>=(const E &expected) const
Definition: tests.h:362
void check(WIBBLE_TEST_LOCPRM) const
Definition: tests.h:201
TestContains(const std::string &actual, const std::string &expected, bool inverted=false)
Definition: tests.h:323
TestEquals< std::string, std::string > operator==(const std::string &expected) const
Definition: tests.h:370
TestFileExists fileexists() const
Definition: tests.h:380
bool inverted
Definition: tests.h:275
std::string actual
Definition: tests.h:320
A actual
Definition: tests.h:194
std::string actual
Definition: tests.h:298
void check(WIBBLE_TEST_LOCPRM) const
Definition: tests.h:227
bool inverted
Definition: tests.h:333
std::string expected
Definition: tests.h:299
A actual
Definition: tests.h:353
bool inverted
Definition: tests.h:300
#define WIBBLE_TESTS_ALWAYS_THROWS
Definition: tests.h:45
TestIsGt< std::string, std::string > operator>(const std::string &expected) const
Definition: tests.h:374
TestEndsWith endswith(const std::string &expected) const
Definition: tests.h:377
A actual
Definition: tests.h:167
A actual
Definition: tests.h:247
const wibble::tests::LocationInfo wibble_test_location_info
Definition: tests.cpp:17
bool inverted
Definition: tests.h:146
E expected
Definition: tests.h:168
void impl_ensure_equals(const Location &loc, const Actual &actual, const Expected &expected)
Definition: tests.h:109
void impl_ensure_not_contains(const wibble::tests::Location &loc, const std::string &haystack, const std::string &needle)
Definition: tests.cpp:176
TestIsGte(const A &actual, const E &expected, bool inverted=false)
Definition: tests.h:276
TestEndsWith(const std::string &actual, const std::string &expected, bool inverted=false)
Definition: tests.h:312
TestRegexp operator!()
Definition: tests.h:336
std::string actual
Definition: tests.h:309
TestStartsWith(const std::string &actual, const std::string &expected, bool inverted=false)
Definition: tests.h:301
bool inverted
Definition: tests.h:322
E expected
Definition: tests.h:274
E expected
Definition: tests.h:195
std::string actual
Definition: tests.h:331
TestEquals< A, E > operator==(const E &expected) const
Definition: tests.h:357
bool operator<=(const T &a, const std::set< T > &b)
Definition: operators.h:220
ActualString(const std::string &s)
Definition: tests.h:369
TestIsLt(const A &actual, const E &expected, bool inverted=false)
Definition: tests.h:197
#define WIBBLE_TEST_LOCPRM
Definition: tests.h:93
TestBool< A > operator!()
Definition: tests.h:149
E expected
Definition: tests.h:248
TestContains contains(const std::string &expected) const
Definition: tests.h:378
TestIsGte< std::string, std::string > operator>=(const std::string &expected) const
Definition: tests.h:375
Actual(const A &actual)
Definition: tests.h:354
TestEquals(const A &actual, const E &expected, bool inverted=false)
Definition: tests.h:170
E expected
Definition: tests.h:222
void impl_ensure(const Location &loc, bool res)
Definition: tests.cpp:160
TestRegexp matches(const std::string ®exp) const
Definition: tests.h:379
std::string expected
Definition: tests.h:321
TestContains operator!()
Definition: tests.h:325
bool inverted
Definition: tests.h:249
~Actual()
Definition: tests.h:355
TestEndsWith operator!()
Definition: tests.h:314
TestIsLt< A, E > operator!()
Definition: tests.h:200
bool inverted
Definition: tests.h:169
std::string pathname
Definition: tests.h:342
TestBool< A > istrue() const
Definition: tests.h:363
TestIsGt(const A &actual, const E &expected, bool inverted=false)
Definition: tests.h:250
std::string regexp
Definition: tests.h:332
bool inverted
Definition: tests.h:343
TestIsLte< A, E > operator!()
Definition: tests.h:226
const A & actual
Definition: tests.h:145
TestEquals< std::string, std::string > operator!=(const std::string &expected) const
Definition: tests.h:371
bool inverted
Definition: tests.h:223
A actual
Definition: tests.h:221
void check(WIBBLE_TEST_LOCPRM) const
Definition: tests.h:253
TestBool(const A &actual, bool inverted=false)
Definition: tests.h:147
void check(WIBBLE_TEST_LOCPRM) const
Definition: tests.h:151
TestBool< A > isfalse() const
Definition: tests.h:364
void impl_ensure_similar(const Location &loc, const Actual &actual, const Expected &expected, const Precision &precision)
Definition: tests.h:123
TestStartsWith startswith(const std::string &expected) const
Definition: tests.h:376
Actual< A > actual(const A &actual)
Definition: tests.h:384
std::string expected
Definition: tests.h:310
TestStartsWith operator!()
Definition: tests.h:303
void impl_ensure_contains(const wibble::tests::Location &loc, const std::string &haystack, const std::string &needle)
Definition: tests.cpp:166
A actual
Definition: tests.h:273
TestIsGte< A, E > operator!()
Definition: tests.h:278
TestEquals< A, E > operator!=(const E &expected) const
Definition: tests.h:358
bool inverted
Definition: tests.h:196
void check(WIBBLE_TEST_LOCPRM) const
Definition: tests.h:174
TestRegexp(const std::string &actual, const std::string ®exp, bool inverted=false)
Definition: tests.h:334
TestFileExists operator!()
Definition: tests.h:345
TestIsGt< A, E > operator!()
Definition: tests.h:252
LocationInfo()
Definition: tests.h:90
TestIsGt< A, E > operator>(const E &expected) const
Definition: tests.h:361
bool inverted
Definition: tests.h:311