TemporaryDirectory: Automatically add a dash after the prefix

This commit is contained in:
Kamil Śliwak 2021-07-20 12:17:42 +02:00
parent 251de730ed
commit fb6a25715d
3 changed files with 6 additions and 6 deletions

View File

@ -31,7 +31,7 @@ using namespace solidity::test;
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
TemporaryDirectory::TemporaryDirectory(std::string const& _prefix): TemporaryDirectory::TemporaryDirectory(std::string const& _prefix):
m_path(fs::temp_directory_path() / fs::unique_path(_prefix + "%%%%-%%%%-%%%%-%%%%")) m_path(fs::temp_directory_path() / fs::unique_path(_prefix + "-%%%%-%%%%-%%%%-%%%%"))
{ {
// Prefix should just be a file name and not contain anything that would make us step out of /tmp. // Prefix should just be a file name and not contain anything that would make us step out of /tmp.
assert(fs::path(_prefix) == fs::path(_prefix).stem()); assert(fs::path(_prefix) == fs::path(_prefix).stem());

View File

@ -40,7 +40,7 @@ namespace solidity::test
class TemporaryDirectory class TemporaryDirectory
{ {
public: public:
TemporaryDirectory(std::string const& _prefix = "solidity-test-"); TemporaryDirectory(std::string const& _prefix = "solidity-test");
~TemporaryDirectory(); ~TemporaryDirectory();
boost::filesystem::path const& path() const { return m_path; } boost::filesystem::path const& path() const { return m_path; }

View File

@ -37,10 +37,10 @@ BOOST_AUTO_TEST_CASE(TemporaryDirectory_should_create_and_delete_a_unique_and_em
{ {
fs::path dirPath; fs::path dirPath;
{ {
TemporaryDirectory tempDir("temporary-directory-test-"); TemporaryDirectory tempDir("temporary-directory-test");
dirPath = tempDir.path(); dirPath = tempDir.path();
BOOST_TEST(dirPath.stem().string().find("temporary-directory-test-") == 0); BOOST_TEST(dirPath.stem().string().find("temporary-directory-test") == 0);
BOOST_TEST(fs::equivalent(dirPath.parent_path(), fs::temp_directory_path())); BOOST_TEST(fs::equivalent(dirPath.parent_path(), fs::temp_directory_path()));
BOOST_TEST(fs::is_directory(dirPath)); BOOST_TEST(fs::is_directory(dirPath));
BOOST_TEST(fs::is_empty(dirPath)); BOOST_TEST(fs::is_empty(dirPath));
@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE(TemporaryDirectory_should_delete_its_directory_even_if_not_
{ {
fs::path dirPath; fs::path dirPath;
{ {
TemporaryDirectory tempDir("temporary-directory-test-"); TemporaryDirectory tempDir("temporary-directory-test");
dirPath = tempDir.path(); dirPath = tempDir.path();
BOOST_TEST(fs::is_directory(dirPath)); BOOST_TEST(fs::is_directory(dirPath));
@ -73,7 +73,7 @@ BOOST_AUTO_TEST_CASE(TemporaryWorkingDirectory_should_change_and_restore_working
try try
{ {
{ {
TemporaryDirectory tempDir("temporary-directory-test-"); TemporaryDirectory tempDir("temporary-directory-test");
assert(fs::equivalent(fs::current_path(), originalWorkingDirectory)); assert(fs::equivalent(fs::current_path(), originalWorkingDirectory));
assert(!fs::equivalent(tempDir.path(), originalWorkingDirectory)); assert(!fs::equivalent(tempDir.path(), originalWorkingDirectory));