forked from qt-creator/qt-creator
PluginManager: Clean up
* Remove unused testDataDirectory() * Move startTests() to PluginManagerPrivate Change-Id: I3ad582a7ea35c8f08d1455ea3536baed88ecb2ad Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com> Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
@@ -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
|
* \internal
|
||||||
*/
|
*/
|
||||||
@@ -788,21 +703,6 @@ bool PluginManager::testRunRequested()
|
|||||||
return !d->testSpecs.isEmpty();
|
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
|
Creates a profiling entry showing the elapsed time if profiling is
|
||||||
activated.
|
activated.
|
||||||
@@ -881,7 +781,7 @@ void PluginManagerPrivate::nextDelayedInitialize()
|
|||||||
emit q->initializationDone();
|
emit q->initializationDone();
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
if (q->testRunRequested())
|
if (q->testRunRequested())
|
||||||
q->startTests();
|
startTests();
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
delayedInitializeTimer->start();
|
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
|
\internal
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -145,7 +145,6 @@ public:
|
|||||||
static QString serializedArguments();
|
static QString serializedArguments();
|
||||||
|
|
||||||
static bool testRunRequested();
|
static bool testRunRequested();
|
||||||
static QString testDataDirectory();
|
|
||||||
|
|
||||||
static void profilingReport(const char *what, const PluginSpec *spec = 0);
|
static void profilingReport(const char *what, const PluginSpec *spec = 0);
|
||||||
|
|
||||||
@@ -162,8 +161,6 @@ public slots:
|
|||||||
void remoteArguments(const QString &serializedArguments, QObject *socket);
|
void remoteArguments(const QString &serializedArguments, QObject *socket);
|
||||||
void shutdown();
|
void shutdown();
|
||||||
|
|
||||||
private slots:
|
|
||||||
void startTests();
|
|
||||||
friend class Internal::PluginManagerPrivate;
|
friend class Internal::PluginManagerPrivate;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -148,6 +148,8 @@ private:
|
|||||||
QList<PluginSpec *> &circularityCheckQueue);
|
QList<PluginSpec *> &circularityCheckQueue);
|
||||||
void stopAll();
|
void stopAll();
|
||||||
void deleteAll();
|
void deleteAll();
|
||||||
|
|
||||||
|
void startTests();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user