diff --git a/src/libs/extensionsystem/pluginmanager.cpp b/src/libs/extensionsystem/pluginmanager.cpp index 4e688a5cd4b..2798f2314e6 100644 --- a/src/libs/extensionsystem/pluginmanager.cpp +++ b/src/libs/extensionsystem/pluginmanager.cpp @@ -695,91 +695,6 @@ void PluginManager::formatPluginVersions(QTextStream &str) } } -void PluginManager::startTests() -{ - if (PluginManager::hasError()) { - qWarning("Errors occurred while loading plugins, skipping test run. " - "For details, start without \"-test\" option."); - QTimer::singleShot(1, QCoreApplication::instance(), SLOT(quit())); - return; - } - -#ifdef WITH_TESTS - foreach (const PluginManagerPrivate::TestSpec &testSpec, d->testSpecs) { - const PluginSpec * const pluginSpec = testSpec.pluginSpec; - if (!pluginSpec->plugin()) - continue; - - // Collect all test functions of the plugin. - QStringList allTestFunctions; - const QMetaObject *metaObject = pluginSpec->plugin()->metaObject(); - - for (int i = metaObject->methodOffset(); i < metaObject->methodCount(); ++i) { - const QByteArray signature = metaObject->method(i).methodSignature(); - if (signature.startsWith("test") && !signature.endsWith("_data()")) { - const QString method = QString::fromLatin1(signature); - const QString methodName = method.left(method.size() - 2); - allTestFunctions.append(methodName); - } - } - - QStringList testFunctionsToExecute; - - // User did not specify any test functions, so add every test function. - if (testSpec.testFunctions.isEmpty()) { - testFunctionsToExecute = allTestFunctions; - - // User specified test functions. Add them if they are valid. - } else { - foreach (const QString &userTestFunction, testSpec.testFunctions) { - // There might be a test data suffix like in "testfunction:testdata1". - QString testFunctionName = userTestFunction; - QString testDataSuffix; - const int index = testFunctionName.indexOf(QLatin1Char(':')); - if (index != -1) { - testDataSuffix = testFunctionName.mid(index); - testFunctionName = testFunctionName.left(index); - } - - const QRegExp regExp(testFunctionName, Qt::CaseSensitive, QRegExp::Wildcard); - QStringList matchingFunctions; - foreach (const QString &testFunction, allTestFunctions) { - if (regExp.exactMatch(testFunction)) - matchingFunctions.append(testFunction); - } - if (!matchingFunctions.isEmpty()) { - // If the specified test data is invalid, the QTest framework will - // print a reasonable error message for us. - foreach (const QString &matchingFunction, matchingFunctions) - testFunctionsToExecute.append(matchingFunction + testDataSuffix); - } else { - QTextStream out(stdout); - out << "No test function matches \"" << testFunctionName - << "\" for plugin \"" << pluginSpec->name() << "\"." << endl - << " Available test functions for plugin \"" << pluginSpec->name() - << "\" are:" << endl; - foreach (const QString &testFunction, allTestFunctions) - out << " " << testFunction << endl; - } - } - } - - // Don't run QTest::qExec without any test functions, that'd run - // *all* slots as tests. - if (!testFunctionsToExecute.isEmpty()) { - // QTest::qExec() expects basically QCoreApplication::arguments(), - QStringList qExecArguments = QStringList() - << QLatin1String("arg0") // fake application name - << QLatin1String("-maxwarnings") << QLatin1String("0"); // unlimit output - qExecArguments << testFunctionsToExecute; - QTest::qExec(pluginSpec->plugin(), qExecArguments); - } - } - if (!d->testSpecs.isEmpty()) - QTimer::singleShot(1, QCoreApplication::instance(), SLOT(quit())); -#endif -} - /*! * \internal */ @@ -788,21 +703,6 @@ bool PluginManager::testRunRequested() return !d->testSpecs.isEmpty(); } -/*! - * \internal - */ -QString PluginManager::testDataDirectory() -{ - QByteArray ba = qgetenv("QTCREATOR_TEST_DIR"); - QString s = QString::fromLocal8Bit(ba.constData(), ba.size()); - if (s.isEmpty()) { - s = QLatin1String(IDE_TEST_DIR); - s.append(QLatin1String("/tests")); - } - s = QDir::cleanPath(s); - return s; -} - /*! Creates a profiling entry showing the elapsed time if profiling is activated. @@ -881,7 +781,7 @@ void PluginManagerPrivate::nextDelayedInitialize() emit q->initializationDone(); #ifdef WITH_TESTS if (q->testRunRequested()) - q->startTests(); + startTests(); #endif } else { delayedInitializeTimer->start(); @@ -976,6 +876,91 @@ void PluginManagerPrivate::deleteAll() } } +void PluginManagerPrivate::startTests() +{ + if (PluginManager::hasError()) { + qWarning("Errors occurred while loading plugins, skipping test run. " + "For details, start without \"-test\" option."); + QTimer::singleShot(1, QCoreApplication::instance(), SLOT(quit())); + return; + } + +#ifdef WITH_TESTS + foreach (const PluginManagerPrivate::TestSpec &testSpec, testSpecs) { + const PluginSpec * const pluginSpec = testSpec.pluginSpec; + if (!pluginSpec->plugin()) + continue; + + // Collect all test functions of the plugin. + QStringList allTestFunctions; + const QMetaObject *metaObject = pluginSpec->plugin()->metaObject(); + + for (int i = metaObject->methodOffset(); i < metaObject->methodCount(); ++i) { + const QByteArray signature = metaObject->method(i).methodSignature(); + if (signature.startsWith("test") && !signature.endsWith("_data()")) { + const QString method = QString::fromLatin1(signature); + const QString methodName = method.left(method.size() - 2); + allTestFunctions.append(methodName); + } + } + + QStringList testFunctionsToExecute; + + // User did not specify any test functions, so add every test function. + if (testSpec.testFunctions.isEmpty()) { + testFunctionsToExecute = allTestFunctions; + + // User specified test functions. Add them if they are valid. + } else { + foreach (const QString &userTestFunction, testSpec.testFunctions) { + // There might be a test data suffix like in "testfunction:testdata1". + QString testFunctionName = userTestFunction; + QString testDataSuffix; + const int index = testFunctionName.indexOf(QLatin1Char(':')); + if (index != -1) { + testDataSuffix = testFunctionName.mid(index); + testFunctionName = testFunctionName.left(index); + } + + const QRegExp regExp(testFunctionName, Qt::CaseSensitive, QRegExp::Wildcard); + QStringList matchingFunctions; + foreach (const QString &testFunction, allTestFunctions) { + if (regExp.exactMatch(testFunction)) + matchingFunctions.append(testFunction); + } + if (!matchingFunctions.isEmpty()) { + // If the specified test data is invalid, the QTest framework will + // print a reasonable error message for us. + foreach (const QString &matchingFunction, matchingFunctions) + testFunctionsToExecute.append(matchingFunction + testDataSuffix); + } else { + QTextStream out(stdout); + out << "No test function matches \"" << testFunctionName + << "\" for plugin \"" << pluginSpec->name() << "\"." << endl + << " Available test functions for plugin \"" << pluginSpec->name() + << "\" are:" << endl; + foreach (const QString &testFunction, allTestFunctions) + out << " " << testFunction << endl; + } + } + } + + // Don't run QTest::qExec without any test functions, that'd run + // *all* slots as tests. + if (!testFunctionsToExecute.isEmpty()) { + // QTest::qExec() expects basically QCoreApplication::arguments(), + QStringList qExecArguments = QStringList() + << QLatin1String("arg0") // fake application name + << QLatin1String("-maxwarnings") << QLatin1String("0"); // unlimit output + qExecArguments << testFunctionsToExecute; + QTest::qExec(pluginSpec->plugin(), qExecArguments); + } + } + if (!testSpecs.isEmpty()) + QTimer::singleShot(1, QCoreApplication::instance(), SLOT(quit())); +#endif +} + /*! \internal */ diff --git a/src/libs/extensionsystem/pluginmanager.h b/src/libs/extensionsystem/pluginmanager.h index 78eadc5932c..ea7e7267f32 100644 --- a/src/libs/extensionsystem/pluginmanager.h +++ b/src/libs/extensionsystem/pluginmanager.h @@ -145,7 +145,6 @@ public: static QString serializedArguments(); static bool testRunRequested(); - static QString testDataDirectory(); static void profilingReport(const char *what, const PluginSpec *spec = 0); @@ -162,8 +161,6 @@ public slots: void remoteArguments(const QString &serializedArguments, QObject *socket); void shutdown(); -private slots: - void startTests(); friend class Internal::PluginManagerPrivate; }; diff --git a/src/libs/extensionsystem/pluginmanager_p.h b/src/libs/extensionsystem/pluginmanager_p.h index 8e2872a4862..150fa65f592 100644 --- a/src/libs/extensionsystem/pluginmanager_p.h +++ b/src/libs/extensionsystem/pluginmanager_p.h @@ -148,6 +148,8 @@ private: QList &circularityCheckQueue); void stopAll(); void deleteAll(); + + void startTests(); }; } // namespace Internal