22 #include <wibble/tests.h>
33 #define ensure_contains(x, y) wreport::tests::impl_ensure_contains(wibble::tests::Location(__FILE__, __LINE__, #x " == " #y), (x), (y))
34 #define inner_ensure_contains(x, y) wreport::tests::impl_ensure_contains(wibble::tests::Location(loc, __FILE__, __LINE__, #x " == " #y), (x), (y))
35 static inline void impl_ensure_contains(
const wibble::tests::Location& loc,
const std::string& haystack,
const std::string& needle)
37 if( haystack.find(needle) == std::string::npos )
40 ss <<
"'" << haystack <<
"' does not contain '" << needle <<
"'";
41 throw tut::failure(loc.msg(ss.str()));
45 #define ensure_not_contains(x, y) arki::tests::impl_ensure_not_contains(wibble::tests::Location(__FILE__, __LINE__, #x " == " #y), (x), (y))
46 #define inner_ensure_not_contains(x, y) arki::tests::impl_ensure_not_contains(wibble::tests::Location(loc, __FILE__, __LINE__, #x " == " #y), (x), (y))
47 static inline void impl_ensure_not_contains(
const wibble::tests::Location& loc,
const std::string& haystack,
const std::string& needle)
49 if( haystack.find(needle) != std::string::npos )
52 ss <<
"'" << haystack <<
"' must not contain '" << needle <<
"'";
53 throw tut::failure(loc.msg(ss.str()));
57 #define ensure_varcode_equals(x, y) wreport::tests::_ensure_varcode_equals(wibble::tests::Location(__FILE__, __LINE__, #x " == " #y), (x), (y))
58 #define inner_ensure_varcode_equals(x, y) wreport::tests::_ensure_varcode_equals(wibble::tests::Location(loc, __FILE__, __LINE__, #x " == " #y), (x), (y))
59 static inline void _ensure_varcode_equals(
const wibble::tests::Location& loc,
Varcode actual,
Varcode expected)
61 if( expected != actual )
64 snprintf(buf, 40,
"expected %01d%02d%03d actual %01d%02d%03d",
67 throw tut::failure(loc.msg(buf));
71 #define ensure_var_equals(x, y) wreport::tests::_ensure_var_equals(wibble::tests::Location(__FILE__, __LINE__, #x " == " #y), (x), (y))
72 #define inner_ensure_var_equals(x, y) wreport::tests::_ensure_var_equals(wibble::tests::Location(loc, __FILE__, __LINE__, #x " == " #y), (x), (y))
73 static inline void _ensure_var_equals(
const wibble::tests::Location& loc,
const Var& var,
int val)
75 inner_ensure_equals(var.enqi(), val);
77 static inline void _ensure_var_equals(
const wibble::tests::Location& loc,
const Var& var,
double val)
79 inner_ensure_equals(var.enqd(), val);
81 static inline void _ensure_var_equals(
const wibble::tests::Location& loc,
const Var& var,
const std::string& val)
83 inner_ensure_equals(std::string(var.enqc()), val);
86 #define ensure_var_undef(x) wreport::tests::_ensure_var_undef(wibble::tests::Location(__FILE__, __LINE__, #x " is undef"), (x))
87 #define inner_ensure_var_undef(x) wreport::tests::_ensure_var_undef(wibble::tests::Location(loc, __FILE__, __LINE__, #x " is undef"), (x))
88 static inline void _ensure_var_undef(
const wibble::tests::Location& loc,
const Var& var)
90 inner_ensure_equals(var.value(), (
const char*)0);
105 LocalEnv(
const std::string& key,
const std::string& val)
108 const char* v = getenv(key.c_str());
109 oldVal = v == NULL ?
"" : v;
110 setenv(key.c_str(), val.c_str(), 1);
114 setenv(key.c_str(), oldVal.c_str(), 1);