SourceForge has been redesigned. Learn more.
Close

#32 Add optional line wrapping for TextTestProgressListener

open
nobody
5
2003-11-07
2003-11-07
Dale King
No

I have my build process in VC++ set up to run the tests
as part of the build and have the output go to the
output window. The VC++ output window has a
horizontal scroll bar so long lines do not automatically
wrap. If I use the TextTestProgressListener with a large
number of tests the dots and failure indications are not
all visible at once.

I want to be able to specify that the output from the
TextTestProgressListener inserts line breaks every n
characters. Currently I do that with this subclass of
TextTestProgressListener:

class WrappedTextTestProgressListener : public
CPPUNIT_NS::TextTestProgressListener
{
private:
unsigned margin;
unsigned column;

void incrementColumn()
{
if( ++column >= margin )
{
std::cerr << std::endl;
column = 0;
}
}

public:
WrappedTextTestProgressListener( unsigned margin
= ~0 )
: margin( margin ), column( 0 )
{
}

void addFailure( const CPPUNIT_NS::TestFailure
&failure )
{
TextTestProgressListener::addFailure( failure );
incrementColumn();
}

void startTest( CPPUNIT_NS::Test *test )
{
TextTestProgressListener::startTest( test );
incrementColumn();
}
};

This functionality should probably be incorporated into
TextTestProgressListener. Note that the line wrapping is
optional. If you don't specify a margin you will not see a
difference (unless you have enough test to overflow
unsigned).

Another way to go is that I could create a special output
stream wrapper that wraps an ostream to do the line
wrapping. However that doesn't work in this case
because TextTestProgressListener is hardcoded to use
std::cerr. It should take the ostream as a parameter to
the constructor with a specified default value of
std::cerr.

Discussion


Log in to post a comment.