imb / fctx

C unit testing in a header (works for C++ too!).
Other
36 stars 15 forks source link

Better C++ support (std::string, std::wstring, exception testing) #21

Open imb opened 13 years ago

imb commented 13 years ago

I'd like all the standard string tests to support the std::string and std::wstring, I would also like to add a checker for verifying that an exception is correctly generated.

imb commented 13 years ago

Exception verification is now available with fct_chk_ex in the tip.

imb commented 13 years ago

Been thinking on this a little bit, and I think the start would include something like this:

namespace {
template<typename T>
eq(const T &, const T &) {
   throw std::exception("not implemented");
}
} /* fct */

Now that's overly simplified but the idea is that certain types would specialize that template to get "equal" support for their type. So for instance to support a Foo type you would write,

namespace fct{
// specialized for foo
template<>
eq<Foo>(Foo &f1, Foo &f2) {
   myproject::check_foo_likeness(f1,f2);
}
} // namespace foo

That's the rough sketch, but I was also thinking about adding a sort of "fct::repr" template specialization as well that lets you represent your object if there is a specialization, otherwise it falls back to a "this object at address X is not equal to that object at address Y" kind of representation. So quick example,

namespace fct {
template<>
std::string repr<Foo>(Foo const &f) {
   return f.getName();
}
} // namespace fct

as an idea of how to do it. Then the "repr" can be used to hopefully produce meaningful error messages.

imb commented 13 years ago

This issue should be 'open'.