34#include <QtCore/QRegExp>
36#include <QtCore/QMetaEnum>
48 Runner *Runner::s_self = 0L;
49 bool Runner::s_debugCapturingEnabled =
false;
58 QRegExp reQuery(query);
59 QDir dir(folder,
"kunittest_*.la");
64 kDebug() <<
"Looking in folder: " << dir.absolutePath();
67 QStringList modules = dir.entryList();
69 for (
int i = 0; i < modules.count(); ++i )
71 QString module = modules[i];
72 kDebug() <<
"Module: " << dir.absolutePath() +
'/' + module;
74 if ( reQuery.indexIn(module) != -1 )
77 module.truncate(module.length()-3);
88 kDebug() <<
"\tModule doesn't match.";
94 s_debugCapturingEnabled = enabled;
105 return m_registry.count();
144 return globalSkipped;
166 cout <<
"# Running normal tests... #" << endl << endl;
168 Registry::const_iterator it = m_registry.constBegin();
169 for( ; it != m_registry.constEnd(); ++it )
173 cout <<
"# Done with normal tests:" << endl;
174 cout <<
" Total test cases: " << m_registry.count() << endl;
175 cout <<
" Total test steps : " << globalSteps << endl;
176 cout <<
" Total passed test steps (including unexpected) : " << globalPasses << endl;
177 cout <<
" Total unexpected passed test steps : " << globalXPasses << endl;
178 cout <<
" Total failed test steps (including expected) : " << globalFails << endl;
179 cout <<
" Total expected failed test steps : " << globalXFails << endl;
180 cout <<
" Total skipped test steps : " << globalSkipped << endl;
182 unsigned int numTests = m_registry.count();
184 if ( globalFails == 0 )
185 if ( globalXFails == 0 )
186 str = QString(
"All %1 tests passed" ).arg( numTests );
188 str = QString(
"All %1 tests behaved as expected (%2 expected failures)" ).arg( numTests ).arg( globalXFails );
190 if ( globalXPasses == 0 )
191 str = QString(
"%1 of %2 tests failed" ).arg( globalFails ).arg( numTests );
193 str = QString(
"%1 of %2 tests did not behave as expected (%1 unexpected passes)" ).arg( globalFails ).arg( numTests ).arg( globalXPasses );
195 str += QString(
" (%1 tests skipped)" ).arg( globalSkipped );
196 cout << str.toLocal8Bit().constData() << endl;
199 return m_registry.count();
204 Registry::const_iterator it = m_registry.constBegin();
205 for( ; it != m_registry.constEnd(); ++it )
206 if ( QString( it.key() ).startsWith(
prefix) )
212 Tester *test = m_registry.value( name );
215 if ( s_debugCapturingEnabled )
217 cout <<
"KUnitTest_Debug_Start[" << name <<
"]" << endl;
223 if ( s_debugCapturingEnabled )
225 cout <<
"KUnitTest_Debug_End[" << name <<
"]" << endl << endl << flush;
234 if ( test->inherits(
"KUnitTest::SlotTester") )
241 numXFail += res->
xfails();
258 globalPasses += numPass;
259 globalFails += numFail;
260 globalXFails += numXFail;
261 globalXPasses += numXPass;
262 globalSkipped += numSkip;
264 cout << name <<
" - ";
265 cout << numPass <<
" test" << ( ( 1 == numPass )?
"":
"s") <<
" passed";
267 cout <<
" (" << numXPass <<
" unexpected pass" << ( ( 1 == numXPass )?
"":
"es") <<
")";
269 cout <<
", " << numFail <<
" test" << ( ( 1 == numFail )?
"":
"s") <<
" failed";
270 if ( 0 < numXFail ) {
271 cout <<
" (" << numXFail <<
" expected failure" << ( ( 1 == numXFail )?
"":
"s") <<
")";
274 cout <<
"; also " << numSkip <<
" skipped";
278 if ( 0 < numXPass ) {
279 cout <<
" Unexpected pass" << ( ( 1 == numXPass )?
"":
"es") <<
":" << endl;
281 for ( QStringList::Iterator itr = list.begin(); itr != list.end(); ++itr ) {
282 cout <<
"\t" << (*itr).toLatin1().constData() << endl;
285 if ( 0 < (numFail - numXFail) ) {
286 cout <<
" Unexpected failure" << ( ( 1 == numFail )?
"":
"s") <<
":" << endl;
288 for ( QStringList::Iterator itr = list.begin(); itr != list.end(); ++itr ) {
289 cout <<
"\t" << (*itr).toLatin1().constData() << endl;
292 if ( 0 < numXFail ) {
293 cout <<
" Expected failure" << ( ( 1 == numXFail)?
"":
"s") <<
":" << endl;
295 for ( QStringList::Iterator itr = list.begin(); itr != list.end(); ++itr ) {
296 cout <<
"\t" << (*itr).toLatin1().constData() << endl;
300 cout <<
" Skipped test" << ( ( 1 == numSkip )?
"":
"s") <<
":" << endl;
302 for ( QStringList::Iterator itr = list.begin(); itr != list.end(); ++itr ) {
303 cout <<
"\t" << (*itr).toLatin1().constData() << endl;
T * create(const QString &keyword, QObject *parent=0, const QVariantList &args=QVariantList())
QString errorString() const
KPluginFactory * factory()
bool addResourceDir(const char *type, const QString &absdir, bool priority=true)
int numberOfFailedTests() const
static void loadModules(const QString &folder, const QString &query)
void runTest(const char *name)
int numberOfSkippedTests() const
void runMatchingTests(const QString &prefix)
int numberOfExpectedFailures() const
int numberOfPassedTests() const
static void registerTester(const char *name, Tester *test)
int numberOfTests() const
void finished(const char *name, Tester *test)
static void setDebugCapturingEnabled(bool enabled)
const TestResultsList & resultsList() const
Return the list of results - used internally by Runner.
QStringList skipList() const
QStringList xfailList() const
QStringList errorList() const
QStringList xpassList() const
int testsFinished() const
virtual TestResults * results() const
virtual void allTests()=0
Copyright (C) 2005 Jeroen Wijnhout Jeroen.Wijnhout@kdemail.net