Add "-notest" option that prevents a plugin from being tested

This is similar to "-noload" and prevents a plugin from being loaded
for testing. Nice to blacklist some problematic plugins.

Change-Id: Ib273d244333a9d275969c9608e556a11b7518386
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
Tobias Hunger
2016-02-11 11:53:31 +01:00
parent eb4d1584b6
commit 3990c1c7ed
4 changed files with 56 additions and 26 deletions

View File

@@ -29,6 +29,8 @@
#include "pluginmanager_p.h" #include "pluginmanager_p.h"
#include "pluginspec_p.h" #include "pluginspec_p.h"
#include <utils/algorithm.h>
#include <QCoreApplication> #include <QCoreApplication>
using namespace ExtensionSystem; using namespace ExtensionSystem;
@@ -38,6 +40,7 @@ const char END_OF_OPTIONS[] = "--";
const char *OptionsParser::NO_LOAD_OPTION = "-noload"; const char *OptionsParser::NO_LOAD_OPTION = "-noload";
const char *OptionsParser::LOAD_OPTION = "-load"; const char *OptionsParser::LOAD_OPTION = "-load";
const char *OptionsParser::TEST_OPTION = "-test"; const char *OptionsParser::TEST_OPTION = "-test";
const char *OptionsParser::NOTEST_OPTION = "-notest";
const char *OptionsParser::PROFILE_OPTION = "-profile"; const char *OptionsParser::PROFILE_OPTION = "-profile";
OptionsParser::OptionsParser(const QStringList &args, OptionsParser::OptionsParser(const QStringList &args,
@@ -76,7 +79,7 @@ bool OptionsParser::parse()
if (checkForProfilingOption()) if (checkForProfilingOption())
continue; continue;
#ifdef WITH_TESTS #ifdef WITH_TESTS
if (checkForTestOption()) if (checkForTestOptions())
continue; continue;
#endif #endif
if (checkForAppOption()) if (checkForAppOption())
@@ -104,37 +107,57 @@ bool OptionsParser::checkForEndOfOptions()
return true; return true;
} }
bool OptionsParser::checkForTestOption() bool OptionsParser::checkForTestOptions()
{ {
if (m_currentArg != QLatin1String(TEST_OPTION)) if (m_currentArg == QLatin1String(TEST_OPTION)) {
return false; if (nextToken(RequiredToken)) {
if (nextToken(RequiredToken)) { if (m_currentArg == QLatin1String("all")) {
if (m_currentArg == QLatin1String("all")) { foreach (PluginSpec *spec, m_pmPrivate->pluginSpecs) {
foreach (PluginSpec *spec, m_pmPrivate->pluginSpecs) { if (spec && !m_pmPrivate->containsTestSpec(spec))
if (spec && !m_pmPrivate->containsTestSpec(spec)) m_pmPrivate->testSpecs.append(PluginManagerPrivate::TestSpec(spec));
m_pmPrivate->testSpecs.append(PluginManagerPrivate::TestSpec(spec)); }
} } else {
} else { QStringList args = m_currentArg.split(QLatin1Char(','));
QStringList args = m_currentArg.split(QLatin1Char(',')); const QString pluginName = args.takeFirst();
const QString pluginName = args.takeFirst(); if (PluginSpec *spec = m_pmPrivate->pluginByName(pluginName)) {
if (PluginSpec *spec = m_pmPrivate->pluginByName(pluginName)) { if (m_pmPrivate->containsTestSpec(spec)) {
if (m_pmPrivate->containsTestSpec(spec)) { if (m_errorString)
*m_errorString = QCoreApplication::translate("PluginManager",
"The plugin \"%1\" is specified twice for testing.").arg(pluginName);
m_hasError = true;
} else {
m_pmPrivate->testSpecs.append(PluginManagerPrivate::TestSpec(spec, args));
}
} else {
if (m_errorString) if (m_errorString)
*m_errorString = QCoreApplication::translate("PluginManager", *m_errorString = QCoreApplication::translate("PluginManager",
"The plugin \"%1\" is specified twice for testing.").arg(pluginName); "The plugin \"%1\" does not exist.").arg(pluginName);
m_hasError = true;
}
}
}
return true;
} else if (m_currentArg == QLatin1String(NOTEST_OPTION)) {
if (nextToken(RequiredToken)) {
if (PluginSpec *spec = m_pmPrivate->pluginByName(m_currentArg)) {
if (!m_pmPrivate->containsTestSpec(spec)) {
if (m_errorString)
*m_errorString = QCoreApplication::translate("PluginManager",
"The plugin \"%1\" is not tested.").arg(m_currentArg);
m_hasError = true; m_hasError = true;
} else { } else {
m_pmPrivate->testSpecs.append(PluginManagerPrivate::TestSpec(spec, args)); m_pmPrivate->removeTestSpec(spec);
} }
} else { } else {
if (m_errorString) if (m_errorString)
*m_errorString = QCoreApplication::translate("PluginManager", *m_errorString = QCoreApplication::translate("PluginManager",
"The plugin \"%1\" does not exist.").arg(pluginName); "The plugin \"%1\" does not exist.").arg(m_currentArg);
m_hasError = true; m_hasError = true;
} }
} }
return true;
} }
return true; return false;
} }
bool OptionsParser::checkForLoadOption() bool OptionsParser::checkForLoadOption()

