[frameworks/kio] autotests: jobtest: set the language the expected text is written in

Méven Car <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit eadb7d02941a730e4605421ba006fb998c11109b by Méven Car.
Committed on 16/08/2026 at 16:54.
Pushed by meven into branch 'master'.

jobtest: set the language the expected text is written in

Some of what the test compares is text KIO puts together, expected in the
English it is written in, so the test failed whenever the locale of the user
running it is not English.

The language is now set before main runs, ignoring the user locale, so nothing
has read it by then and a worker the test starts inherits the setting.

M  +14   -0    autotests/jobtest.cpp

https://invent.kde.org/frameworks/kio/-/commit/eadb7d02941a730e4605421ba006fb998c11109b

diff --git a/autotests/jobtest.cpp b/autotests/jobtest.cpp
index 3358f03a7e..cfb67855b7 100644
--- a/autotests/jobtest.cpp
+++ b/autotests/jobtest.cpp
@@ -45,6 +45,7 @@
 #include <QFileInfo>
 #include <QHash>
 #include <QHostInfo>
+#include <QLocale>
 #include <QPointer>
 #include <QProcess>
 #include <QScopeGuard>
@@ -63,6 +64,19 @@
 
 using namespace Qt::StringLiterals;
 
+// Sets the language the comparisons below expect, ignoring the locale of the user running the test.
+// This runs before main, so nothing has read that locale by then.
+void initLocale()
+{
+#ifndef Q_OS_WIN
+    qputenv("LC_ALL", "en_US.utf-8");
+#else
+    QLocale::setDefault(QLocale(QStringLiteral("en_US")));
+#endif
+}
+
+Q_CONSTRUCTOR_FUNCTION(initLocale)
+
 QTEST_MAIN(JobTest)
 
 // The code comes partly from kdebase/kioslave/trash/testtrash.cpp
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.