From: Jan Nieuwenhuizen Date: Wed, 14 Feb 2007 10:58:25 +0000 (+0100) Subject: Yaffut update. X-Git-Tag: release/2.11.19-1~7^2~5 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=894d44860ef5cfaadb8d8de82bddcd78defe9676;p=lilypond.git Yaffut update. --- diff --git a/flower/include/file-name.hh b/flower/include/file-name.hh index 46d4724974..e8ea1ea3c2 100644 --- a/flower/include/file-name.hh +++ b/flower/include/file-name.hh @@ -23,7 +23,7 @@ public: string base_; string ext_; - File_name (string); + File_name (string=""); bool is_absolute () const; string to_string () const; diff --git a/flower/include/yaffut-parameters.hh b/flower/include/yaffut-parameters.hh index 9a569f903c..57429e64ba 100644 --- a/flower/include/yaffut-parameters.hh +++ b/flower/include/yaffut-parameters.hh @@ -3,28 +3,17 @@ #include "yaffut.hh" -namespace yaffut { -template -struct TestOne: public ITest, public Suite -{ - ParameterOne const parameter_one_; - //static Registrator s_Registrator; - TestOne(ParameterOne p) - : Suite(p) - , parameter_one_ (p) - { - Registrator* r = &Test::s_Registrator; - r = 0; - } -}; - -#define TEST_STRING(Suite, Case, String)\ +#define TEST_PARAMETER(Suite, Case, Type, value) \ namespace { \ - struct Case: public yaffut::TestOne{ Case(); }; \ + struct Case: public yaffut::Test{ \ + Type parameter_one_; \ + Case (); \ + }; \ } \ - template struct yaffut::TestOne; Case::Case() \ - : yaffut::TestOne (String) +template struct yaffut::Test; Case::Case () \ + : Suite (value), parameter_one_ (value) -} +#define TEST_STRING(Suite, Case, String) \ + TEST_PARAMETER(Suite, Case, std::string, String) #endif // __YAFFUT_PARAMETERS_H__ diff --git a/flower/include/yaffut.hh b/flower/include/yaffut.hh index 91a3521493..06434b0332 100644 --- a/flower/include/yaffut.hh +++ b/flower/include/yaffut.hh @@ -135,12 +135,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 +241,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 +284,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 +373,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 diff --git a/flower/test-file-name.cc b/flower/test-file-name.cc index 0bd427bda8..edae635e82 100644 --- a/flower/test-file-name.cc +++ b/flower/test-file-name.cc @@ -6,6 +6,11 @@ using namespace std; string slashify (string file_name); +struct CaseB: public yaffut::Test +{ + CaseB(): File_name("123"){} +}; + TEST_STRING (File_name, Mingw_slashify, "foe.ly") { string s = slashify (to_string ());