From 953be3d3b25baf7e04d11f04284975843fc6c59b Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Tue, 28 Jul 2015 12:29:24 +0200 Subject: [PATCH] CppEditor: Tests: Revive tests depending on loaded projects The tests were broken since the qmake project manager switched to an asynchronous loading. We can't simply check if there are loaded projects because at time the tests are executed there are not any. The user has to set some environment variable in order to make these tests run. Change-Id: I94778578dea5562ee5dad2c565c7b877c18996a7 Reviewed-by: Erik Verbruggen --- src/plugins/cppeditor/cppeditorplugin.h | 13 ++++- .../cppeditor/fileandtokenactions_test.cpp | 49 ++++++++----------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/plugins/cppeditor/cppeditorplugin.h b/src/plugins/cppeditor/cppeditorplugin.h index 8745dc9bb4c..a4f4304b0cf 100644 --- a/src/plugins/cppeditor/cppeditorplugin.h +++ b/src/plugins/cppeditor/cppeditorplugin.h @@ -213,8 +213,17 @@ private slots: void test_includehierarchy_data(); void test_includehierarchy(); - // The following tests depend on the projects that are loaded on startup - // and will be skipped in case no projects are loaded. + // The following tests operate on a project and require special invocation: + // + // Ensure that the project is properly configured for a given settings path: + // $ ./qtcreator -settingspath /your/settings/path /path/to/project + // + // ...and that it builds, which might prevent blocking dialogs for not + // existing files (e.g. ui_*.h). + // + // Run a test: + // $ export QTC_TEST_WAIT_FOR_LOADED_PROJECT=1 + // $ ./qtcreator -settingspath /your/settings/path -test CppEditor,test_openEachFile /path/to/project void test_openEachFile(); void test_switchHeaderSourceOnEachFile(); void test_moveTokenWiseThroughEveryFile(); diff --git a/src/plugins/cppeditor/fileandtokenactions_test.cpp b/src/plugins/cppeditor/fileandtokenactions_test.cpp index 7e3e463589c..63ab5cc6882 100644 --- a/src/plugins/cppeditor/fileandtokenactions_test.cpp +++ b/src/plugins/cppeditor/fileandtokenactions_test.cpp @@ -118,17 +118,8 @@ private: CppEditor *editor, const Actions &tokenActions); static void undoAllChangesAndCloseAllEditors(); - - /// This function expects: - /// (1) Only Qt4 projects are loaded (qmake in PATH should point to Qt4/bin). - /// (2) No *.pro.user file exists for the projects. - static void configureAllProjects(const QList > &projects); - - static bool allProjectsConfigured; }; -bool TestActionsTestCase::allProjectsConfigured = false; - typedef TestActionsTestCase::Actions Actions; typedef TestActionsTestCase::ActionPointer ActionPointer; @@ -137,18 +128,35 @@ Actions singleAction(const ActionPointer &action) return Actions() << action; } +static bool waitUntilAProjectIsLoaded(int timeOutInMs = 30000) +{ + QElapsedTimer timer; + timer.start(); + + while (timer.elapsed() < timeOutInMs) { + if (!CppModelManager::instance()->projectInfos().isEmpty()) + return true; + + QCoreApplication::processEvents(); + QThread::msleep(20); + } + + return false; +} + TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Actions &fileActions) : Tests::TestCase(/*runGarbageCollector=*/false) { QVERIFY(succeededSoFar()); + if (qgetenv("QTC_TEST_WAIT_FOR_LOADED_PROJECT") != "1") + QSKIP("Environment variable QTC_TEST_WAIT_FOR_LOADED_PROJECT=1 not set."); + QVERIFY(waitUntilAProjectIsLoaded()); + // Collect files to process QStringList filesToOpen; QList > projects; - const QList projectInfos - = m_modelManager->projectInfos(); - if (projectInfos.isEmpty()) - QSKIP("No project(s) loaded. Test operates only on loaded projects."); + const QList projectInfos = m_modelManager->projectInfos(); foreach (const ProjectInfo &info, projectInfos) { QPointer project = info.project(); @@ -160,12 +168,6 @@ TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Acti filesToOpen << sourceFile; } - // Configure all projects on first execution of this function (= very first test) - if (!TestActionsTestCase::allProjectsConfigured) { - configureAllProjects(projects); - TestActionsTestCase::allProjectsConfigured = true; - } - Utils::sort(filesToOpen); // Process all files from the projects @@ -311,15 +313,6 @@ void TestActionsTestCase::undoAllChangesAndCloseAllEditors() QCOMPARE(DocumentModel::openedDocuments().size(), 0); } -void TestActionsTestCase::configureAllProjects(const QList > - &projects) -{ - foreach (const QPointer &project, projects) { - qDebug() << "*** Configuring project" << project->displayName(); - project->configureAsExampleProject(QStringList()); - } -} - class NoOpTokenAction : public TestActionsTestCase::AbstractAction { public: