Thread: [Cppunit-devel] Subclassing Exception class for better test failure report
Brought to you by:
blep
From: Baptiste L. <bl...@cl...> - 2001-06-10 11:59:56
|
I want to allow library users and cppunit to subclass the Exception class. First purpose for this would be to have a NotEqualException which would take two strings in the constructor (acual and expected), allowing better error report (put the text on different line, on different edit filed in a GUI...). Further purpose is to allow users of the library to "create" their one assertions and capture more information, while still being able to use cppunit framework. To do this we need: - be able to duplicate any instance of Exception (or subclassed Exception) - identify the actual Exception type so we can downcast if allow. To do this, I propose to: - add "public virtual Exception *clone() const" method which returns a copy of the Exception. - add "protected virtual std::string exceptionType() const" method which returns a string that identify the exception type (the most extensible and portable way I can think of). - add "public static bool isInstanceOf( Exception &e )" method to each class which inherits Exception. This method returns true if exceptionType() return the correct identifier string. I'd like to be able to report assertEqual() in a better way soon, so feedback is welcome. A simple string work well for simple data, but when you are comparing data structure, it's unreadable. Thanks, Baptiste. --- Baptiste Lepilleur <gai...@fr...> http://gaiacrtn.free.fr/index.html Author of The Text Reformatter, a tool for fanfiction readers and writers. Language: English, French (Well, I'm French). |
From: Michael A. <ch...@mu...> - 2001-06-10 18:25:49
|
Just a small point - I would like to be able to use CppUnit in Unicode = projects, so I think it needs some generic string class which chances = dependent on using Unicode or not. It could be a simple typedef to = std::string or std::wstring. Michael Arnoldus ----- Original Message -----=20 From: "Baptiste Lepilleur" <bl...@cl...> To: "Cpp Unit Develpment Mailing List" = <cpp...@li...> Sent: Saturday, June 10, 2000 2:15 PM Subject: [Cppunit-devel] Subclassing Exception class for better test = failure report > I want to allow library users and cppunit to subclass the = Exception > class. >=20 > First purpose for this would be to have a NotEqualException which = would > take two strings in the constructor (acual and expected), allowing = better > error report (put the text on different line, on different edit filed = in a > GUI...). >=20 > Further purpose is to allow users of the library to "create" their = one > assertions and capture more information, while still being able to use > cppunit framework. >=20 > To do this we need: > - be able to duplicate any instance of Exception (or subclassed > Exception) > - identify the actual Exception type so we can downcast if allow. >=20 > To do this, I propose to: > - add "public virtual Exception *clone() const" method which = returns a > copy of the Exception. > - add "protected virtual std::string exceptionType() const" method = which > returns a string that identify the exception type (the most extensible = and > portable way I can think of). > - add "public static bool isInstanceOf( Exception &e )" method to = each > class which inherits Exception. This method returns true if = exceptionType() > return the correct identifier string. >=20 > I'd like to be able to report assertEqual() in a better way soon, = so > feedback is welcome. A simple string work well for simple data, but = when you > are comparing data structure, it's unreadable. >=20 > Thanks, > Baptiste. > --- > Baptiste Lepilleur <gai...@fr...> = http://gaiacrtn.free.fr/index.html > Author of The Text Reformatter, a tool for fanfiction readers and = writers. > Language: English, French (Well, I'm French). >=20 >=20 > _______________________________________________ > Cppunit-devel mailing list > Cpp...@li... > http://lists.sourceforge.net/lists/listinfo/cppunit-devel >=20 >=20 >=20 |
From: Baptiste L. <bl...@cl...> - 2001-06-10 19:08:56
|
Yes. If you remember the mail that I wrote a while back, this is the second option for unicode: having a "string" class in the cppunit nameclass that is an alias to either std::string or std::wstring. That solution also fit well with the <sstream>/ostringstream problem. The method expectionType() would be a victim to that change... I will rise the unicode problem once the basic will be cleaned up (config, core stuff working correctly). Should not be so long. I'm nearly done writing unit tests (there is 72 tests by now and they cover most of the functionnalities). Baptiste. ----- Original Message ----- From: "Michael Arnoldus" <ch...@mu...> To: <cpp...@li...> Sent: Sunday, June 10, 2001 8:24 PM Subject: Re: [Cppunit-devel] Subclassing Exception class for better test failure report Just a small point - I would like to be able to use CppUnit in Unicode projects, so I think it needs some generic string class which chances dependent on using Unicode or not. It could be a simple typedef to std::string or std::wstring. Michael Arnoldus ----- Original Message ----- From: "Baptiste Lepilleur" <bl...@cl...> To: "Cpp Unit Develpment Mailing List" <cpp...@li...> Sent: Saturday, June 10, 2000 2:15 PM Subject: [Cppunit-devel] Subclassing Exception class for better test failure report > I want to allow library users and cppunit to subclass the Exception > class. > > First purpose for this would be to have a NotEqualException which would > take two strings in the constructor (acual and expected), allowing better > error report (put the text on different line, on different edit filed in a > GUI...). > > Further purpose is to allow users of the library to "create" their one > assertions and capture more information, while still being able to use > cppunit framework. > > To do this we need: > - be able to duplicate any instance of Exception (or subclassed > Exception) > - identify the actual Exception type so we can downcast if allow. > > To do this, I propose to: > - add "public virtual Exception *clone() const" method which returns a > copy of the Exception. > - add "protected virtual std::string exceptionType() const" method which > returns a string that identify the exception type (the most extensible and > portable way I can think of). > - add "public static bool isInstanceOf( Exception &e )" method to each > class which inherits Exception. This method returns true if exceptionType() > return the correct identifier string. > > I'd like to be able to report assertEqual() in a better way soon, so > feedback is welcome. A simple string work well for simple data, but when you > are comparing data structure, it's unreadable. > > Thanks, > Baptiste. > --- > Baptiste Lepilleur <gai...@fr...> http://gaiacrtn.free.fr/index.html > Author of The Text Reformatter, a tool for fanfiction readers and writers. > Language: English, French (Well, I'm French). > > > _______________________________________________ > Cppunit-devel mailing list > Cpp...@li... > http://lists.sourceforge.net/lists/listinfo/cppunit-devel > > > _______________________________________________ Cppunit-devel mailing list Cpp...@li... http://lists.sourceforge.net/lists/listinfo/cppunit-devel |