From 4cb9ac6d320f9fecea1fec97a2246b3fdb596e7c Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (l)" <j.wuttke@fz-juelich.de> Date: Wed, 24 Aug 2016 19:55:54 +0200 Subject: [PATCH] glob without glob.h which is not available under Windows --- Core/Tools/FileSystem.cpp | 6 +++--- .../PyCore/persistence/PyPersistenceTest.cpp | 17 +++++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Core/Tools/FileSystem.cpp b/Core/Tools/FileSystem.cpp index 930714c8ef8..8b0dcd1c89f 100644 --- a/Core/Tools/FileSystem.cpp +++ b/Core/Tools/FileSystem.cpp @@ -70,8 +70,8 @@ std::string FileSystem::filename(const std::string& path) std::vector<std::string> FileSystem::reglob(const std::string& dir, const std::string& pattern) { std::vector<std::string> ret; - for (const std::string& fname: filesInDirectory(dir)) { - ret.push_back(fname); - } + for (const std::string& fname: filesInDirectory(dir)) + if (std::regex_match(fname, std::regex(pattern))) + ret.push_back(fname); return ret; } diff --git a/Tests/Functional/PyCore/persistence/PyPersistenceTest.cpp b/Tests/Functional/PyCore/persistence/PyPersistenceTest.cpp index 6f563eb93a1..20965ecae7b 100644 --- a/Tests/Functional/PyCore/persistence/PyPersistenceTest.cpp +++ b/Tests/Functional/PyCore/persistence/PyPersistenceTest.cpp @@ -36,18 +36,16 @@ PyPersistenceTest::PyPersistenceTest( //! Runs a Python script, and returns true if the output of the script agrees with reference data. bool PyPersistenceTest::runTest() { - std::string dat_stem = FileSystem::GetJoinPath(PYPERSIST_OUT_DIR, getName()); - std::string ref_stem = FileSystem::GetJoinPath(PYPERSIST_REF_DIR, getName()); - // Remove old output for (const std::string& fname: - FileSystem::reglob(PYPERSIST_OUT_DIR, getName()+"\\.\\w+\\.\\w+")) { + FileSystem::reglob(PYPERSIST_OUT_DIR, getName()+"\\.\\w+\\..+")) { std::remove( fname.c_str() ); std::cout << "Removed old output " << fname.c_str() << "\n"; } // Run Python script std::string pyscript_filename = FileSystem::GetJoinPath(m_directory, getName()+".py"); + std::string dat_stem = FileSystem::GetJoinPath(PYPERSIST_OUT_DIR, getName()); if (!runPython(pyscript_filename + " " + dat_stem)) return false; @@ -58,12 +56,15 @@ bool PyPersistenceTest::runTest() std::cerr << "There is no test output of form " << dat_stem << ".*.*\n"; return false; } + // Compare the keys in the file names if (!compareFileMaps(dat, ref)) return false; // Compare files one by one for (auto const& it: dat) - if (!compareFilePair( it.second, ref[it.first] ) ) + if (!compareFilePair( + FileSystem::GetJoinPath(PYPERSIST_OUT_DIR, it.second), + FileSystem::GetJoinPath(PYPERSIST_REF_DIR, ref[it.first]))) return false; return true; } @@ -74,10 +75,10 @@ std::map<const std::string, const std::string> PyPersistenceTest::glob2map(const std::string& dir, const std::string& stem) { std::map<const std::string, const std::string> ret; - for (const std::string& fpath: FileSystem::reglob(dir, stem+"\\.\\w+\\.\\w+")) { + for (const std::string& fname: FileSystem::reglob(dir, stem+"\\.\\w+\\..+")) { std::vector<std::string> fname_segments = - Utils::String::split(FileSystem::filename(fpath), "."); - ret.insert(make_pair(fname_segments[1]+"."+fname_segments[2], fpath)); + Utils::String::split(FileSystem::filename(fname), "."); + ret.insert(make_pair(fname_segments[1]+"."+fname_segments[2], fname)); } return ret; } -- GitLab