forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user