Thread: [Cppunit-devel] regular expression match
Brought to you by:
blep
From: Volker B. <vbo...@te...> - 2002-04-10 07:05:22
|
Hi, for quite a while now it has been a plan of mine to add some sort of regular expression support to cppunit. Whenever it gets to comparing strings it would often help to use regular expressions instead of exact string match. Often dynamic information is the problem. An example: I want to check the output of a logging server. Every message should have this format: <msg. sequence no.> <process id> <date> <time> <message> e.g. 2 15337 2002-04-05 09:44 server started With current cppunit I use shell scripts to check the output. With regular expressions it would be much easier, e.g. CPPUNIT_ASSERT_REGEX_MATCH("^\d+ \d+ 20\d{2}-\d{2}-\d{2}" "\d{2}:\d{2} server started", logline); (with perl style \d :=3D [0-9]). But there might be some issues with using regular expressions in C++: - Although regular expression handling is part of the POSIX standard I don't know how portable it is. - The regex interface is somewhat more complicated than a simple string equality. There are a lot of switches and options controlling the type of match. But it should be *really simple* to use in cppunit. - There are some concurring regex implementation. On Debian Linux e.g. there are at least 5: glibc (libc/POSIX), libregex (GNU), libregexx (C++ wrapper for libregex), libboost (C++, maintained by well known Steve M. Robbins...), libpcre (perl style regex) I think, we should have at least one simple regex-assert, at least on some platforms that supports regexps. Perhaps we could have a requirement like this 'if you want to use regexps with cppunit you have to install libXXX otherwise they will be disabled' (the way cppunit deals with doxygen). I think this has some advantages: - One could use the 'best suited' library, e.g. a C++-library. - There might be less portability issues. Comments? Are there even any existing implementations of regex-asserts already? Best regards, Volker (BTW. regexps are still less than one could think of: In the example above there is no way to ensure that the timestamp is a valid date...) --=20 Volker Boerchers <vbo...@te...> System Engineer TECON Systems AG, Perlengraben 2, 50676 K=F6ln, http://www.tecon.de Tel: +49-221-92007-55, Fax: +49-221-92007-77 |
From: Steve M. R. <ste...@vi...> - 2002-04-10 12:45:45
|
Hi, I haven't any real opinion on adding regular expression matching to CppUnit. I presume one could always call their own favourite regex matcher wrapped up in CPPUNIT_ASSERT without too much trouble. However, since you mentioned the BOOST libraries, I wonder if you have looked at their implementations of concept checking and testing? The web page (www.boost.org) indicates that there is not yet any unit test library. The BOOST code is pretty well designed and the mailing list is full of very bright people. So it would be a boon to have CppUnit involved with them. I haven't looked at any of this stuff, myself. Has anyone else? -Steve -- by Rocket to the Moon, by Airplane to the Rocket, by Taxi to the Airport, by Frontdoor to the Taxi, by throwing back the blanket and laying down the legs ... - They Might Be Giants |
From: Duane M. <dua...@ma...> - 2002-04-10 15:54:42
|
--- At Wed, 10 Apr 2002 08:45:39 -0400, Steve M. Robbins wrote: >Hi, > >I haven't any real opinion on adding regular expression matching >to CppUnit. I presume one could always call their own favourite >regex matcher wrapped up in CPPUNIT_ASSERT without too much trouble. > >However, since you mentioned the BOOST libraries, I wonder if you have >looked at their implementations of concept checking and testing? The >web page (www.boost.org) indicates that there is not yet any unit test >library. The BOOST code is pretty well designed and the mailing list >is full of very bright people. So it would be a boon to have CppUnit >involved with them. > >I haven't looked at any of this stuff, myself. Has anyone else? I am a subscriber of the boost users list <mailto:boost-users- sub...@ya...> or <http://www.boost.org>. Boost has a C++ regular expression interface as well as a unit test framework. The unit test framework has no relationship to CppUnit. I have mentioned it to the developer of the Boost framework with no real response. The present unit testing is buried in boost, I believe to test some of boost. But the intention is that it will eventually be something like CppUnit. I find this very disappointing as CppUnit is much farther along. I imagine that CppUnit could also benefit greatly from the input of the Boost group. As I understand it, the boost regular expression library is meant to be Perl compatible (although why not posix I am not sure). I believe boost may be working towards getting the regular expression library into the C++ standard library. Be aware that I have used neither of these libraries. ...Duane -- "If tyranny and oppression come to this land, it will be in the guise of fighting a foreign enemy." - James Madison |
From: Arlo B. <arl...@ho...> - 2002-04-10 16:01:30
|
I've been using the boost libraries for a while, including their regexp stuff. If you're looking for a regexp library, I'd recommend Boost's. In particular, it works well with STLPort, which means that the list of currently supported platforms includes all Windows, Mac OS X, Mac OS 6.something +, a few dozen Linux distros, most Unixes, Amiga, PS2, XBox, and so on. You don't have to worry about platform availability, although you do have to ensure that the developer installs the STLPort and Boost libraries. Likewise, he boost regex was built with Unicode in mind. It performs all matching using char_traits, so should internationalize as well as the rest of the STL (YMMV). It supports most digraphs, and matches umlauted, accented, and otherwise modified characters correctly. I expect it to work with the Asian, Arabic and Hebrew languages, but don't really know. Additionally, it uses a pretty full regex syntax, similar to Perl's. I haven't found much missing, although the regex strings end up as even more line noise than they do in Perl, because you have to escape the backslash character past the C++ processor any time that you put in an escape sequence. There is a learning curve on the boost regexp - it tries to expose a completely generalized interface, which leads to complexity. As most STL things, it defines algorithms that operates on ranges, which means that you can trivially use it to match not only on a string, but also on any container, on files directly, or an a wrapped stream (it requires on bi-directional iterators, so you can't just match on cin directly). However, this adds some complexity to its use - there are lots of results classes, templates, and syntactical garbage to keep track of. For the purposes of CppUnit, you are really only looking for a match / no match result, so you could easily wrap it all in a functor which returns a bool. Then a simple macro to assert on that, and voila. Note, however, the use of you in that sentence. Sorry guys, but I've got a ship date coming up at work, and won't be able to get around to just writing this for a while. Another option would be to have a family of such functors that use the various regex libraries, and have CppUnit select one based on what libs are installed on the developer's machine (either statically or dynamically). I don't know how feasible it would be to check for support on other platforms (haven't tried it), but it's trivial to tell whether Boost & STLPort are installed on a Window box, as they are both DLLs. In any case, static config is simple enough. I agree that it would be good to have these two projects become involved with each other. Note, however, that CppUnit isn't really architected in the way that they're planning to build the test library. Probably both sides will change on this one - as Steve pointed out, they don't have an implementation. Arlo > -----Original Message----- > From: cpp...@li... > > I haven't any real opinion on adding regular expression matching > to CppUnit. I presume one could always call their own favourite > regex matcher wrapped up in CPPUNIT_ASSERT without too much trouble. > > However, since you mentioned the BOOST libraries, I wonder if you have > looked at their implementations of concept checking and testing? The > web page (www.boost.org) indicates that there is not yet any unit test > library. The BOOST code is pretty well designed and the mailing list > is full of very bright people. So it would be a boon to have CppUnit > involved with them. > > I haven't looked at any of this stuff, myself. Has anyone else? |
From: Volker B. <vbo...@te...> - 2002-04-11 10:34:26
|
On Wed, 10 Apr 2002, Arlo Belshee wrote: > I've been using the boost libraries for a while, including their regexp > stuff. If you're looking for a regexp library, I'd recommend Boost's. I stumbled across the boost project searching for a regexp library but was pretty amazed that I never heard about this large and nice thing before. > In particular, it works well with STLPort, which means that the list of > currently supported platforms includes all Windows, Mac OS X, Mac OS > 6.something +, a few dozen Linux distros, most Unixes, Amiga, PS2, XBox, = and > so on. You don't have to worry about platform availability, although you = do > have to ensure that the developer installs the STLPort and Boost librarie= s. >=20 > Likewise, he boost regex was built with Unicode in mind. It performs all > matching using char_traits, so should internationalize as well as the res= t > of the STL (YMMV). It supports most digraphs, and matches umlauted, > accented, and otherwise modified characters correctly. I expect it to wor= k > with the Asian, Arabic and Hebrew languages, but don't really know. >=20 > Additionally, it uses a pretty full regex syntax, similar to Perl's. I > haven't found much missing, although the regex strings end up as even mor= e > line noise than they do in Perl, because you have to escape the backslash > character past the C++ processor any time that you put in an escape > sequence. Thank you for this evaluation! When I find the time I will implement an asserter using the boost-library and try to add the necessary autoconf stuff. As long as one makes the library selectable via configure this dependency should be acceptable I think. Regex matching would be an add-on and no basic functionality would depend on it. Regards, Volker --=20 Volker Boerchers <vbo...@te...> System Engineer TECON Systems AG, Perlengraben 2, 50676 K=F6ln, http://www.tecon.de Tel: +49-221-92007-55, Fax: +49-221-92007-77 |
From: Baptiste L. <gai...@fr...> - 2002-04-10 16:49:53
|
----- Original Message ----- From: "Steve M. Robbins" <ste...@vi...> To: "CppUnit Development" <cpp...@li...> Sent: Wednesday, April 10, 2002 2:45 PM Subject: Re: [Cppunit-devel] regular expression match > Hi, > > I haven't any real opinion on adding regular expression matching > to CppUnit. I presume one could always call their own favourite > regex matcher wrapped up in CPPUNIT_ASSERT without too much trouble. > > However, since you mentioned the BOOST libraries, I wonder if you have > looked at their implementations of concept checking and testing? The > web page (www.boost.org) indicates that there is not yet any unit test > library. The BOOST code is pretty well designed and the mailing list > is full of very bright people. So it would be a boon to have CppUnit > involved with them. > > I haven't looked at any of this stuff, myself. Has anyone else? I have used some of boost component (smart-pointer and regular expression). There is lot of interesting thing, but not always supported by all compiler (tuple is pretty much useless on VC++). I haven't looked to deep into the unit test (I tried to give it a look, but they are usually a large bunch of lines, pretty much unreadable for me.). Still, they test for memory leak. Baptiste. |
From: Baptiste L. <gai...@fr...> - 2002-04-10 16:52:32
|
You can easily add your own assertion using Asserter. Look up the documentation menu 'module': creating you assertion. At the current time, I don't wish to introduce dependency uppon boost library (weird build system, and not has more portability problems than cppunit. Still a great lib, though.). Baptiste. ----- Original Message ----- From: "Volker Boerchers" <vbo...@te...> To: <cpp...@li...> Sent: Wednesday, April 10, 2002 9:04 AM Subject: [Cppunit-devel] regular expression match Hi, for quite a while now it has been a plan of mine to add some sort of regular expression support to cppunit. Whenever it gets to comparing strings it would often help to use regular expressions instead of exact string match. Often dynamic information is the problem. An example: I want to check the output of a logging server. Every message should have this format: <msg. sequence no.> <process id> <date> <time> <message> e.g. 2 15337 2002-04-05 09:44 server started With current cppunit I use shell scripts to check the output. With regular expressions it would be much easier, e.g. CPPUNIT_ASSERT_REGEX_MATCH("^\d+ \d+ 20\d{2}-\d{2}-\d{2}" "\d{2}:\d{2} server started", logline); (with perl style \d := [0-9]). But there might be some issues with using regular expressions in C++: - Although regular expression handling is part of the POSIX standard I don't know how portable it is. - The regex interface is somewhat more complicated than a simple string equality. There are a lot of switches and options controlling the type of match. But it should be *really simple* to use in cppunit. - There are some concurring regex implementation. On Debian Linux e.g. there are at least 5: glibc (libc/POSIX), libregex (GNU), libregexx (C++ wrapper for libregex), libboost (C++, maintained by well known Steve M. Robbins...), libpcre (perl style regex) I think, we should have at least one simple regex-assert, at least on some platforms that supports regexps. Perhaps we could have a requirement like this 'if you want to use regexps with cppunit you have to install libXXX otherwise they will be disabled' (the way cppunit deals with doxygen). I think this has some advantages: - One could use the 'best suited' library, e.g. a C++-library. - There might be less portability issues. Comments? Are there even any existing implementations of regex-asserts already? Best regards, Volker (BTW. regexps are still less than one could think of: In the example above there is no way to ensure that the timestamp is a valid date...) -- Volker Boerchers <vbo...@te...> System Engineer TECON Systems AG, Perlengraben 2, 50676 Köln, http://www.tecon.de Tel: +49-221-92007-55, Fax: +49-221-92007-77 _______________________________________________ Cppunit-devel mailing list Cpp...@li... https://lists.sourceforge.net/lists/listinfo/cppunit-devel |