View File

@@ -48,6 +48,7 @@ public:
static const char *NO_LOAD_OPTION; static const char *NO_LOAD_OPTION;
static const char *LOAD_OPTION; static const char *LOAD_OPTION;
static const char *TEST_OPTION; static const char *TEST_OPTION;
static const char *NOTEST_OPTION;
static const char *PROFILE_OPTION; static const char *PROFILE_OPTION;
private: private:
// return value indicates if the option was processed // return value indicates if the option was processed
@@ -55,7 +56,7 @@ private:
bool checkForEndOfOptions(); bool checkForEndOfOptions();
bool checkForLoadOption(); bool checkForLoadOption();
bool checkForNoLoadOption(); bool checkForNoLoadOption();
bool checkForTestOption(); bool checkForTestOptions();
bool checkForAppOption(); bool checkForAppOption();
bool checkForPluginOption(); bool checkForPluginOption();
bool checkForProfilingOption(); bool checkForProfilingOption();

View File

@@ -721,6 +721,9 @@ void PluginManager::formatOptions(QTextStream &str, int optionIndentation, int d
formatOption(str, QString::fromLatin1(OptionsParser::TEST_OPTION) + QLatin1String(" all"), formatOption(str, QString::fromLatin1(OptionsParser::TEST_OPTION) + QLatin1String(" all"),
QString(), QLatin1String("Run tests from all plugins"), QString(), QLatin1String("Run tests from all plugins"),
optionIndentation, descriptionIndentation); optionIndentation, descriptionIndentation);
formatOption(str, QString::fromLatin1(OptionsParser::NOTEST_OPTION),
QLatin1String("plugin"), QLatin1String("Exclude all of the plugin's tests from the test run"),
optionIndentation, descriptionIndentation);
#endif #endif
} }

View File

@@ -28,6 +28,8 @@
#include "pluginspec.h" #include "pluginspec.h"
#include <utils/algorithm.h>
#include <QSet> #include <QSet>
#include <QStringList> #include <QStringList>
#include <QObject> #include <QObject>
@@ -87,11 +89,12 @@ public:
bool containsTestSpec(PluginSpec *pluginSpec) const bool containsTestSpec(PluginSpec *pluginSpec) const
{ {
foreach (const TestSpec &testSpec, testSpecs) { return Utils::contains(testSpecs, [pluginSpec](const TestSpec &s) { return s.pluginSpec == pluginSpec; });
if (testSpec.pluginSpec == pluginSpec) }
return true;
} void removeTestSpec(PluginSpec *pluginSpec)
return false; {
testSpecs = Utils::filtered(testSpecs, [pluginSpec](const TestSpec &s) { return s.pluginSpec != pluginSpec; });
} }
QHash<QString, PluginCollection *> pluginCategories; QHash<QString, PluginCollection *> pluginCategories;