Fix tst_elementautonumids on macOS: give the binary its settings through QET_SETTINGS_DIR

duplicatesAreNotNumberedWhenSwitchedOff turns two preferences off by
writing <home>/config/QElectroTech/QElectroTech.conf and pointing
XDG_CONFIG_HOME there. Only Linux reads settings from that file. macOS
keeps them in the system preferences, so the binary never saw the two
preferences, numbered the pasted duplicates anyway, and the test failed
on macOS, on master too.

Write the file where QET_SETTINGS_DIR points instead (#1178), and set that
variable for every run of the binary, so no run reads the user's own
settings either.

No file-format change. Tests: tst_elementautonumids fails on master on
macOS and passes with this change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Beat Hangartner <beat@hangartners.ch>
This commit is contained in:
Beat Hangartner
2026-10-06 10:53:10 +02:00
parent 85342f4b56
commit 43cc013e54
+6 -2
View File
@@ -47,14 +47,18 @@ class tst_elementautonumids : public QObject
{
const QString home = m_dir.filePath(QStringLiteral("home%1").arg(m_run++));
QDir().mkpath(home);
// QET_SETTINGS_DIR, not a file under XDG_CONFIG_HOME: macOS and
// Windows keep the settings elsewhere and would never read it.
const QString settings_dir = home + QStringLiteral("/settings");
if (!m_preferences.isEmpty()) {
QDir().mkpath(home + QStringLiteral("/config/QElectroTech"));
QFile settings(home + QStringLiteral("/config/QElectroTech/QElectroTech.conf"));
QDir().mkpath(settings_dir + QStringLiteral("/QElectroTech"));
QFile settings(settings_dir + QStringLiteral("/QElectroTech/QElectroTech.ini"));
if (settings.open(QIODevice::WriteOnly)) {
settings.write(m_preferences.toUtf8());
}
}
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert(QStringLiteral("QET_SETTINGS_DIR"), settings_dir);
env.insert(QStringLiteral("QT_QPA_PLATFORM"), QStringLiteral("offscreen"));
env.insert(QStringLiteral("QET_ENABLE_SCRIPTING"), QStringLiteral("1"));
env.insert(QStringLiteral("HOME"), home);