36#define TESTGRP(name) \
37typedef test_group<name ## _shar> tg; \
38typedef tg::object to; \
39tg 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))
108template <
class Actual,
class Expected>
113 std::stringstream
ss;
114 ss <<
"expected '" << expected <<
"' actual '" <<
actual <<
"'";
115 loc.fail_test(
ss.str());
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))
122template <
class Actual,
class Expected,
class Precision>
127 std::stringstream
ss;
128 ss <<
"expected '" << expected <<
"' actual '" <<
actual <<
"'";
129 loc.fail_test(
ss.str());
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))
164template<
typename A,
typename E>
179 std::stringstream
ss;
180 ss <<
"value '" <<
actual <<
"' is different than the expected '" <<
expected <<
"'";
184 std::stringstream
ss;
185 ss <<
"value '" <<
actual <<
"' is not different than the expected '" <<
expected <<
"'";
191template<
typename A,
typename E>
206 std::stringstream
ss;
207 ss <<
"value '" <<
actual <<
"' is not less than the expected '" <<
expected <<
"'";
211 std::stringstream
ss;
212 ss <<
"value '" <<
actual <<
"' is less than the expected '" <<
expected <<
"'";
218template<
typename A,
typename E>
232 std::stringstream
ss;
233 ss <<
"value '" <<
actual <<
"' is not less than or equals to the expected '" <<
expected <<
"'";
237 std::stringstream
ss;
238 ss <<
"value '" <<
actual <<
"' is less than or equals to the expected '" <<
expected <<
"'";
244template<
typename A,
typename E>
258 std::stringstream
ss;
259 ss <<
"value '" <<
actual <<
"' is not greater than the expected '" <<
expected <<
"'";
263 std::stringstream
ss;
264 ss <<
"value '" <<
actual <<
"' is greater than the expected '" <<
expected <<
"'";
270template<
typename A,
typename E>
284 std::stringstream
ss;
285 ss <<
"value '" <<
actual <<
"' is not greater than or equals to the expected '" <<
expected <<
"'";
289 std::stringstream
ss;
290 ss <<
"value '" <<
actual <<
"' is greater than or equals to the expected '" <<
expected <<
"'";
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__)
std::string locstr() const
Definition tests.cpp:58
Location nest(const wibble::tests::LocationInfo &info, const char *file, int line, const char *args=0) const
Definition tests.cpp:43
void backtrace(std::ostream &out) const
Definition tests.cpp:48
std::string msg(const std::string m) const
Definition tests.cpp:65
Location()
Definition tests.cpp:22
void fail_test(const std::string &msg) const WIBBLE_TESTS_ALWAYS_THROWS
Definition tests.cpp:74
void impl_ensure_not_contains(const wibble::tests::Location &loc, const std::string &haystack, const std::string &needle)
Definition tests.cpp:176
void impl_ensure_contains(const wibble::tests::Location &loc, const std::string &haystack, const std::string &needle)
Definition tests.cpp:166
void impl_ensure_similar(const Location &loc, const Actual &actual, const Expected &expected, const Precision &precision)
Definition tests.h:123
Actual< A > actual(const A &actual)
Definition tests.h:384
void impl_ensure(const Location &loc, bool res)
Definition tests.cpp:160
void impl_ensure_equals(const Location &loc, const Actual &actual, const Expected &expected)
Definition tests.h:109
TestContains contains(const std::string &expected) const
Definition tests.h:378
TestIsGt< std::string, std::string > operator>(const std::string &expected) const
Definition tests.h:374
TestIsLt< std::string, std::string > operator<(const std::string &expected) const
Definition tests.h:372
TestEquals< std::string, std::string > operator!=(const std::string &expected) const
Definition tests.h:371
TestIsLte< std::string, std::string > operator<=(const std::string &expected) const
Definition tests.h:373
TestIsGte< std::string, std::string > operator>=(const std::string &expected) const
Definition tests.h:375
TestEndsWith endswith(const std::string &expected) const
Definition tests.h:377
TestRegexp matches(const std::string ®exp) const
Definition tests.h:379
TestStartsWith startswith(const std::string &expected) const
Definition tests.h:376
TestEquals< std::string, std::string > operator==(const std::string &expected) const
Definition tests.h:370
ActualString(const std::string &s)
Definition tests.h:369
TestFileExists fileexists() const
Definition tests.h:380
TestEquals< A, E > operator==(const E &expected) const
Definition tests.h:357
TestIsLt< A, E > operator<(const E &expected) const
Definition tests.h:359
~Actual()
Definition tests.h:355
A actual
Definition tests.h:353
TestIsLte< A, E > operator<=(const E &expected) const
Definition tests.h:360
TestBool< A > istrue() const
Definition tests.h:363
TestIsGt< A, E > operator>(const E &expected) const
Definition tests.h:361
TestBool< A > isfalse() const
Definition tests.h:364
TestEquals< A, E > operator!=(const E &expected) const
Definition tests.h:358
TestIsGte< A, E > operator>=(const E &expected) const
Definition tests.h:362
Actual(const A &actual)
Definition tests.h:354
std::ostream & operator()()
Clear the stringstream and return self.
Definition tests.cpp:85
LocationInfo()
Definition tests.h:90
TestBool< A > operator!()
Definition tests.h:149
void check(WIBBLE_TEST_LOCPRM) const
Definition tests.h:151
bool inverted
Definition tests.h:146
TestBool(const A &actual, bool inverted=false)
Definition tests.h:147
const A & actual
Definition tests.h:145
void check(WIBBLE_TEST_LOCPRM) const
Definition tests.cpp:218
bool inverted
Definition tests.h:322
TestContains(const std::string &actual, const std::string &expected, bool inverted=false)
Definition tests.h:323
std::string expected
Definition tests.h:321
std::string actual
Definition tests.h:320
TestContains operator!()
Definition tests.h:325
bool inverted
Definition tests.h:311
std::string expected
Definition tests.h:310
TestEndsWith operator!()
Definition tests.h:314
void check(WIBBLE_TEST_LOCPRM) const
Definition tests.cpp:202
TestEndsWith(const std::string &actual, const std::string &expected, bool inverted=false)
Definition tests.h:312
std::string actual
Definition tests.h:309
bool inverted
Definition tests.h:169
TestEquals< A, E > operator!()
Definition tests.h:173
TestEquals(const A &actual, const E &expected, bool inverted=false)
Definition tests.h:170
void check(WIBBLE_TEST_LOCPRM) const
Definition tests.h:174
A actual
Definition tests.h:167
E expected
Definition tests.h:168
void check(WIBBLE_TEST_LOCPRM) const
Definition tests.cpp:251
bool inverted
Definition tests.h:343
TestFileExists(const std::string &pathname, bool inverted=false)
Definition tests.h:344
std::string pathname
Definition tests.h:342
TestFileExists operator!()
Definition tests.h:345
TestIsGt(const A &actual, const E &expected, bool inverted=false)
Definition tests.h:250
A actual
Definition tests.h:247
bool inverted
Definition tests.h:249
TestIsGt< A, E > operator!()
Definition tests.h:252
E expected
Definition tests.h:248
void check(WIBBLE_TEST_LOCPRM) const
Definition tests.h:253
bool inverted
Definition tests.h:275
E expected
Definition tests.h:274
TestIsGte(const A &actual, const E &expected, bool inverted=false)
Definition tests.h:276
TestIsGte< A, E > operator!()
Definition tests.h:278
A actual
Definition tests.h:273
void check(WIBBLE_TEST_LOCPRM) const
Definition tests.h:279
E expected
Definition tests.h:195
bool inverted
Definition tests.h:196
void check(WIBBLE_TEST_LOCPRM) const
Definition tests.h:201
A actual
Definition tests.h:194
TestIsLt< A, E > operator!()
Definition tests.h:200
TestIsLt(const A &actual, const E &expected, bool inverted=false)
Definition tests.h:197
bool inverted
Definition tests.h:223
void check(WIBBLE_TEST_LOCPRM) const
Definition tests.h:227
A actual
Definition tests.h:221
TestIsLte< A, E > operator!()
Definition tests.h:226
TestIsLte(const A &actual, const E &expected, bool inverted=false)
Definition tests.h:224
E expected
Definition tests.h:222
TestRegexp operator!()
Definition tests.h:336
void check(WIBBLE_TEST_LOCPRM) const
Definition tests.cpp:234
std::string actual
Definition tests.h:331
bool inverted
Definition tests.h:333
TestRegexp(const std::string &actual, const std::string ®exp, bool inverted=false)
Definition tests.h:334
std::string regexp
Definition tests.h:332
void check(WIBBLE_TEST_LOCPRM) const
Definition tests.cpp:186
bool inverted
Definition tests.h:300
TestStartsWith operator!()
Definition tests.h:303
std::string expected
Definition tests.h:299
TestStartsWith(const std::string &actual, const std::string &expected, bool inverted=false)
Definition tests.h:301
std::string actual
Definition tests.h:298
const wibble::tests::Location wibble_test_location
Definition tests.cpp:16
const wibble::tests::Location wibble_test_location
Definition tests.cpp:16
#define WIBBLE_TEST_LOCPRM
Definition tests.h:93
const wibble::tests::LocationInfo wibble_test_location_info
Definition tests.cpp:17
#define WIBBLE_TESTS_ALWAYS_THROWS
Definition tests.h:45