From 93c86fe5cd5ab3e17fbf78dac0f3afd571696134 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 10 Feb 2022 13:36:49 +0000 Subject: [PATCH 1/3] Fix harmless signed/unsigned warning in wxRegEx unit test Cast the expected number of matches to "int" to have the same type as wxRegEx::Replace() return value -- there is no danger of truncation here as we're never going to expect billions of matches. --- tests/regex/wxregextest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/regex/wxregextest.cpp b/tests/regex/wxregextest.cpp index ce5721d4b0..e1d58d1f65 100644 --- a/tests/regex/wxregextest.cpp +++ b/tests/regex/wxregextest.cpp @@ -141,7 +141,7 @@ CheckReplace(const char* pattern, wxRegEx re(pattern); wxString text(original); - CHECK( re.Replace(&text, replacement) == numMatches ); + CHECK( re.Replace(&text, replacement) == static_cast(numMatches) ); CHECK( text == expected ); } From 046f228bb21104bec8f1ece08ca19ac6825b9a7f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 10 Feb 2022 13:38:00 +0000 Subject: [PATCH 2/3] Reset watch directory in wxFileSystemWatcher unit test Share the same variable between GetWatchDir() and RemoveWatchDir() to make things more clear. Also check for GetWatchDir() postcondition (i.e. that the directory exists) in the function itself instead of doing it in the caller. --- tests/fswatcher/fswatchertest.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/tests/fswatcher/fswatchertest.cpp b/tests/fswatcher/fswatchertest.cpp index 19aea462fb..eff0df1298 100644 --- a/tests/fswatcher/fswatchertest.cpp +++ b/tests/fswatcher/fswatchertest.cpp @@ -128,32 +128,32 @@ public: // static helpers static const wxFileName& GetWatchDir() { - static wxFileName dir; - - if (dir.DirExists()) - return dir; + if (ms_watchDir.DirExists()) + return ms_watchDir; wxString tmp = wxStandardPaths::Get().GetTempDir(); - dir.AssignDir(tmp); + ms_watchDir.AssignDir(tmp); // XXX look for more unique name? there is no function to generate // unique filename, the file always get created... - dir.AppendDir("fswatcher_test"); - REQUIRE(!dir.DirExists()); - REQUIRE(dir.Mkdir()); + ms_watchDir.AppendDir("fswatcher_test"); + REQUIRE(!ms_watchDir.DirExists()); + REQUIRE(ms_watchDir.Mkdir()); + REQUIRE(ms_watchDir.DirExists()); - return dir; + return ms_watchDir; } static void RemoveWatchDir() { - wxFileName dir = GetWatchDir(); - REQUIRE(dir.DirExists()); + REQUIRE(ms_watchDir.DirExists()); // just to be really sure we know what we remove - REQUIRE( dir.GetDirs().Last() == "fswatcher_test" ); + REQUIRE( ms_watchDir.GetDirs().Last() == "fswatcher_test" ); - CHECK( dir.Rmdir(wxPATH_RMDIR_RECURSIVE) ); + CHECK( ms_watchDir.Rmdir(wxPATH_RMDIR_RECURSIVE) ); + + ms_watchDir = wxFileName(); } static wxFileName RandomName(const wxFileName& base, int length = 10) @@ -178,9 +178,13 @@ public: protected: static EventGenerator* ms_instance; + +private: + static wxFileName ms_watchDir; }; EventGenerator* EventGenerator::ms_instance = 0; +wxFileName EventGenerator::ms_watchDir; // Abstract base class from which concrete event tests inherit. @@ -799,7 +803,6 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, // We don't use this function for events. Just run the tests wxFileName watchdir = EventGenerator::GetWatchDir(); - REQUIRE(watchdir.DirExists()); wxFileName treedir(watchdir); treedir.AppendDir("treetrunk"); From 34ca92d36252ec9dcb0375f7379000301fda6cb9 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 10 Feb 2022 13:55:54 +0000 Subject: [PATCH 3/3] Show logs in case of Mkdir or Rmdir failures in wxFSW unit tests Try to gather more information about the test failures on GitHub Actions when creating or removing the test directory that isn't reproducible locally. --- tests/fswatcher/fswatchertest.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/fswatcher/fswatchertest.cpp b/tests/fswatcher/fswatchertest.cpp index eff0df1298..eb16020d4a 100644 --- a/tests/fswatcher/fswatchertest.cpp +++ b/tests/fswatcher/fswatchertest.cpp @@ -23,6 +23,7 @@ #include "wx/filename.h" #include "wx/filefn.h" #include "wx/fswatcher.h" +#include "wx/log.h" #include "wx/scopedptr.h" #include "wx/stdpaths.h" #include "wx/vector.h" @@ -33,6 +34,27 @@ // local functions // ---------------------------------------------------------------------------- +#if wxUSE_LOG +// Logging is disabled by default when running the tests, but sometimes it can +// be helpful to see the errors in case of unexpected failure, so this class +// re-enables logs in its scope. +// +// It's a counterpart to wxLogNull. +class LogEnabler +{ +public: + LogEnabler() : m_wasEnabled(wxLog::EnableLogging(true)) { } + ~LogEnabler() { wxLog::EnableLogging(m_wasEnabled); } + +private: + const bool m_wasEnabled; + + wxDECLARE_NO_COPY_CLASS(LogEnabler); +}; +#else // !wxUSE_LOG +class LogEnabler { }; +#endif // wxUSE_LOG/!wxUSE_LOG + // class generating file system events class EventGenerator { @@ -138,7 +160,10 @@ public: // unique filename, the file always get created... ms_watchDir.AppendDir("fswatcher_test"); REQUIRE(!ms_watchDir.DirExists()); + + LogEnabler enableLogs; REQUIRE(ms_watchDir.Mkdir()); + REQUIRE(ms_watchDir.DirExists()); return ms_watchDir; @@ -151,6 +176,7 @@ public: // just to be really sure we know what we remove REQUIRE( ms_watchDir.GetDirs().Last() == "fswatcher_test" ); + LogEnabler enableLogs; CHECK( ms_watchDir.Rmdir(wxPATH_RMDIR_RECURSIVE) ); ms_watchDir = wxFileName();