diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2022-09-22 17:14:55 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2022-10-04 07:43:01 +0000 |
commit | a29bbf5568bf651b076f051720a98e9d0297faa9 (patch) | |
tree | 5d99c12c7d9735e7f113c3a04ccf95746ef8dedc /tests | |
parent | 512001849af89e4b2c5bfb18b039387d6fe7aaa6 (diff) | |
download | qbs-a29bbf5568bf651b076f051720a98e9d0297faa9.tar.gz |
Make handling of deprecated items and properties configurable
As of now, a newly deprecated property leads to users getting bombarded
with warnings, even though they did not yet have a chance to adapt their
project.
Now the warnings appear by default one minor version before removal,
which together with our convention of keeping deprecated properties for
at least two minor versions gives users enough time to adapt without
getting spammed.
There is also a mode for switching to the previous behavior (for early
detection), as well as the possibility to trigger errors instead of
warnings, which should be helpful in CI configurations.
To support the case where the user cannot do anything about them, the
warnings can also be suppressed altogether.
Change-Id: I295f816758f0f111fcb0351581a4328be3af5668
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/blackbox/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/blackbox/blackbox.qbs | 1 | ||||
-rw-r--r-- | tests/auto/blackbox/testdata/deprecated-property/deprecated-property.qbs | 2 | ||||
-rw-r--r-- | tests/auto/blackbox/testdata/deprecated-property/modules/themodule/m.qbs | 8 | ||||
-rw-r--r-- | tests/auto/blackbox/tst_blackbox.cpp | 61 | ||||
-rw-r--r-- | tests/auto/blackbox/tst_blackbox.h | 1 |
6 files changed, 62 insertions, 12 deletions
diff --git a/tests/auto/blackbox/CMakeLists.txt b/tests/auto/blackbox/CMakeLists.txt index 0bf79a433..5b5376064 100644 --- a/tests/auto/blackbox/CMakeLists.txt +++ b/tests/auto/blackbox/CMakeLists.txt @@ -1,6 +1,7 @@ add_qbs_test(blackbox DEFINES ${QBS_UNIT_TESTS_DEFINES} + "QBS_VERSION=\"${QBS_VERSION}\"" SOURCES ../shared.h tst_blackboxbase.cpp diff --git a/tests/auto/blackbox/blackbox.qbs b/tests/auto/blackbox/blackbox.qbs index 3f0ff959a..ac6bf750e 100644 --- a/tests/auto/blackbox/blackbox.qbs +++ b/tests/auto/blackbox/blackbox.qbs @@ -25,4 +25,5 @@ QbsAutotest { ] cpp.defines: base.concat(["SRCDIR=" + Utilities.cStringQuote(path)]) .concat(qbsbuildconfig.enableUnitTests ? ["QBS_ENABLE_UNIT_TESTS"] : []) + .concat("QBS_VERSION=" + Utilities.cStringQuote(qbsversion.version)) } diff --git a/tests/auto/blackbox/testdata/deprecated-property/deprecated-property.qbs b/tests/auto/blackbox/testdata/deprecated-property/deprecated-property.qbs index e3dacffea..e699672a8 100644 --- a/tests/auto/blackbox/testdata/deprecated-property/deprecated-property.qbs +++ b/tests/auto/blackbox/testdata/deprecated-property/deprecated-property.qbs @@ -3,6 +3,6 @@ import qbs // FIXME: Don't remove this import because then the test fails! Product { Depends { name: "themodule" } themodule.newProp: true - themodule.oldProp: false + themodule.expiringProp: false themodule.veryOldProp: false } diff --git a/tests/auto/blackbox/testdata/deprecated-property/modules/themodule/m.qbs b/tests/auto/blackbox/testdata/deprecated-property/modules/themodule/m.qbs index cd6b0b70c..58164e918 100644 --- a/tests/auto/blackbox/testdata/deprecated-property/modules/themodule/m.qbs +++ b/tests/auto/blackbox/testdata/deprecated-property/modules/themodule/m.qbs @@ -1,8 +1,8 @@ -import qbs // FIXME: Don't remove this import because then the test fails! +import qbs.Environment Module { property bool newProp - property bool oldProp + property bool expiringProp property bool forgottenProp PropertyOptions { @@ -10,9 +10,9 @@ Module { description: "Use this, it's good!" } PropertyOptions { - name: "oldProp" + name: "expiringProp" description: "Use newProp instead." - removalVersion: "99.9" + removalVersion: Environment.getEnv("REMOVAL_VERSION") } PropertyOptions { name: "veryOldProp" diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp index 679972d37..8bc905929 100644 --- a/tests/auto/blackbox/tst_blackbox.cpp +++ b/tests/auto/blackbox/tst_blackbox.cpp @@ -53,6 +53,7 @@ #include <QtCore/qsettings.h> #include <QtCore/qtemporarydir.h> #include <QtCore/qtemporaryfile.h> +#include <QtCore/qversionnumber.h> #include <algorithm> #include <functional> @@ -1055,22 +1056,68 @@ void TestBlackbox::dependencyScanningLoop() void TestBlackbox::deprecatedProperty() { + QFETCH(QString, version); + QFETCH(QString, mode); + QFETCH(bool, expiringWarning); + QFETCH(bool, expiringError); + QDir::setCurrent(testDataDir + "/deprecated-property"); QbsRunParameters params(QStringList("-q")); params.expectFailure = true; + params.environment.insert("REMOVAL_VERSION", version); + if (!mode.isEmpty()) + params.arguments << "--deprecation-warnings" << mode; QVERIFY(runQbs(params) != 0); m_qbsStderr = QDir::fromNativeSeparators(QString::fromLocal8Bit(m_qbsStderr)).toLocal8Bit(); - QVERIFY2(m_qbsStderr.contains("deprecated-property.qbs:6:24 The property 'oldProp' is " - "deprecated and will be removed in Qbs 99.9.0."), m_qbsStderr.constData()); - QVERIFY2(m_qbsStderr.contains("deprecated-property.qbs:7:28 The property 'veryOldProp' can no " - "longer be used. It was removed in Qbs 1.3.0."), m_qbsStderr.constData()); + const bool hasExpiringWarning = m_qbsStderr.contains(QByteArray( + "deprecated-property.qbs:6:29 The property 'expiringProp' is " + "deprecated and will be removed in Qbs ") + version.toLocal8Bit()); + QVERIFY2(expiringWarning == hasExpiringWarning, m_qbsStderr.constData()); + const bool hasRemovedOutput = m_qbsStderr.contains( + "deprecated-property.qbs:7:28 The property 'veryOldProp' can no " + "longer be used. It was removed in Qbs 1.3.0."); + QVERIFY2(hasRemovedOutput == !expiringError, m_qbsStderr.constData()); QVERIFY2(m_qbsStderr.contains("Property 'forgottenProp' was scheduled for removal in version " "1.8.0, but is still present."), m_qbsStderr.constData()); QVERIFY2(m_qbsStderr.contains("themodule/m.qbs:22:5 Removal version for 'forgottenProp' " "specified here."), m_qbsStderr.constData()); - QVERIFY2(m_qbsStderr.count("Use newProp instead.") == 2, m_qbsStderr.constData()); - QVERIFY2(m_qbsStderr.count("is deprecated") == 1, m_qbsStderr.constData()); - QVERIFY2(m_qbsStderr.count("was removed") == 1, m_qbsStderr.constData()); + QVERIFY2(m_qbsStderr.count("Use newProp instead.") == 1 + + int(expiringWarning && !expiringError), m_qbsStderr.constData()); + QVERIFY2(m_qbsStderr.count("is deprecated") == int(expiringWarning), m_qbsStderr.constData()); + QVERIFY2(m_qbsStderr.count("was removed") == int(!expiringError), m_qbsStderr.constData()); +} + +void TestBlackbox::deprecatedProperty_data() +{ + QTest::addColumn<QString>("version"); + QTest::addColumn<QString>("mode"); + QTest::addColumn<bool>("expiringWarning"); + QTest::addColumn<bool>("expiringError"); + + const auto current = QVersionNumber::fromString(QBS_VERSION); + const QString next = QVersionNumber(current.majorVersion(), current.minorVersion() + 1) + .toString(); + const QString nextNext = QVersionNumber(current.majorVersion(), current.minorVersion() + 2) + .toString(); + const QString nextMajor = QVersionNumber(current.majorVersion() + 1).toString(); + + QTest::newRow("default/next") << next << QString() << true << false; + QTest::newRow("default/nextnext") << nextNext << QString() << false << false; + QTest::newRow("default/nextmajor") << nextMajor << QString() << true << false; + QTest::newRow("error/next") << next << QString("error") << true << true; + QTest::newRow("error/nextnext") << nextNext << QString("error") << true << true; + QTest::newRow("error/nextmajor") << nextMajor << QString("error") << true << true; + QTest::newRow("on/next") << next << QString("on") << true << false; + QTest::newRow("on/nextnext") << nextNext << QString("on") << true << false; + QTest::newRow("on/nextmajor") << nextMajor << QString("on") << true << false; + QTest::newRow("before-removal/next") << next << QString("before-removal") << true << false; + QTest::newRow("before-removal/nextnext") << nextNext << QString("before-removal") + << false << false; + QTest::newRow("before-removal/nextmajor") << nextMajor << QString("before-removal") + << true << false; + QTest::newRow("off/next") << next << QString("off") << false << false; + QTest::newRow("off/nextnext") << nextNext << QString("off") << false << false; + QTest::newRow("off/nextmajor") << nextMajor << QString("off") << false << false; } void TestBlackbox::disappearedProfile() diff --git a/tests/auto/blackbox/tst_blackbox.h b/tests/auto/blackbox/tst_blackbox.h index dc184989c..285d465fd 100644 --- a/tests/auto/blackbox/tst_blackbox.h +++ b/tests/auto/blackbox/tst_blackbox.h @@ -95,6 +95,7 @@ private slots: void dependenciesProperty(); void dependencyScanningLoop(); void deprecatedProperty(); + void deprecatedProperty_data(); void disappearedProfile(); void discardUnusedData(); void discardUnusedData_data(); |