aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/api/testdata/soft-dependency/soft-dependency.qbs8
-rw-r--r--tests/auto/blackbox/testdata/fallback-module-provider/fallback-module-provider.qbs8
-rw-r--r--tests/auto/blackbox/testdata/fallback-module-provider/libdir/qbsmetatestmodule.pc5
-rw-r--r--tests/auto/blackbox/testdata/fallback-module-provider/main.cpp5
-rw-r--r--tests/auto/blackbox/testdata/module-providers/main.cpp6
-rw-r--r--tests/auto/blackbox/testdata/module-providers/module-providers.qbs20
-rw-r--r--tests/auto/blackbox/testdata/module-providers/module-providers/mygenerator/provider.qbs31
-rw-r--r--tests/auto/blackbox/tst_blackbox.cpp100
-rw-r--r--tests/auto/blackbox/tst_blackbox.h3
-rw-r--r--tests/auto/language/tst_language.cpp3
-rw-r--r--tests/auto/language/tst_language.h4
11 files changed, 187 insertions, 6 deletions
diff --git a/tests/auto/api/testdata/soft-dependency/soft-dependency.qbs b/tests/auto/api/testdata/soft-dependency/soft-dependency.qbs
index 62713a481..42d2f2de4 100644
--- a/tests/auto/api/testdata/soft-dependency/soft-dependency.qbs
+++ b/tests/auto/api/testdata/soft-dependency/soft-dependency.qbs
@@ -1,12 +1,10 @@
-Application {
+CppApplication {
Depends {
name: "nosuchmodule"
required: false
}
- Depends {
- name: "cpp"
+ Properties {
condition: nosuchmodule.present
+ files: "main.cpp"
}
-
- files: "main.cpp"
}
diff --git a/tests/auto/blackbox/testdata/fallback-module-provider/fallback-module-provider.qbs b/tests/auto/blackbox/testdata/fallback-module-provider/fallback-module-provider.qbs
new file mode 100644
index 000000000..a798e15b3
--- /dev/null
+++ b/tests/auto/blackbox/testdata/fallback-module-provider/fallback-module-provider.qbs
@@ -0,0 +1,8 @@
+CppApplication {
+ name: "p"
+ property bool fallbacksEnabled
+ Depends { name: "pkgconfig"; required: false }
+ Depends { name: "qbsmetatestmodule"; required: false; enableFallback: fallbacksEnabled }
+ property bool dummy: { console.info("pkg-config present: " + pkgconfig.present); }
+ files: "main.cpp"
+}
diff --git a/tests/auto/blackbox/testdata/fallback-module-provider/libdir/qbsmetatestmodule.pc b/tests/auto/blackbox/testdata/fallback-module-provider/libdir/qbsmetatestmodule.pc
new file mode 100644
index 000000000..ae4daba89
--- /dev/null
+++ b/tests/auto/blackbox/testdata/fallback-module-provider/libdir/qbsmetatestmodule.pc
@@ -0,0 +1,5 @@
+Name: qbsmetatestmodule
+Description: just a test
+Version: 0.0.1
+
+Cflags: -DTHE_MAGIC_DEFINE
diff --git a/tests/auto/blackbox/testdata/fallback-module-provider/main.cpp b/tests/auto/blackbox/testdata/fallback-module-provider/main.cpp
new file mode 100644
index 000000000..442b755bf
--- /dev/null
+++ b/tests/auto/blackbox/testdata/fallback-module-provider/main.cpp
@@ -0,0 +1,5 @@
+#ifndef THE_MAGIC_DEFINE
+#error "missing the magic define"
+#endif
+
+int main() {}
diff --git a/tests/auto/blackbox/testdata/module-providers/main.cpp b/tests/auto/blackbox/testdata/module-providers/main.cpp
new file mode 100644
index 000000000..9cd29b1fe
--- /dev/null
+++ b/tests/auto/blackbox/testdata/module-providers/main.cpp
@@ -0,0 +1,6 @@
+#include <iostream>
+
+int main()
+{
+ std::cout << "The letters are " << LETTER1 << " and " << LETTER2 << std::endl;
+}
diff --git a/tests/auto/blackbox/testdata/module-providers/module-providers.qbs b/tests/auto/blackbox/testdata/module-providers/module-providers.qbs
new file mode 100644
index 000000000..d1ff79269
--- /dev/null
+++ b/tests/auto/blackbox/testdata/module-providers/module-providers.qbs
@@ -0,0 +1,20 @@
+Project {
+ CppApplication {
+ name: "app1"
+ Depends { name: "mygenerator.module1" }
+ Depends { name: "mygenerator.module2" }
+ moduleProviders.mygenerator.chooseLettersFrom: "beginning"
+ files: "main.cpp"
+ }
+ CppApplication {
+ name: "app2"
+ Depends { name: "mygenerator.module1" }
+ Depends { name: "mygenerator.module2" }
+ Profile {
+ name: "myProfile"
+ moduleProviders.mygenerator.chooseLettersFrom: "end"
+ }
+ qbs.profile: "myProfile"
+ files: "main.cpp"
+ }
+}
diff --git a/tests/auto/blackbox/testdata/module-providers/module-providers/mygenerator/provider.qbs b/tests/auto/blackbox/testdata/module-providers/module-providers/mygenerator/provider.qbs
new file mode 100644
index 000000000..dae02c03a
--- /dev/null
+++ b/tests/auto/blackbox/testdata/module-providers/module-providers/mygenerator/provider.qbs
@@ -0,0 +1,31 @@
+import qbs.File;
+import qbs.FileInfo;
+import qbs.TextFile;
+
+ModuleProvider {
+ property string chooseLettersFrom
+ relativeSearchPaths: {
+ console.info("Running setup script for " + name);
+ var startAtBeginning = chooseLettersFrom === "beginning";
+ var moduleBaseDir = FileInfo.joinPaths(outputBaseDir, "modules", "mygenerator");
+ var module1Dir = FileInfo.joinPaths(moduleBaseDir, "module1");
+ File.makePath(module1Dir);
+ var module1 = new TextFile(FileInfo.joinPaths(module1Dir, "module1.qbs"), TextFile.WriteOnly);
+ module1.writeLine("Module {");
+ module1.writeLine(" Depends { name: 'cpp' }");
+ module1.writeLine(" cpp.defines: 'LETTER1=" + (startAtBeginning ? "\\\'A\\\'" : "\\\'Z\\\'")
+ + "'");
+ module1.writeLine("}");
+ module1.close();
+ var module2Dir = FileInfo.joinPaths(moduleBaseDir, "module2");
+ File.makePath(module2Dir);
+ var module2 = new TextFile(FileInfo.joinPaths(module2Dir, "module2.qbs"), TextFile.WriteOnly);
+ module2.writeLine("Module {");
+ module2.writeLine(" Depends { name: 'cpp' }");
+ module2.writeLine(" cpp.defines: 'LETTER2=" + (startAtBeginning ? "\\\'B\\\'" : "\\\'Y\\\'")
+ + "'");
+ module2.writeLine("}");
+ module2.close();
+ return "";
+ }
+}
diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp
index fbcd16eb8..82f29f320 100644
--- a/tests/auto/blackbox/tst_blackbox.cpp
+++ b/tests/auto/blackbox/tst_blackbox.cpp
@@ -6310,6 +6310,106 @@ void TestBlackbox::maximumCxxLanguageVersion()
m_qbsStdout.constData());
}
+void TestBlackbox::moduleProviders()
+{
+ QDir::setCurrent(testDataDir + "/module-providers");
+
+ // Resolving in dry-run mode must not leave any data behind.
+ QCOMPARE(runQbs(QbsRunParameters("resolve", QStringList("-n"))), 0);
+ QCOMPARE(m_qbsStdout.count("Running setup script for mygenerator"), 2);
+ QVERIFY(!QFile::exists(relativeBuildDir()));
+
+ // Initial build.
+ QCOMPARE(runQbs(QbsRunParameters("run", QStringList{"-p", "app1"})), 0);
+ QVERIFY(QFile::exists(relativeBuildDir()));
+ QCOMPARE(m_qbsStdout.count("Running setup script for mygenerator"), 2);
+ QVERIFY2(m_qbsStdout.contains("The letters are A and B"), m_qbsStdout.constData());
+ QCOMPARE(runQbs(QbsRunParameters("run", QStringList{"-p", "app2"})), 0);
+ QVERIFY2(m_qbsStdout.contains("The letters are Z and Y"), m_qbsStdout.constData());
+
+ // Rebuild with overridden module provider config. The output for product 2 must change,
+ // but no setup script must be re-run, because both config values have already been
+ // handled in the first run.
+ const QStringList resolveArgs("moduleProviders.mygenerator.chooseLettersFrom:beginning");
+ QCOMPARE(runQbs(QbsRunParameters("resolve", resolveArgs)), 0);
+ QVERIFY2(!m_qbsStdout.contains("Running setup script"), m_qbsStdout.constData());
+ QCOMPARE(runQbs(QbsRunParameters("run", QStringList{"-p", "app1"})), 0);
+ QVERIFY2(m_qbsStdout.contains("The letters are A and B"), m_qbsStdout.constData());
+ QCOMPARE(runQbs(QbsRunParameters("run", QStringList{"-p", "app2"})), 0);
+ QVERIFY2(m_qbsStdout.contains("The letters are A and B"), m_qbsStdout.constData());
+
+ // Forcing Probe execution triggers a re-run of the setup script. But only once,
+ // because the module provider config is the same now.
+ QCOMPARE(runQbs(QbsRunParameters("resolve", QStringList(resolveArgs)
+ << "--force-probe-execution")), 0);
+ QCOMPARE(m_qbsStdout.count("Running setup script for mygenerator"), 1);
+ QCOMPARE(runQbs(QbsRunParameters("run", QStringList{"-p", "app1"})), 0);
+ QVERIFY2(m_qbsStdout.contains("The letters are A and B"), m_qbsStdout.constData());
+ QCOMPARE(runQbs(QbsRunParameters("run", QStringList{"-p", "app2"})), 0);
+ QVERIFY2(m_qbsStdout.contains("The letters are A and B"), m_qbsStdout.constData());
+
+ // Now re-run without the module provider config override. Again, the setup script must
+ // run once, for the config value that was not present in the last run.
+ QCOMPARE(runQbs(QbsRunParameters("resolve")), 0);
+ QCOMPARE(m_qbsStdout.count("Running setup script for mygenerator"), 1);
+ QCOMPARE(runQbs(QbsRunParameters("run", QStringList{"-p", "app1"})), 0);
+ QVERIFY2(m_qbsStdout.contains("The letters are A and B"), m_qbsStdout.constData());
+ QCOMPARE(runQbs(QbsRunParameters("run", QStringList{"-p", "app2"})), 0);
+ QVERIFY2(m_qbsStdout.contains("The letters are Z and Y"), m_qbsStdout.constData());
+}
+
+void TestBlackbox::fallbackModuleProvider_data()
+{
+ QTest::addColumn<bool>("fallbacksEnabledGlobally");
+ QTest::addColumn<bool>("fallbacksEnabledInProduct");
+ QTest::addColumn<QStringList>("pkgConfigLibDirs");
+ QTest::addColumn<bool>("successExpected");
+ QTest::newRow("without custom lib dir, fallbacks disabled globally and in product")
+ << false << false << QStringList() << false;
+ QTest::newRow("without custom lib dir, fallbacks disabled globally, enabled in product")
+ << false << true << QStringList() << false;
+ QTest::newRow("without custom lib dir, fallbacks enabled globally, disabled in product")
+ << true << false << QStringList() << false;
+ QTest::newRow("without custom lib dir, fallbacks enabled globally and in product")
+ << true << true << QStringList() << false;
+ QTest::newRow("with custom lib dir, fallbacks disabled globally and in product")
+ << false << false << QStringList(testDataDir + "/fallback-module-provider/libdir")
+ << false;
+ QTest::newRow("with custom lib dir, fallbacks disabled globally, enabled in product")
+ << false << true << QStringList(testDataDir + "/fallback-module-provider/libdir")
+ << false;
+ QTest::newRow("with custom lib dir, fallbacks enabled globally, disabled in product")
+ << true << false << QStringList(testDataDir + "/fallback-module-provider/libdir")
+ << false;
+ QTest::newRow("with custom lib dir, fallbacks enabled globally and in product")
+ << true << true << QStringList(testDataDir + "/fallback-module-provider/libdir")
+ << true;
+}
+
+void TestBlackbox::fallbackModuleProvider()
+{
+ QFETCH(bool, fallbacksEnabledInProduct);
+ QFETCH(bool, fallbacksEnabledGlobally);
+ QFETCH(QStringList, pkgConfigLibDirs);
+ QFETCH(bool, successExpected);
+ QDir::setCurrent(testDataDir + "/fallback-module-provider");
+ static const auto b2s = [](bool b) { return QString(b ? "true" : "false"); };
+ QbsRunParameters resolveParams("resolve",
+ QStringList{"modules.pkgconfig.libDirs:" + pkgConfigLibDirs.join(','),
+ "products.p.fallbacksEnabled:" + b2s(fallbacksEnabledInProduct)});
+ if (!fallbacksEnabledGlobally)
+ resolveParams.arguments << "--no-fallback-module-provider";
+ QCOMPARE(runQbs(resolveParams), 0);
+ const bool pkgConfigPresent = m_qbsStdout.contains("pkg-config present: true");
+ const bool pkgConfigNotPresent = m_qbsStdout.contains("pkg-config present: false");
+ QVERIFY(pkgConfigPresent != pkgConfigNotPresent);
+ if (pkgConfigNotPresent)
+ successExpected = false;
+ QbsRunParameters buildParams;
+ buildParams.expectFailure = !successExpected;
+ QCOMPARE(runQbs(buildParams) == 0, successExpected);
+}
+
void TestBlackbox::minimumSystemVersion()
{
rmDirR(relativeBuildDir());
diff --git a/tests/auto/blackbox/tst_blackbox.h b/tests/auto/blackbox/tst_blackbox.h
index 313ad5d40..624cd5fbb 100644
--- a/tests/auto/blackbox/tst_blackbox.h
+++ b/tests/auto/blackbox/tst_blackbox.h
@@ -174,6 +174,9 @@ private slots:
void makefileGenerator();
void maximumCLanguageVersion();
void maximumCxxLanguageVersion();
+ void moduleProviders();
+ void fallbackModuleProvider_data();
+ void fallbackModuleProvider();
void minimumSystemVersion();
void minimumSystemVersion_data();
void missingBuildGraph();
diff --git a/tests/auto/language/tst_language.cpp b/tests/auto/language/tst_language.cpp
index be9dfb932..6b5cc2447 100644
--- a/tests/auto/language/tst_language.cpp
+++ b/tests/auto/language/tst_language.cpp
@@ -93,7 +93,7 @@ TestLanguage::TestLanguage(ILogSink *logSink, Settings *settings)
{
qsrand(QTime::currentTime().msec());
qRegisterMetaType<QList<bool> >("QList<bool>");
- defaultParameters.setBuildRoot("/some/build/directory");
+ defaultParameters.setBuildRoot(m_tempDir.path() + "/buildroot");
defaultParameters.setPropertyCheckingMode(ErrorHandlingMode::Strict);
defaultParameters.setSettingsDirectory(m_settings->baseDirectory());
}
@@ -163,6 +163,7 @@ void TestLanguage::handleInitCleanupDataTags(const char *projectFileName, bool *
void TestLanguage::init()
{
m_logSink->setLogLevel(LoggerInfo);
+ QVERIFY(m_tempDir.isValid());
}
#define HANDLE_INIT_CLEANUP_DATATAGS(fn) {\
diff --git a/tests/auto/language/tst_language.h b/tests/auto/language/tst_language.h
index 0fa44afe4..3fe6d8f2a 100644
--- a/tests/auto/language/tst_language.h
+++ b/tests/auto/language/tst_language.h
@@ -45,6 +45,7 @@
#include <logging/ilogsink.h>
#include <tools/setupprojectparameters.h>
+#include <QtCore/qtemporarydir.h>
#include <QtTest/qtest.h>
class TestLanguage : public QObject
@@ -178,6 +179,9 @@ private slots:
void versionCompare();
void wildcards_data();
void wildcards();
+
+private:
+ QTemporaryDir m_tempDir;
};
#endif // TST_LANGUAGE_H