fix: honor DirectoryIsValid create flag; unbreak Windows CI tests

DirectoryIsValid() ignored try_to_create_if_not_exists and always
called mkpath(). On the Windows CI runner (which may create dirs at
the drive root) PathWidget validation both created bogus directories
and never flagged invalid paths; on Linux the mkpath just failed.

- filefunctions: only mkpath when try_to_create_if_not_exists is set
- TaskProjectLoadTest: Project::set_filename() stores native
  separators on Windows, normalize before comparing paths
- DialogProjectProperties: use a nonexistent file inside a temp dir
  instead of a fixed /definitely/... path that prior tests may have
  partially created on a writable drive
This commit is contained in:
2026-07-17 20:35:25 +08:00
parent c734ecdba1
commit 016341ea7c
3 changed files with 13 additions and 4 deletions
+2 -1
View File
@@ -168,7 +168,8 @@ bool FileFunctions::DirectoryIsValid(const QDir &d,
bool try_to_create_if_not_exists) bool try_to_create_if_not_exists)
{ {
// Return whether the directory exists, or whether it could be created if it doesn't // Return whether the directory exists, or whether it could be created if it doesn't
return d.exists() || d.mkpath(QStringLiteral(".")); return d.exists() ||
(try_to_create_if_not_exists && d.mkpath(QStringLiteral(".")));
} }
QString FileFunctions::EnsureFilenameExtension(QString fn, QString FileFunctions::EnsureFilenameExtension(QString fn,
+8 -2
View File
@@ -9,6 +9,7 @@
#include <QGroupBox> #include <QGroupBox>
#include <QLineEdit> #include <QLineEdit>
#include <QStandardPaths> #include <QStandardPaths>
#include <QTemporaryDir>
#include <QTreeWidget> #include <QTreeWidget>
#include <QXmlStreamReader> #include <QXmlStreamReader>
#include <QXmlStreamWriter> #include <QXmlStreamWriter>
@@ -803,8 +804,13 @@ TEST(DialogProjectProperties, OcioValidationTogglesOnInvalidFilename)
auto *ocio_edit = dialog.findChild<QLineEdit *>(); auto *ocio_edit = dialog.findChild<QLineEdit *>();
ASSERT_NE(ocio_edit, nullptr); ASSERT_NE(ocio_edit, nullptr);
// A bad config path flags the line edit as invalid (red text) // A bad config path flags the line edit as invalid (red text). Use a
ocio_edit->setText(QStringLiteral("/definitely/not/a/config.ocio")); // nonexistent file inside a temp dir: a fixed absolute path is not
// guaranteed to stay nonexistent on every platform (e.g. an earlier test
// may have created parts of it on a writable drive).
QTemporaryDir dir;
ASSERT_TRUE(dir.isValid());
ocio_edit->setText(dir.filePath(QStringLiteral("nonexistent.ocio")));
EXPECT_TRUE(ocio_edit->styleSheet().contains(QStringLiteral("red"))); EXPECT_TRUE(ocio_edit->styleSheet().contains(QStringLiteral("red")));
// Restoring an empty (default) filename clears the error again // Restoring an empty (default) filename clears the error again
+3 -1
View File
@@ -312,7 +312,9 @@ TEST_F(TaskProjectLoadTest, LoadingValidProjectSucceeds)
olive::Project *loaded = task.GetLoadedProject(); olive::Project *loaded = task.GetLoadedProject();
ASSERT_NE(loaded, nullptr); ASSERT_NE(loaded, nullptr);
EXPECT_EQ(loaded->filename(), path); // Project::set_filename() stores native separators on Windows
EXPECT_EQ(QDir::fromNativeSeparators(loaded->filename()),
QDir::fromNativeSeparators(path));
EXPECT_FALSE(loaded->nodes().isEmpty()); EXPECT_FALSE(loaded->nodes().isEmpty());
delete loaded; delete loaded;