aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2017-07-07 15:16:48 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2017-07-10 13:43:39 +0000
commit77e407ef6b63253154ed692f69a2fac53d8c3fdf (patch)
tree80cf61d90a7bb0f2818ae6369f5b08764f417030 /tests
parent709bcc3efcf444639971d16c5e6d685d23fba464 (diff)
Fix behavior with corrupt or outdated build graphs
Commit b6bf17cfd1 introduced a glitch in that a rebuild using a build graph whose magic string does not match would throw an error at the first attempt and silently succeed at the second one. The new behavior is the same as for attempts to rebuild with property changes: A plain "build" fails, a "resolve" does the trick. Some more code had to move from the command line parser to the loader to achieve this. Change-Id: I906748cc1686c0c5d413d9451ec9e2aa26ea2035 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/blackbox/testdata/build-graph-versions/build-graph-versions.qbs5
-rw-r--r--tests/auto/blackbox/testdata/build-graph-versions/main.cpp1
-rw-r--r--tests/auto/blackbox/tst_blackbox.cpp30
-rw-r--r--tests/auto/blackbox/tst_blackbox.h1
-rw-r--r--tests/auto/cmdlineparser/tst_cmdlineparser.cpp19
-rw-r--r--tests/auto/language/testdata/dirwithmultipleprojects/project.qbs (renamed from tests/auto/cmdlineparser/data/dirwithmultipleprojects/project.qbs)0
-rw-r--r--tests/auto/language/testdata/dirwithmultipleprojects/project2.qbs (renamed from tests/auto/cmdlineparser/data/dirwithmultipleprojects/project2.qbs)0
-rw-r--r--tests/auto/language/testdata/dirwithnoprojects/.gitignore (renamed from tests/auto/cmdlineparser/data/dirwithnoprojects/.gitignore)0
-rw-r--r--tests/auto/language/testdata/dirwithoneproject/project.qbs (renamed from tests/auto/cmdlineparser/data/dirwithoneproject/project.qbs)0
-rw-r--r--tests/auto/language/tst_language.cpp36
-rw-r--r--tests/auto/language/tst_language.h2
11 files changed, 75 insertions, 19 deletions
diff --git a/tests/auto/blackbox/testdata/build-graph-versions/build-graph-versions.qbs b/tests/auto/blackbox/testdata/build-graph-versions/build-graph-versions.qbs
new file mode 100644
index 000000000..f6ae698a0
--- /dev/null
+++ b/tests/auto/blackbox/testdata/build-graph-versions/build-graph-versions.qbs
@@ -0,0 +1,5 @@
+import qbs
+
+CppApplication {
+ files: ["main.cpp"]
+}
diff --git a/tests/auto/blackbox/testdata/build-graph-versions/main.cpp b/tests/auto/blackbox/testdata/build-graph-versions/main.cpp
new file mode 100644
index 000000000..8b8d58de0
--- /dev/null
+++ b/tests/auto/blackbox/testdata/build-graph-versions/main.cpp
@@ -0,0 +1 @@
+int main() { }
diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp
index 77a6f8a81..3acf4ee37 100644
--- a/tests/auto/blackbox/tst_blackbox.cpp
+++ b/tests/auto/blackbox/tst_blackbox.cpp
@@ -485,6 +485,36 @@ void TestBlackbox::buildEnvChange()
QVERIFY(runQbs(params) != 0);
}
+void TestBlackbox::buildGraphVersions()
+{
+ QDir::setCurrent(testDataDir + "/build-graph-versions");
+ QCOMPARE(runQbs(), 0);
+ QVERIFY2(m_qbsStdout.contains("compiling main.cpp"), m_qbsStdout.constData());
+ QFile bgFile(relativeBuildGraphFilePath());
+ QVERIFY2(bgFile.open(QIODevice::ReadWrite), qPrintable(bgFile.errorString()));
+ bgFile.write("blubb");
+ bgFile.close();
+
+ // The first attempt at simple rebuilding as well as subsequent ones must fail.
+ QbsRunParameters params;
+ params.expectFailure = true;
+ QVERIFY(runQbs(params) != 0);
+ QVERIFY2(m_qbsStderr.contains("Cannot use stored build graph"), m_qbsStderr.constData());
+ QVERIFY2(m_qbsStderr.contains("Use the 'resolve' command"), m_qbsStderr.constData());
+ QVERIFY(runQbs(params) != 0);
+ QVERIFY2(m_qbsStderr.contains("Cannot use stored build graph"), m_qbsStderr.constData());
+ QVERIFY2(m_qbsStderr.contains("Use the 'resolve' command"), m_qbsStderr.constData());
+
+ // On re-resolving, the error turns into a warning and a new build graph is created.
+ QCOMPARE(runQbs(QbsRunParameters("resolve")), 0);
+ QVERIFY2(m_qbsStderr.contains("Cannot use stored build graph"), m_qbsStderr.constData());
+ QVERIFY2(!m_qbsStderr.contains("Use the 'resolve' command"), m_qbsStderr.constData());
+
+ QCOMPARE(runQbs(), 0);
+ QVERIFY2(!m_qbsStderr.contains("Cannot use stored build graph"), m_qbsStderr.constData());
+ QVERIFY2(m_qbsStdout.contains("compiling main.cpp"), m_qbsStdout.constData());
+}
+
void TestBlackbox::changedFiles_data()
{
QTest::addColumn<bool>("useChangedFilesForInitialBuild");
diff --git a/tests/auto/blackbox/tst_blackbox.h b/tests/auto/blackbox/tst_blackbox.h
index 77f5762fb..4ae313946 100644
--- a/tests/auto/blackbox/tst_blackbox.h
+++ b/tests/auto/blackbox/tst_blackbox.h
@@ -47,6 +47,7 @@ private slots:
void badInterpreter();
void buildDirectories();
void buildEnvChange();
+ void buildGraphVersions();
void changedFiles_data();
void changedFiles();
void changeInDisabledProduct();
diff --git a/tests/auto/cmdlineparser/tst_cmdlineparser.cpp b/tests/auto/cmdlineparser/tst_cmdlineparser.cpp
index 92a202a45..de8ecc0b6 100644
--- a/tests/auto/cmdlineparser/tst_cmdlineparser.cpp
+++ b/tests/auto/cmdlineparser/tst_cmdlineparser.cpp
@@ -165,25 +165,6 @@ private slots:
QVERIFY(!parser.parseCommandLine(QStringList() << fileArgs << "-123")); // Unknown numeric argument.
}
- void testProjectFileLookup()
- {
- const QString srcDir = QLatin1String(SRCDIR);
- const QString noProjectsDir = srcDir + QLatin1String("/data/dirwithnoprojects");
- const QString oneProjectDir = srcDir + QLatin1String("/data/dirwithoneproject");
- const QString multiProjectsDir = srcDir + QLatin1String("/data/dirwithmultipleprojects");
- QVERIFY(QDir(noProjectsDir).exists() && QDir(oneProjectDir).exists()
- && QDir(multiProjectsDir).exists());
- CommandLineParser parser;
- const QStringList args(QLatin1String("-f"));
- QString projectFilePath = multiProjectsDir + QLatin1String("/project.qbs");
- QVERIFY(parser.parseCommandLine(args + QStringList(projectFilePath)));
- QCOMPARE(projectFilePath, parser.projectFilePath());
- projectFilePath = oneProjectDir + QLatin1String("/project.qbs");
- QVERIFY(parser.parseCommandLine(args + QStringList(oneProjectDir)));
- QCOMPARE(projectFilePath, parser.projectFilePath());
- QVERIFY(!parser.parseCommandLine(args + QStringList(noProjectsDir)));
- QVERIFY(!parser.parseCommandLine(args + QStringList(multiProjectsDir)));
- }
};
QTEST_MAIN(TestCmdLineParser)
diff --git a/tests/auto/cmdlineparser/data/dirwithmultipleprojects/project.qbs b/tests/auto/language/testdata/dirwithmultipleprojects/project.qbs
index e69de29bb..e69de29bb 100644
--- a/tests/auto/cmdlineparser/data/dirwithmultipleprojects/project.qbs
+++ b/tests/auto/language/testdata/dirwithmultipleprojects/project.qbs
diff --git a/tests/auto/cmdlineparser/data/dirwithmultipleprojects/project2.qbs b/tests/auto/language/testdata/dirwithmultipleprojects/project2.qbs
index e69de29bb..e69de29bb 100644
--- a/tests/auto/cmdlineparser/data/dirwithmultipleprojects/project2.qbs
+++ b/tests/auto/language/testdata/dirwithmultipleprojects/project2.qbs
diff --git a/tests/auto/cmdlineparser/data/dirwithnoprojects/.gitignore b/tests/auto/language/testdata/dirwithnoprojects/.gitignore
index d6b7ef32c..d6b7ef32c 100644
--- a/tests/auto/cmdlineparser/data/dirwithnoprojects/.gitignore
+++ b/tests/auto/language/testdata/dirwithnoprojects/.gitignore
diff --git a/tests/auto/cmdlineparser/data/dirwithoneproject/project.qbs b/tests/auto/language/testdata/dirwithoneproject/project.qbs
index e69de29bb..e69de29bb 100644
--- a/tests/auto/cmdlineparser/data/dirwithoneproject/project.qbs
+++ b/tests/auto/language/testdata/dirwithoneproject/project.qbs
diff --git a/tests/auto/language/tst_language.cpp b/tests/auto/language/tst_language.cpp
index fdde1fae3..fdcd98da8 100644
--- a/tests/auto/language/tst_language.cpp
+++ b/tests/auto/language/tst_language.cpp
@@ -1797,6 +1797,42 @@ void TestLanguage::profileValuesAndOverriddenValues()
QCOMPARE(exceptionCaught, false);
}
+void TestLanguage::projectFileLookup()
+{
+ QFETCH(QString, projectFileInput);
+ QFETCH(QString, projectFileOutput);
+ QFETCH(bool, failureExpected);
+
+ try {
+ SetupProjectParameters params;
+ params.setProjectFilePath(projectFileInput);
+ Loader::setupProjectFilePath(params);
+ QVERIFY(!failureExpected);
+ QCOMPARE(params.projectFilePath(), projectFileOutput);
+ } catch (const ErrorInfo &) {
+ QVERIFY(failureExpected);
+ }
+}
+
+void TestLanguage::projectFileLookup_data()
+{
+ QTest::addColumn<QString>("projectFileInput");
+ QTest::addColumn<QString>("projectFileOutput");
+ QTest::addColumn<bool>("failureExpected");
+
+ const QString baseDir = QLatin1String(SRCDIR) + "/testdata";
+ const QString multiProjectsDir = baseDir + "/dirwithmultipleprojects";
+ const QString noProjectsDir = baseDir + "/dirwithnoprojects";
+ const QString oneProjectDir = baseDir + "/dirwithoneproject";
+ QVERIFY(QDir(noProjectsDir).exists() && QDir(oneProjectDir).exists()
+ && QDir(multiProjectsDir).exists());
+ const QString fullFilePath = multiProjectsDir + "/project.qbs";
+ QTest::newRow("full file path") << fullFilePath << fullFilePath << false;
+ QTest::newRow("base dir ") << oneProjectDir << (oneProjectDir + "/project.qbs") << false;
+ QTest::newRow("empty dir") << noProjectsDir << QString() << true;
+ QTest::newRow("ambiguous dir") << multiProjectsDir << QString() << true;
+}
+
void TestLanguage::productConditions()
{
bool exceptionCaught = false;
diff --git a/tests/auto/language/tst_language.h b/tests/auto/language/tst_language.h
index 9d63414a5..62805ec2f 100644
--- a/tests/auto/language/tst_language.h
+++ b/tests/auto/language/tst_language.h
@@ -126,6 +126,8 @@ private slots:
void productConditions();
void productDirectories();
void profileValuesAndOverriddenValues();
+ void projectFileLookup();
+ void projectFileLookup_data();
void propertiesBlocks_data();
void propertiesBlocks();
void propertiesBlockInGroup();