Commit 1de6040a authored by GILLES Sebastien's avatar GILLES Sebastien

#1480 Directory: introduce the 'create' behaviour (along with its test).

parent 8e77bd6e
......@@ -15,6 +15,7 @@
#include "Utilities/Filesystem/Directory.hpp"
#include "Utilities/Filesystem/File.hpp"
#include "Utilities/Environment/Environment.hpp"
#include "Utilities/String/String.hpp"
#include "Test/Tools/Fixture/Mpi.hpp"
#include "Test/Tools/Fixture/Environment.hpp"
......@@ -48,6 +49,29 @@ PRAGMA_DIAGNOSTIC(ignored "-Wdisabled-macro-expansion")
# endif // __clang__
BOOST_FIXTURE_TEST_CASE(create, fixture)
{
decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
decltype(auto) test_dir = environment.GetEnvironmentVariable("MOREFEM_TEST_OUTPUT_DIR", __FILE__, __LINE__);
decltype(auto) mpi = GetMpi();
std::string path = test_dir + "/directory_test/" + Utilities::String::GenerateRandomString(10);
FilesystemNS::Directory create(mpi,
path,
FilesystemNS::behaviour::create,
__FILE__, __LINE__);
BOOST_CHECK(FilesystemNS::Folder::DoExist(create));
BOOST_CHECK_THROW(FilesystemNS::Directory create_once_again(mpi,
path,
FilesystemNS::behaviour::create,
__FILE__, __LINE__),
Exception);
}
BOOST_FIXTURE_TEST_CASE(overwrite, fixture)
{
decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
......
......@@ -138,6 +138,13 @@ namespace MoReFEM::FilesystemNS
case behaviour::read:
// Do nothing: we expects it to exist!
break;
case behaviour::create:
{
std::ostringstream oconv;
oconv << "Directory " << path_ << " already exists whereas it was expected not to (maybe the "
"behaviour set at call site was not the proper one).";
throw Exception(oconv.str(), invoking_file, invoking_line);
}
}
}
else
......@@ -148,6 +155,7 @@ namespace MoReFEM::FilesystemNS
case behaviour::overwrite:
case behaviour::ignore:
case behaviour::quit:
case behaviour::create:
Folder::Create(path_, invoking_file, invoking_line);
break;
case behaviour::read:
......@@ -158,6 +166,7 @@ namespace MoReFEM::FilesystemNS
throw Exception(oconv.str(), __FILE__, __LINE__);
}
break;
}
}
}
......@@ -249,6 +258,9 @@ namespace MoReFEM::FilesystemNS
case behaviour::read:
out << "read";
break;
case behaviour::create:
out << "create";
break;
}
return out;
......
......@@ -36,6 +36,8 @@ namespace MoReFEM::FilesystemNS
* - quit: Quit the program if the directory exists.
* - ignore: Do not create the directory and use the existing one (including possible previous content).
* - read: this mode expects the directory to exist and throws an exception otherwise.
* - create: create a new directory - it is expected here it doesn't exist yet (and an exception is thrown if it
* does).
*/
......@@ -50,10 +52,8 @@ namespace MoReFEM::FilesystemNS
ask,
quit,
ignore,
read
// TMP 'create' should be added!
// create_behaviour
// read_behaviour
read,
create
};
//! \copydoc doxygen_hide_std_stream_out_overload
......
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