X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=flower%2Finclude%2Fyaffut.hh;h=e324922b69738c60abbc17c7ab88b46ef3b789b8;hb=41b723feaf642125d00d549739c6f9ed2f28fc63;hp=91a35214935e1598a873a1e6fdc6af0397f2c01b;hpb=308689f5ec62b42a01c9673cdb16cc7fa7a9bdd9;p=lilypond.git diff --git a/flower/include/yaffut.hh b/flower/include/yaffut.hh index 91a3521493..e324922b69 100644 --- a/flower/include/yaffut.hh +++ b/flower/include/yaffut.hh @@ -9,7 +9,9 @@ #include #include +#include #include +#include #include #include #include @@ -135,12 +137,12 @@ public: } catch(const std::exception& e) { - std::cout << "[FAIL]\n" << e.what() << std::flush; + std::cout << "[FAIL]\n " << e.what() << std::flush; ++m_fail; } catch(...) { - std::cout << "[FAIL]\nunknown exception" << std::flush; + std::cout << "[FAIL]\n unknown exception" << std::flush; ++m_fail; } } @@ -241,12 +243,30 @@ struct Registrator } }; -template -struct Test: public ITest, public Suite +template +struct Registrator +{ + Registrator() + { + Factory::Instance().Register(TestName(), Create); + } + const std::string& TestName() + { + static const std::string name ("::" + demangle()); + return name; + } + static ITest* Create() + { + return new Case; + } +}; + + +template +struct Test: public ITest, public virtual Suite { static Registrator s_Registrator; - Test() - : Suite() + Test(): Suite() { Registrator* r = &s_Registrator; r = 0; @@ -266,6 +286,33 @@ struct Test: public ITest, public Suite template Registrator Test::s_Registrator; + +template +struct Test: public ITest +{ + static Registrator s_Registrator; + Test() + { + Registrator* r = &s_Registrator; + r = 0; + } + template + void assert_throw(void(T::*mf)(), const char* at) + { + try + { + (dynamic_cast (this)->*mf)(); + throw yaffut::failure (at, "statement failed to throw"); + } + catch(const E&){} + } +}; + +template +Registrator Test::s_Registrator; + + + template void equal(const Expected& e, const Actual& a, const char* at = "", const char* expr = "") { @@ -328,19 +375,16 @@ void assert_throw(void(*pf)(), const char* at = "") catch(const E&){} } -//define catch-all suite -struct Suite {}; - } -//and for those who prefer macro obscurity over more typing +//and for those who prefer macro obscurity over typing #define TEST(Suite, Case)\ namespace { struct Case: public yaffut::Test{ Case(); }; } \ template struct yaffut::Test; Case::Case() #define FUNC(Case)\ - namespace { struct Case: public yaffut::Test{ Case(); }; } \ - template struct yaffut::Test; Case::Case() + namespace { struct Case: public yaffut::Test{ Case(); }; } \ + template struct yaffut::Test; Case::Case() #ifdef YAFFUT_MAIN