summaryrefslogtreecommitdiff
path: root/src/libs/extensionsystem/pluginmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/extensionsystem/pluginmanager.cpp')
-rw-r--r--src/libs/extensionsystem/pluginmanager.cpp97
1 files changed, 67 insertions, 30 deletions
diff --git a/src/libs/extensionsystem/pluginmanager.cpp b/src/libs/extensionsystem/pluginmanager.cpp
index de8c7b6153..caa9078e21 100644
--- a/src/libs/extensionsystem/pluginmanager.cpp
+++ b/src/libs/extensionsystem/pluginmanager.cpp
@@ -133,7 +133,7 @@ enum { debugLeaks = 0 };
invokable methods of the "provider" object in the object pool.
The \c{ExtensionSystem::invoke} function template encapsulates
- {ExtensionSystem::Invoker} construction for the common case where
+ {ExtensionSystem::Invoker} construction for the common case where
the success of the call is not checked.
\code
@@ -335,9 +335,8 @@ bool PluginManager::hasError()
{
foreach (PluginSpec *spec, plugins()) {
// only show errors on startup if plugin is enabled.
- if (spec->hasError() && spec->isEnabled() && !spec->isDisabledIndirectly()) {
+ if (spec->hasError() && spec->isEnabled() && !spec->isDisabledIndirectly())
return true;
- }
}
return false;
}
@@ -505,11 +504,10 @@ QString PluginManager::serializedArguments()
foreach (const QString &argument, m_instance->d->arguments) {
rc += separator;
const QFileInfo fi(argument);
- if (fi.exists() && fi.isRelative()) {
+ if (fi.exists() && fi.isRelative())
rc += fi.absoluteFilePath();
- } else {
+ else
rc += argument;
- }
}
}
return rc;
@@ -618,8 +616,11 @@ void PluginManager::formatOptions(QTextStream &str, int optionIndentation, int d
QString(), QLatin1String("Profile plugin loading"),
optionIndentation, descriptionIndentation);
#ifdef WITH_TESTS
- formatOption(str, QLatin1String(OptionsParser::TEST_OPTION),
- QLatin1String("plugin|all"), QLatin1String("Run plugin's tests"),
+ formatOption(str, QString::fromLatin1(OptionsParser::TEST_OPTION)
+ + QLatin1String(" <plugin> [testfunction[:testdata]]..."), QString(),
+ QLatin1String("Run plugin's tests"), optionIndentation, descriptionIndentation);
+ formatOption(str, QString::fromLatin1(OptionsParser::TEST_OPTION) + QLatin1String(" all"),
+ QString(), QLatin1String("Run tests from all plugins"),
optionIndentation, descriptionIndentation);
#endif
}
@@ -664,28 +665,67 @@ void PluginManager::formatPluginVersions(QTextStream &str)
void PluginManager::startTests()
{
#ifdef WITH_TESTS
- foreach (PluginSpec *pluginSpec, d->testSpecs) {
+ foreach (const PluginManagerPrivate::TestSpec &testSpec, d->testSpecs) {
+ const PluginSpec * const pluginSpec = testSpec.pluginSpec;
if (!pluginSpec->plugin())
continue;
- const QMetaObject *mo = pluginSpec->plugin()->metaObject();
- QStringList methods;
- methods.append("arg0");
- // We only want slots starting with "test"
- for (int i = mo->methodOffset(); i < mo->methodCount(); ++i) {
+
+ // Collect all test functions/methods of the plugin.
+ QStringList allTestFunctions;
+ const QMetaObject *metaObject = pluginSpec->plugin()->metaObject();
+
+ for (int i = metaObject->methodOffset(); i < metaObject->methodCount(); ++i) {
#if QT_VERSION >= 0x050000
- const QByteArray signature = mo->method(i).methodSignature();
+ const QByteArray signature = metaObject->method(i).methodSignature();
#else
- const QByteArray signature = mo->method(i).signature();
+ const QByteArray signature = metaObject->method(i).signature();
#endif
if (signature.startsWith("test") && !signature.endsWith("_data()")) {
const QString method = QString::fromLatin1(signature);
- methods.append(method.left(method.size()-2));
+ 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;
+ const int index = testFunctionName.indexOf(QLatin1Char(':'));
+ if (index != -1)
+ testFunctionName = testFunctionName.left(index);
+
+ if (allTestFunctions.contains(testFunctionName)) {
+ // If the specified test data is invalid, the QTest framework will
+ // print a reasonable error message for us.
+ testFunctionsToExecute.append(userTestFunction);
+ } else {
+ QTextStream out(stdout);
+ out << "Unknown test function \"" << testFunctionName
+ << "\" for plugin \"" << pluginSpec->name() << "\"." << endl
+ << " Available test functions for plugin \"" << pluginSpec->name()
+ << "\" are:" << endl;
+ foreach (const QString &testFunction, allTestFunctions)
+ out << " " << testFunction << endl;
+ }
}
}
+
+ // QTest::qExec() expects basically QCoreApplication::arguments(),
+ // so prepend a fake argument for the application name.
+ testFunctionsToExecute.prepend(QLatin1String("arg0"));
+
// Don't run QTest::qExec with only one argument, that'd run
// *all* slots as tests.
- if (methods.size() > 1)
- QTest::qExec(pluginSpec->plugin(), methods);
+ if (testFunctionsToExecute.size() > 1)
+ QTest::qExec(pluginSpec->plugin(), testFunctionsToExecute);
}
if (!d->testSpecs.isEmpty())
QTimer::singleShot(1, QCoreApplication::instance(), SLOT(quit()));
@@ -710,8 +750,8 @@ QString PluginManager::testDataDirectory()
QByteArray ba = qgetenv("QTCREATOR_TEST_DIR");
QString s = QString::fromLocal8Bit(ba.constData(), ba.size());
if (s.isEmpty()) {
- s = IDE_TEST_DIR;
- s.append("/tests");
+ s = QLatin1String(IDE_TEST_DIR);
+ s.append(QLatin1String("/tests"));
}
s = QDir::cleanPath(s);
return s;
@@ -840,7 +880,7 @@ void PluginManagerPrivate::writeSettings()
return;
QStringList tempDisabledPlugins;
QStringList tempForceEnabledPlugins;
- foreach(PluginSpec *spec, pluginSpecs) {
+ foreach (PluginSpec *spec, pluginSpecs) {
if (!spec->isDisabledByDefault() && !spec->isEnabled())
tempDisabledPlugins.append(spec->name());
if (spec->isDisabledByDefault() && spec->isEnabled())
@@ -857,9 +897,8 @@ void PluginManagerPrivate::writeSettings()
*/
void PluginManagerPrivate::readSettings()
{
- if (globalSettings) {
+ if (globalSettings)
defaultDisabledPlugins = globalSettings->value(QLatin1String(C_IGNORED_PLUGINS)).toStringList();
- }
if (settings) {
disabledPlugins = settings->value(QLatin1String(C_IGNORED_PLUGINS)).toStringList();
forceEnabledPlugins = settings->value(QLatin1String(C_FORCEENABLED_PLUGINS)).toStringList();
@@ -996,9 +1035,8 @@ void PluginManagerPrivate::shutdown()
shutdownEventLoop->exec();
}
deleteAll();
- if (!allObjects.isEmpty()) {
+ if (!allObjects.isEmpty())
qDebug() << "There are" << allObjects.size() << "objects left in the plugin manager pool: " << allObjects;
- }
}
/*!
@@ -1173,7 +1211,7 @@ void PluginManagerPrivate::readPluginPaths()
searchPaths << subdir.absoluteFilePath();
}
defaultCollection = new PluginCollection(QString());
- pluginCategories.insert("", defaultCollection);
+ pluginCategories.insert(QString(), defaultCollection);
foreach (const QString &specFile, specFiles) {
PluginSpec *spec = new PluginSpec;
@@ -1270,11 +1308,10 @@ void PluginManagerPrivate::profilingReport(const char *what, const PluginSpec *s
const int absoluteElapsedMS = m_profileTimer->elapsed();
const int elapsedMS = absoluteElapsedMS - m_profileElapsedMS;
m_profileElapsedMS = absoluteElapsedMS;
- if (spec) {
+ if (spec)
qDebug("%-22s %-22s %8dms (%8dms)", what, qPrintable(spec->name()), absoluteElapsedMS, elapsedMS);
- } else {
+ else
qDebug("%-45s %8dms (%8dms)", what, absoluteElapsedMS, elapsedMS);
- }
}
}