Skip to content

Commit

Permalink
fix: save settings file in different directory in testing mode
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
smnppKDAB authored and narnaud committed Jul 12, 2024
1 parent ed03e9b commit 7576540
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/core/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();

Expand Down
3 changes: 1 addition & 2 deletions tests/tst_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
};
Expand Down

0 comments on commit 7576540

Please sign in to comment.