Merge branch 'fsw-tests'
Try to do something about recurrent failures in wxFSW unit tests. See #22119.
This commit is contained in:
@@ -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
|
||||
{
|
||||
@@ -128,32 +150,36 @@ 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());
|
||||
|
||||
return dir;
|
||||
LogEnabler enableLogs;
|
||||
REQUIRE(ms_watchDir.Mkdir());
|
||||
|
||||
REQUIRE(ms_watchDir.DirExists());
|
||||
|
||||
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) );
|
||||
LogEnabler enableLogs;
|
||||
CHECK( ms_watchDir.Rmdir(wxPATH_RMDIR_RECURSIVE) );
|
||||
|
||||
ms_watchDir = wxFileName();
|
||||
}
|
||||
|
||||
static wxFileName RandomName(const wxFileName& base, int length = 10)
|
||||
@@ -178,9 +204,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 +829,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");
|
||||
|
||||
@@ -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<int>(numMatches) );
|
||||
CHECK( text == expected );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user