summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@theqtcompany.com>2015-07-28 12:29:24 +0200
committerNikolai Kosjar <nikolai.kosjar@theqtcompany.com>2015-07-29 08:53:45 +0000
commit953be3d3b25baf7e04d11f04284975843fc6c59b (patch)
tree765ee8d41957a3a50501498382b1ef93a41b7a91
parentdb3dc92202bfb580d23045bd880bc3c18a43ffa3 (diff)
downloadqt-creator-953be3d3b25baf7e04d11f04284975843fc6c59b.tar.gz
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 <erik.verbruggen@theqtcompany.com>
-rw-r--r--src/plugins/cppeditor/cppeditorplugin.h13
-rw-r--r--src/plugins/cppeditor/fileandtokenactions_test.cpp49
2 files changed, 32 insertions, 30 deletions
diff --git a/src/plugins/cppeditor/cppeditorplugin.h b/src/plugins/cppeditor/cppeditorplugin.h
index 8745dc9bb4..a4f4304b0c 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 7e3e463589..63ab5cc688 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<QPointer<ProjectExplorer::Project> > &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<QPointer<ProjectExplorer::Project> > projects;
- const QList<ProjectInfo> projectInfos
- = m_modelManager->projectInfos();
- if (projectInfos.isEmpty())
- QSKIP("No project(s) loaded. Test operates only on loaded projects.");
+ const QList<ProjectInfo> projectInfos = m_modelManager->projectInfos();
foreach (const ProjectInfo &info, projectInfos) {
QPointer<ProjectExplorer::Project> 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<QPointer<ProjectExplorer::Project> >
- &projects)
-{
- foreach (const QPointer<ProjectExplorer::Project> &project, projects) {
- qDebug() << "*** Configuring project" << project->displayName();
- project->configureAsExampleProject(QStringList());
- }
-}
-
class NoOpTokenAction : public TestActionsTestCase::AbstractAction
{
public: