Commit 6c6ee800 authored by GILLES Sebastien's avatar GILLES Sebastien

#1480 Add in the Directory tests two checks about subdirectories - and amend...

#1480 Add in the Directory tests two checks about subdirectories - and amend the code so that these new tests pass correctly!
parent 2008e6cd
......@@ -186,6 +186,57 @@ BOOST_FIXTURE_TEST_CASE(ask_on_rank, fixture)
}
BOOST_FIXTURE_TEST_CASE(subdirectory, fixture)
{
decltype(auto) mpi = GetMpi();
decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
decltype(auto) test_dir = environment.GetEnvironmentVariable("MOREFEM_TEST_OUTPUT_DIR", __FILE__, __LINE__);
const std::string directory_test = test_dir + "/directory_test/";
FilesystemNS::Directory directory(mpi,
directory_test,
FilesystemNS::behaviour::overwrite,
__FILE__, __LINE__);
FilesystemNS::Directory subdirectory(directory,
"Subdirectory",
__FILE__, __LINE__);
std::ostringstream oconv;
oconv << directory_test << "Rank_" << mpi.GetRank<int>() << "/Subdirectory";
BOOST_CHECK(FilesystemNS::Folder::DoExist(oconv.str()));
}
BOOST_FIXTURE_TEST_CASE(subdirectory_not_existing, fixture)
{
decltype(auto) mpi = GetMpi();
decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
decltype(auto) test_dir = environment.GetEnvironmentVariable("MOREFEM_TEST_OUTPUT_DIR", __FILE__, __LINE__);
const std::string directory_test = test_dir + "/directory_test/";
FilesystemNS::Directory directory(mpi,
directory_test,
FilesystemNS::behaviour::read,
__FILE__, __LINE__);
// Throw because it doesn't exist and behaviour is read.
BOOST_CHECK_THROW(FilesystemNS::Directory subdirectory(directory,
"NotExisting",
__FILE__, __LINE__),
Exception);
}
PRAGMA_DIAGNOSTIC(pop)
......
......@@ -235,6 +235,11 @@ namespace MoReFEM::FilesystemNS
std::cin >> answer;
#ifndef NDEBUG
std::cout << "\t answer read = |" << answer << '|' << std::endl;
#endif // NDEBUG
} while (!std::cin);
}
......
......@@ -14,31 +14,11 @@
# include <string>
# include <sstream>
# include <memory>
# include <iostream> // TMP
# include "Utilities/Exceptions/Exception.hpp"
# include "Utilities/Filesystem/Folder.hpp"
// ============================
//! \cond IGNORE_BLOCK_IN_DOXYGEN
// Forward declarations.
// ============================
namespace MoReFEM::Wrappers
{
class Mpi;
} // namespace MoReFEM::Wrappers
// ============================
// End of forward declarations.
//! \endcond IGNORE_BLOCK_IN_DOXYGEN
// ============================
# include "ThirdParty/Wrappers/Mpi/Mpi.hpp"
namespace MoReFEM::FilesystemNS
......
......@@ -20,25 +20,27 @@ namespace MoReFEM::FilesystemNS
Directory::Directory(const Directory& directory,
const StringT& subdirectory,
const char* invoking_file, int invoking_line)
: Directory(directory.GetMpi(),
directory.GetPath(),
behaviour::ignore, // By definition this directory should already exists!
invoking_file, invoking_line)
: mpi_(directory.GetMpi()),
directory_behaviour_(directory.GetBehaviour())
{
std::ostringstream oconv;
if (Folder::DoExist(directory.GetPath()))
if (!Folder::DoExist(directory.GetPath()))
{
oconv << "Directory '" << directory.GetPath() << "' couldn't be found whereas we were trying to build a "
"subdirectory from it (so the directory has been created at some point and then removed.";
"subdirectory from it (so the directory has been created at some point and then removed).";
throw Exception(oconv.str(), invoking_file, invoking_line);
}
oconv << GetPath() << '/' << subdirectory;
oconv << directory.GetPath() << subdirectory << '/';
path_ = oconv.str();
// Use the same policy as for the parent directoru.
directory_behaviour_ = directory.GetBehaviour();
if (GetMpi().IsRootProcessor())
{
oconv.str("");
oconv << directory.GetWildcardPath() << subdirectory << '/';
wildcard_path_ = oconv.str();
}
Construct(invoking_file, invoking_line);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment