Commit 3990c1c7 authored by Tobias Hunger's avatar Tobias Hunger

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: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent eb4d1584
......@@ -29,6 +29,8 @@
#include "pluginmanager_p.h"
#include "pluginspec_p.h"
#include <utils/algorithm.h>
#include <QCoreApplication>
using namespace ExtensionSystem;
......@@ -38,6 +40,7 @@ const char END_OF_OPTIONS[] = "--";
const char *OptionsParser::NO_LOAD_OPTION = "-noload";
const char *OptionsParser::LOAD_OPTION = "-load";
const char *OptionsParser::TEST_OPTION = "-test";
const char *OptionsParser::NOTEST_OPTION = "-notest";
const char *OptionsParser::PROFILE_OPTION = "-profile";
OptionsParser::OptionsParser(const QStringList &args,
......@@ -76,7 +79,7 @@ bool OptionsParser::parse()
if (checkForProfilingOption())
continue;
#ifdef WITH_TESTS
if (checkForTestOption())
if (checkForTestOptions())
continue;
#endif
if (checkForAppOption())
......@@ -104,37 +107,57 @@ bool OptionsParser::checkForEndOfOptions()
return true;
}
bool OptionsParser::checkForTestOption()
bool OptionsParser::checkForTestOptions()
{
if (m_currentArg != QLatin1String(TEST_OPTION))
return false;
if (nextToken(RequiredToken)) {
if (m_currentArg == QLatin1String("all")) {
foreach (PluginSpec *spec, m_pmPrivate->pluginSpecs) {
if (spec && !m_pmPrivate->containsTestSpec(spec))
m_pmPrivate->testSpecs.append(PluginManagerPrivate::TestSpec(spec));
if (m_currentArg == QLatin1String(TEST_OPTION)) {
if (nextToken(RequiredToken)) {
if (m_currentArg == QLatin1String("all")) {
foreach (PluginSpec *spec, m_pmPrivate->pluginSpecs) {
if (spec && !m_pmPrivate->containsTestSpec(spec))
m_pmPrivate->testSpecs.append(PluginManagerPrivate::TestSpec(spec));
}
} else {
QStringList args = m_currentArg.split(QLatin1Char(','));
const QString pluginName = args.takeFirst();
if (PluginSpec *spec = m_pmPrivate->pluginByName(pluginName)) {
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)
*m_errorString = QCoreApplication::translate("PluginManager",
"The plugin \"%1\" does not exist.").arg(pluginName);
m_hasError = true;
}
}
} else {
QStringList args = m_currentArg.split(QLatin1Char(','));
const QString pluginName = args.takeFirst();
if (PluginSpec *spec = m_pmPrivate->pluginByName(pluginName)) {
if (m_pmPrivate->containsTestSpec(spec)) {
}
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 specified twice for testing.").arg(pluginName);
"The plugin \"%1\" is not tested.").arg(m_currentArg);
m_hasError = true;
} else {
m_pmPrivate->testSpecs.append(PluginManagerPrivate::TestSpec(spec, args));
m_pmPrivate->removeTestSpec(spec);
}
} else {
} else {
if (m_errorString)
*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;
}
}
return true;
}
return true;
return false;
}
bool OptionsParser::checkForLoadOption()
......
......@@ -48,6 +48,7 @@ public:
static const char *NO_LOAD_OPTION;
static const char *LOAD_OPTION;
static const char *TEST_OPTION;
static const char *NOTEST_OPTION;
static const char *PROFILE_OPTION;
private:
// return value indicates if the option was processed
......@@ -55,7 +56,7 @@ private:
bool checkForEndOfOptions();
bool checkForLoadOption();
bool checkForNoLoadOption();
bool checkForTestOption();
bool checkForTestOptions();
bool checkForAppOption();
bool checkForPluginOption();
bool checkForProfilingOption();
......
......@@ -721,6 +721,9 @@ void PluginManager::formatOptions(QTextStream &str, int optionIndentation, int d
formatOption(str, QString::fromLatin1(OptionsParser::TEST_OPTION) + QLatin1String(" all"),
QString(), QLatin1String("Run tests from all plugins"),
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
}
......
......@@ -28,6 +28,8 @@
#include "pluginspec.h"
#include <utils/algorithm.h>
#include <QSet>
#include <QStringList>
#include <QObject>
......@@ -87,11 +89,12 @@ public:
bool containsTestSpec(PluginSpec *pluginSpec) const
{
foreach (const TestSpec &testSpec, testSpecs) {
if (testSpec.pluginSpec == pluginSpec)
return true;
}
return false;
return Utils::contains(testSpecs, [pluginSpec](const TestSpec &s) { return s.pluginSpec == pluginSpec; });
}
void removeTestSpec(PluginSpec *pluginSpec)
{
testSpecs = Utils::filtered(testSpecs, [pluginSpec](const TestSpec &s) { return s.pluginSpec != pluginSpec; });
}
QHash<QString, PluginCollection *> pluginCategories;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment