diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2018-10-23 14:13:45 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2018-10-24 07:45:24 +0000 |
commit | 783f2f91854d9c0a3cacca668d52ea761cc2a1b8 (patch) | |
tree | d96584e38f63cf9085397067809998801dec14b7 | |
parent | 6e29a5c6fb1bdf20c0d8ee832a2d1ede9bd31717 (diff) |
Fix TestBlackbox::qbsConfig()
... for the case that it is run by a user with admin rights. We should
not expect failure in that case.
Change-Id: Ib045bf550dbedbfcaa3c38fc9f713a40541ddb61
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
-rw-r--r-- | tests/auto/blackbox/tst_blackbox.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp index 7ee5e5cc6..598836c81 100644 --- a/tests/auto/blackbox/tst_blackbox.cpp +++ b/tests/auto/blackbox/tst_blackbox.cpp @@ -47,6 +47,7 @@ #include <QtCore/qjsonvalue.h> #include <QtCore/qlocale.h> #include <QtCore/qregexp.h> +#include <QtCore/qsettings.h> #include <QtCore/qtemporarydir.h> #include <QtCore/qtemporaryfile.h> @@ -4819,13 +4820,28 @@ void TestBlackbox::qbsConfig() "most qbs-config tests"; #endif // QBS_ENABLE_UNIT_TESTS + bool canWriteToSystemSettings; + QString testSettingsFilePath; + { + QSettings testSettings(QSettings::IniFormat, QSettings::SystemScope, + "dummyOrg", "dummyApp"); + testSettings.setValue("dummyKey", "dummyValue"); + testSettings.sync(); + canWriteToSystemSettings = testSettings.status() == QSettings::NoError; + testSettingsFilePath = testSettings.fileName(); + } + if (canWriteToSystemSettings) + QVERIFY(QFile::remove(testSettingsFilePath)); + // Check that trying to write to actual system settings causes access failure. - params.expectFailure = true; + params.expectFailure = !canWriteToSystemSettings; params.environment.clear(); params.arguments = QStringList{"--system", "key.subkey.scalar", "s"}; - QVERIFY(runQbs(params) != 0); - QVERIFY2(m_qbsStderr.contains("You do not have permission to write to that location."), - m_qbsStderr.constData()); + QCOMPARE(runQbs(params) == 0, canWriteToSystemSettings); + if (!canWriteToSystemSettings) { + QVERIFY2(m_qbsStderr.contains("You do not have permission to write to that location."), + m_qbsStderr.constData()); + } } void TestBlackbox::radAfterIncompleteBuild_data() |