From 75765406633cdd9414fa18489c8f9a583fda9a25 Mon Sep 17 00:00:00 2001 From: Simon Perret Date: Thu, 11 Jul 2024 16:14:39 +0200 Subject: [PATCH] fix: save settings file in different directory in testing mode before this commit, we didn't save json files in test mode, so as not to overwrite the json file already present in the user's home directory. now we save this json file in the temp directory. We have also improved tst_settings.cpp, which now saves the json file in the temp directory. --- src/core/settings.cpp | 7 +++---- tests/tst_settings.cpp | 3 +-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/core/settings.cpp b/src/core/settings.cpp index eaadaf17..0da0badd 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -231,6 +231,9 @@ bool Settings::setValue(QString path, const QVariant &value) QString Settings::userFilePath() const { + if (isTesting()) { + return QDir::tempPath() + '/' + SettingsName; + } return QDir::homePath() + '/' + SettingsName; } @@ -268,10 +271,6 @@ void Settings::loadKnutSettings() void Settings::saveSettings() { - // Don't save settings if testing - if (isTesting()) - return; - const auto &settings = isUser() ? m_userSettings : m_projectSettings; const auto &filePath = isUser() ? userFilePath() : projectFilePath(); diff --git a/tests/tst_settings.cpp b/tests/tst_settings.cpp index c85d9410..7fe6a03f 100644 --- a/tests/tst_settings.cpp +++ b/tests/tst_settings.cpp @@ -18,12 +18,11 @@ /////////////////////////////////////////////////////////////////////////////// // Tests Data /////////////////////////////////////////////////////////////////////////////// -// Use a test fixture for Settings, to be able to save (even if it's used in a test) class SettingsFixture : public Core::Settings { public: SettingsFixture() - : Settings(Core::Settings::Mode::Cli) // Not Testing + : Settings(Core::Settings::Mode::Test) { } };