Go to the documentation of this file.
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))
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>
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))
164 template<
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 <<
"'";
191 template<
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 <<
"'";
218 template<
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 <<
"'";
244 template<
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 <<
"'";
270 template<
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::ostream & operator()()
Clear the stringstream and return self.
Definition: tests.cpp:85
TestContains contains(const std::string &expected) const
Definition: tests.h:378
TestBool< A > operator!()
Definition: tests.h:149
void test_assert_endswith(WIBBLE_TEST_LOCPRM, const std::string &expected, const std::string &actual)
Definition: tests.cpp:114
Actual(const A &actual)
Definition: tests.h:354
TestEndsWith operator!()
Definition: tests.h:314
TestEquals(const A &actual, const E &expected, bool inverted=false)
Definition: tests.h:170
~Actual()
Definition: tests.h:355
void impl_ensure_similar(const Location &loc, const Actual &actual, const Expected &expected, const Precision &precision)
Definition: tests.h:123
void test_assert_startswith(WIBBLE_TEST_LOCPRM, const std::string &expected, const std::string &actual)
Definition: tests.cpp:104
TestBool< A > istrue() const
Definition: tests.h:363
bool inverted
Definition: tests.h:300
std::string regexp
Definition: tests.h:332
const wibble::tests::Location wibble_test_location
Definition: tests.cpp:16
bool inverted
Definition: tests.h:275
std::string expected
Definition: tests.h:299
TestBool< A > isfalse() const
Definition: tests.h:364
TestIsLte(const A &actual, const E &expected, bool inverted=false)
Definition: tests.h:224
const wibble::tests::Location wibble_test_location
Definition: tests.cpp:16
std::string expected
Definition: tests.h:321
bool inverted
Definition: tests.h:196
TestFileExists fileexists() const
Definition: tests.h:380
#define WIBBLE_TESTS_ALWAYS_THROWS
Definition: tests.h:45
TestEquals< A, E > operator==(const E &expected) const
Definition: tests.h:357
bool match(const std::string &str, int flags=0)
Definition: regexp.cpp:74
Location nest(const wibble::tests::LocationInfo &info, const char *file, int line, const char *args=0) const
Definition: tests.cpp:43
void check(WIBBLE_TEST_LOCPRM) const
Definition: tests.cpp:234
bool exists(const std::string &s)
Same as access(s, F_OK);.
Location()
Definition: tests.cpp:22
TestIsGt< A, E > operator!()
Definition: tests.h:252
const A & actual
Definition: tests.h:145
std::string actual
Definition: tests.h:298
std::string pathname
Definition: tests.h:342
TestIsLt< std::string, std::string > operator<(const std::string &expected) const
Definition: tests.h:372
void check(WIBBLE_TEST_LOCPRM) const
Definition: tests.h:227
std::string actual
Definition: tests.h:331
A actual
Definition: tests.h:247
TestBool(const A &actual, bool inverted=false)
Definition: tests.h:147
void check(WIBBLE_TEST_LOCPRM) const
Definition: tests.cpp:186
void test_assert_file_exists(WIBBLE_TEST_LOCPRM, const std::string &fname)
Definition: tests.cpp:140
void check(WIBBLE_TEST_LOCPRM) const
Definition: tests.h:201
TestIsLt(const A &actual, const E &expected, bool inverted=false)
Definition: tests.h:197
TestStartsWith(const std::string &actual, const std::string &expected, bool inverted=false)
Definition: tests.h:301
bool inverted
Definition: tests.h:343
TestEndsWith(const std::string &actual, const std::string &expected, bool inverted=false)
Definition: tests.h:312
TestEquals< A, E > operator!()
Definition: tests.h:173
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
bool inverted
Definition: tests.h:311
void check(WIBBLE_TEST_LOCPRM) const
Definition: tests.h:151
void backtrace(std::ostream &out) const
Definition: tests.cpp:48
TestIsGte< A, E > operator>=(const E &expected) const
Definition: tests.h:362
TestEquals< A, E > operator!=(const E &expected) const
Definition: tests.h:358
TestIsGte(const A &actual, const E &expected, bool inverted=false)
Definition: tests.h:276
E expected
Definition: tests.h:168
void check(WIBBLE_TEST_LOCPRM) const
Definition: tests.h:174
TestStartsWith startswith(const std::string &expected) const
Definition: tests.h:376
void impl_ensure_contains(const wibble::tests::Location &loc, const std::string &haystack, const std::string &needle)
Definition: tests.cpp:166
TestFileExists(const std::string &pathname, bool inverted=false)
Definition: tests.h:344
void test_assert_contains(WIBBLE_TEST_LOCPRM, const std::string &expected, const std::string &actual)
Definition: tests.cpp:124
E expected
Definition: tests.h:248
TestIsGt< A, E > operator>(const E &expected) const
Definition: tests.h:361
E expected
Definition: tests.h:274
E expected
Definition: tests.h:222
std::string actual
Definition: tests.h:320
TestEquals< std::string, std::string > operator!=(const std::string &expected) const
Definition: tests.h:371
E expected
Definition: tests.h:195
void check(WIBBLE_TEST_LOCPRM) const
Definition: tests.cpp:218
ActualString(const std::string &s)
Definition: tests.h:369
void check(WIBBLE_TEST_LOCPRM) const
Definition: tests.cpp:251
TestIsGte< std::string, std::string > operator>=(const std::string &expected) const
Definition: tests.h:375
TestRegexp operator!()
Definition: tests.h:336
void test_assert_istrue(WIBBLE_TEST_LOCPRM, bool val)
Definition: tests.cpp:134
TestFileExists operator!()
Definition: tests.h:345
Actual< A > actual(const A &actual)
Definition: tests.h:384
bool inverted
Definition: tests.h:169
void test_assert_re_match(WIBBLE_TEST_LOCPRM, const std::string ®exp, const std::string &actual)
Definition: tests.cpp:93
std::string expected
Definition: tests.h:310
void check(WIBBLE_TEST_LOCPRM) const
Definition: tests.cpp:202
TestIsLt< A, E > operator!()
Definition: tests.h:200
#define WIBBLE_TEST_LOCPRM
Definition: tests.h:93
A actual
Definition: tests.h:353
TestIsLte< A, E > operator<=(const E &expected) const
Definition: tests.h:360
std::string locstr() const
Definition: tests.cpp:58
TestIsLte< std::string, std::string > operator<=(const std::string &expected) const
Definition: tests.h:373
TestIsLte< A, E > operator!()
Definition: tests.h:226
TestIsLt< A, E > operator<(const E &expected) const
Definition: tests.h:359
bool inverted
Definition: tests.h:223
const wibble::tests::LocationInfo wibble_test_location_info
Definition: tests.cpp:17
bool inverted
Definition: tests.h:333
void fail_test(const std::string &msg) const WIBBLE_TESTS_ALWAYS_THROWS
Definition: tests.cpp:74
bool inverted
Definition: tests.h:146
TestRegexp matches(const std::string ®exp) const
Definition: tests.h:379
TestContains operator!()
Definition: tests.h:325
TestEquals< std::string, std::string > operator==(const std::string &expected) const
Definition: tests.h:370
void test_assert_not_file_exists(WIBBLE_TEST_LOCPRM, const std::string &fname)
Definition: tests.cpp:150
TestEndsWith endswith(const std::string &expected) const
Definition: tests.h:377
TestStartsWith operator!()
Definition: tests.h:303
A actual
Definition: tests.h:167
bool endsWith(const std::string &str, const std::string &part)
Check if a string ends with the given substring.
Definition: string.h:162
bool startsWith(const std::string &str, const std::string &part)
Check if a string starts with the given substring.
Definition: string.h:154
TestIsGte< A, E > operator!()
Definition: tests.h:278
bool inverted
Definition: tests.h:322
A actual
Definition: tests.h:221
TestIsGt(const A &actual, const E &expected, bool inverted=false)
Definition: tests.h:250
LocationInfo()
Definition: tests.h:90
file(GLOB TEST_SOURCES test_ *.cpp) ADD_CUSTOM_TARGET(check COMMAND make libwibble-test &&$
Definition: tests/CMakeLists.txt:3
void check(WIBBLE_TEST_LOCPRM) const
Definition: tests.h:253
bool inverted
Definition: tests.h:249
TestRegexp(const std::string &actual, const std::string ®exp, bool inverted=false)
Definition: tests.h:334
A actual
Definition: tests.h:273
TestIsGt< std::string, std::string > operator>(const std::string &expected) const
Definition: tests.h:374
A actual
Definition: tests.h:194
TestContains(const std::string &actual, const std::string &expected, bool inverted=false)
Definition: tests.h:323
const wibble::tests::LocationInfo wibble_test_location_info
Definition: tests.cpp:17
std::string msg(const std::string m) const
Definition: tests.cpp:65
void impl_ensure_not_contains(const wibble::tests::Location &loc, const std::string &haystack, const std::string &needle)
Definition: tests.cpp:176
Exception to be throwed when ensure() fails or fail() called.
Definition: tut.h:75
std::string actual
Definition: tests.h:309
void check(WIBBLE_TEST_LOCPRM) const
Definition: tests.h:279