summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/auto/qml/qmlformat/tst_qmlformat.cpp25
-rw-r--r--tools/qmlformat/qmlformat.cpp3
2 files changed, 27 insertions, 1 deletions
diff --git a/tests/auto/qml/qmlformat/tst_qmlformat.cpp b/tests/auto/qml/qmlformat/tst_qmlformat.cpp
index e95673221a..d9d4c17d0b 100644
--- a/tests/auto/qml/qmlformat/tst_qmlformat.cpp
+++ b/tests/auto/qml/qmlformat/tst_qmlformat.cpp
@@ -38,6 +38,8 @@ private Q_SLOTS:
void normalizeExample_data();
#endif
+ void testBackupFileLimit();
+
private:
QString readTestFile(const QString &path);
QString runQmlformat(const QString &fileToFormat, QStringList args, bool shouldSucceed = true,
@@ -366,6 +368,29 @@ void TestQmlformat::normalizeExample()
}
#endif
+void TestQmlformat::testBackupFileLimit()
+{
+ // Create a temporary directory
+ QTemporaryDir tempDir;
+
+ // Unformatted file to format
+ const QString fileToFormat{ testFile("Annotations.qml") };
+
+ {
+ const QString tempFile = tempDir.path() + QDir::separator() + "test_0.qml";
+ const QString backupFile = tempFile + QStringLiteral("~");
+ QFile::copy(fileToFormat, tempFile);
+
+ QProcess process;
+ process.start(m_qmlformatPath, QStringList{ "--verbose", "--inplace", tempFile });
+ QVERIFY(process.waitForFinished());
+ QCOMPARE(process.exitStatus(), QProcess::NormalExit);
+ QCOMPARE(process.exitCode(), 0);
+ QVERIFY(QFileInfo::exists(tempFile));
+ QVERIFY(!QFileInfo::exists(backupFile));
+ };
+}
+
QString TestQmlformat::runQmlformat(const QString &fileToFormat, QStringList args,
bool shouldSucceed, RunOption rOptions)
{
diff --git a/tools/qmlformat/qmlformat.cpp b/tools/qmlformat/qmlformat.cpp
index 3aa452c21c..2e99dd3110 100644
--- a/tools/qmlformat/qmlformat.cpp
+++ b/tools/qmlformat/qmlformat.cpp
@@ -123,7 +123,8 @@ bool parseFile(const QString &filename, const Options &options)
if (options.verbose)
qWarning().noquote() << "Writing to file" << filename;
FileWriter fw;
- res = qmlFile.writeOut(filename, 2, lwOptions, &fw, checks);
+ const unsigned numberOfBackupFiles = 0;
+ res = qmlFile.writeOut(filename, numberOfBackupFiles, lwOptions, &fw, checks);
} else {
QFile out;
out.open(stdout, QIODevice::WriteOnly);