Re: [Cppunit-devel] regular expression match
Brought to you by:
blep
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 |