diff options
| author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2001-05-19 10:29:11 +0000 |
|---|---|---|
| committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2001-05-19 10:29:11 +0000 |
| commit | fed3ef0b01704ee7fd9f41e8cbb706da38c004fe (patch) | |
| tree | 3a83cb3a8a0c46dfcefcfb6ed5b72c6865b717e0 /src/cppunit/TextTestRunner.cpp | |
| parent | 5d704cbbd7928e8a3baec2e18c8d7e0e6089dc6e (diff) | |
| download | cppunit-fed3ef0b01704ee7fd9f41e8cbb706da38c004fe.tar.gz | |
* Merged Steve M. Robbins patch to replace assertImplementation with assert in hierarchy example.
* Added a TextTestRunner to runner tests. It is based on Michael Feather's version, but have been rewriten.
* Removed traces that printed the test name in TextTestResult while running.
* Added the test name to error and failure report in TextTestResult.
* Updated hierarchy example to use TextTestRunner.
Diffstat (limited to 'src/cppunit/TextTestRunner.cpp')
| -rw-r--r-- | src/cppunit/TextTestRunner.cpp | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/cppunit/TextTestRunner.cpp b/src/cppunit/TextTestRunner.cpp new file mode 100644 index 0000000..aaa6c86 --- /dev/null +++ b/src/cppunit/TextTestRunner.cpp @@ -0,0 +1,106 @@ + +#include <iostream> +#include <cppunit/TestSuite.h> +#include <cppunit/TextTestRunner.h> +#include <cppunit/TextTestResult.h> + +namespace CppUnit { + +TextTestRunner::TextTestRunner() +{ + m_suite = new TestSuite( "All Tests" ); +} + + +TextTestRunner::~TextTestRunner() +{ + delete m_suite; +} + + +/** Adds the specified test. + * + * \param test Test to add. + */ +void +TextTestRunner::addTest( Test *test ) +{ + if ( test != NULL ) + m_suite->addTest( test ); +} + + +/** Runs the named test case. + * + * \param testName Name of the test case to run. If an empty is given, then + * all added test are run. The name must be the name of + * of an added test. + * \param doWait if \c true then the user must press the RETURN key + * before the run() method exit. + */ + +void +TextTestRunner::run( std::string testName, + bool doWait ) +{ + runTestByName( testName ); + wait( doWait ); +} + + +void +TextTestRunner::runTestByName( std::string testName ) +{ + if ( testName.empty() ) + { + runTest( m_suite ); + } + else + { + Test *test = findTestByName( testName ); + if ( test != NULL ) + runTest( test ); + else + { + std::cout << "Test " << testName << " not found." << std::endl; + } + } +} + + +void +TextTestRunner::wait( bool doWait ) +{ + if ( doWait ) + { + std::cout << "<RETURN> to continue" << std::endl; + std::cin.get (); + } +} + + +Test * +TextTestRunner::findTestByName( std::string name ) const +{ + for ( std::vector<Test *>::const_iterator it = m_suite->getTests().begin(); + it != m_suite->getTests().end(); + ++it ) + { + Test *test = *it; + if ( test->getName() == name ) + return test; + } + return NULL; +} + + +void +TextTestRunner::runTest( Test *test ) +{ + TextTestResult result; + test->run( &result ); + std::cout << result << std::endl; +} + + +} // namespace CppUnit |
