20 #ifndef TEST_UNIT_TEST_DIRGUARD_H
21 #define TEST_UNIT_TEST_DIRGUARD_H
23 #include <ripple/basics/contract.h>
24 #include <boost/filesystem.hpp>
25 #include <test/jtx/TestSuite.h>
37 using path = boost::filesystem::path;
49 if (is_directory(toRm) && is_empty(toRm))
52 test_.log <<
"Expected " << toRm.string()
53 <<
" to be an empty existing directory." <<
std::endl;
57 DirGuard(beast::unit_test::suite& test,
path subDir,
bool useCounter =
true)
60 using namespace boost::filesystem;
62 static auto subDirCounter = 0;
76 Throw<std::runtime_error>(
77 "Cannot create directory: " +
subDir_.string());
85 using namespace boost::filesystem;
111 bool created_ =
false;
115 beast::unit_test::suite& test,
119 bool useCounter =
true,
121 :
DirGuard(test, subDir, useCounter)
122 , file_(file.is_absolute() ? file :
subdir() / file)
135 Throw<std::runtime_error>(
136 "Refusing to overwrite existing file: " + file_.string());
144 using namespace boost::filesystem;
152 test_.log <<
"Expected " << file_.string()
153 <<
" to be an existing file." <<
std::endl;
172 return boost::filesystem::exists(file_);
180 #endif // TEST_UNIT_TEST_DIRGUARD_H