mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
TemporaryDirectory: Use soltestAssert() instead of assert() and remove filesystem namespace alias
This commit is contained in:
parent
fb6a25715d
commit
5a0a0af48f
@ -18,9 +18,10 @@
|
||||
|
||||
#include <test/TemporaryDirectory.h>
|
||||
|
||||
#include <test/libsolidity/util/SoltestErrors.h>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <regex>
|
||||
#include <iostream>
|
||||
|
||||
@ -34,7 +35,7 @@ TemporaryDirectory::TemporaryDirectory(std::string const& _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.
|
||||
assert(fs::path(_prefix) == fs::path(_prefix).stem());
|
||||
soltestAssert(fs::path(_prefix) == fs::path(_prefix).stem(), "");
|
||||
|
||||
fs::create_directory(m_path);
|
||||
}
|
||||
@ -42,10 +43,10 @@ TemporaryDirectory::TemporaryDirectory(std::string const& _prefix):
|
||||
TemporaryDirectory::~TemporaryDirectory()
|
||||
{
|
||||
// A few paranoid sanity checks just to be extra sure we're not deleting someone's homework.
|
||||
assert(m_path.string().find(fs::temp_directory_path().string()) == 0);
|
||||
assert(!fs::equivalent(m_path, fs::temp_directory_path()));
|
||||
assert(!fs::equivalent(m_path, m_path.root_path()));
|
||||
assert(!m_path.empty());
|
||||
soltestAssert(m_path.string().find(fs::temp_directory_path().string()) == 0, "");
|
||||
soltestAssert(!fs::equivalent(m_path, fs::temp_directory_path()), "");
|
||||
soltestAssert(!fs::equivalent(m_path, m_path.root_path()), "");
|
||||
soltestAssert(!m_path.empty(), "");
|
||||
|
||||
boost::system::error_code errorCode;
|
||||
uintmax_t numRemoved = fs::remove_all(m_path, errorCode);
|
||||
|
@ -18,6 +18,8 @@
|
||||
|
||||
#include <test/TemporaryDirectory.h>
|
||||
|
||||
#include <test/libsolidity/util/SoltestErrors.h>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
@ -26,8 +28,6 @@
|
||||
using namespace std;
|
||||
using namespace boost::test_tools;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
namespace solidity::test
|
||||
{
|
||||
|
||||
@ -35,59 +35,59 @@ BOOST_AUTO_TEST_SUITE(TemporaryDirectoryTest)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TemporaryDirectory_should_create_and_delete_a_unique_and_empty_directory)
|
||||
{
|
||||
fs::path dirPath;
|
||||
boost::filesystem::path dirPath;
|
||||
{
|
||||
TemporaryDirectory tempDir("temporary-directory-test");
|
||||
dirPath = tempDir.path();
|
||||
|
||||
BOOST_TEST(dirPath.stem().string().find("temporary-directory-test") == 0);
|
||||
BOOST_TEST(fs::equivalent(dirPath.parent_path(), fs::temp_directory_path()));
|
||||
BOOST_TEST(fs::is_directory(dirPath));
|
||||
BOOST_TEST(fs::is_empty(dirPath));
|
||||
BOOST_TEST(boost::filesystem::equivalent(dirPath.parent_path(), boost::filesystem::temp_directory_path()));
|
||||
BOOST_TEST(boost::filesystem::is_directory(dirPath));
|
||||
BOOST_TEST(boost::filesystem::is_empty(dirPath));
|
||||
}
|
||||
BOOST_TEST(!fs::exists(dirPath));
|
||||
BOOST_TEST(!boost::filesystem::exists(dirPath));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TemporaryDirectory_should_delete_its_directory_even_if_not_empty)
|
||||
{
|
||||
fs::path dirPath;
|
||||
boost::filesystem::path dirPath;
|
||||
{
|
||||
TemporaryDirectory tempDir("temporary-directory-test");
|
||||
dirPath = tempDir.path();
|
||||
|
||||
BOOST_TEST(fs::is_directory(dirPath));
|
||||
BOOST_TEST(boost::filesystem::is_directory(dirPath));
|
||||
|
||||
{
|
||||
ofstream tmpFile((dirPath / "test-file.txt").string());
|
||||
tmpFile << "Delete me!" << endl;
|
||||
}
|
||||
assert(fs::is_regular_file(dirPath / "test-file.txt"));
|
||||
soltestAssert(boost::filesystem::is_regular_file(dirPath / "test-file.txt"), "");
|
||||
}
|
||||
BOOST_TEST(!fs::exists(dirPath / "test-file.txt"));
|
||||
BOOST_TEST(!boost::filesystem::exists(dirPath / "test-file.txt"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TemporaryWorkingDirectory_should_change_and_restore_working_directory)
|
||||
{
|
||||
fs::path originalWorkingDirectory = fs::current_path();
|
||||
boost::filesystem::path originalWorkingDirectory = boost::filesystem::current_path();
|
||||
|
||||
try
|
||||
{
|
||||
{
|
||||
TemporaryDirectory tempDir("temporary-directory-test");
|
||||
assert(fs::equivalent(fs::current_path(), originalWorkingDirectory));
|
||||
assert(!fs::equivalent(tempDir.path(), originalWorkingDirectory));
|
||||
soltestAssert(boost::filesystem::equivalent(boost::filesystem::current_path(), originalWorkingDirectory), "");
|
||||
soltestAssert(!boost::filesystem::equivalent(tempDir.path(), originalWorkingDirectory), "");
|
||||
|
||||
TemporaryWorkingDirectory tempWorkDir(tempDir.path());
|
||||
|
||||
BOOST_TEST(fs::equivalent(fs::current_path(), tempDir.path()));
|
||||
BOOST_TEST(boost::filesystem::equivalent(boost::filesystem::current_path(), tempDir.path()));
|
||||
}
|
||||
BOOST_TEST(fs::equivalent(fs::current_path(), originalWorkingDirectory));
|
||||
BOOST_TEST(boost::filesystem::equivalent(boost::filesystem::current_path(), originalWorkingDirectory));
|
||||
|
||||
fs::current_path(originalWorkingDirectory);
|
||||
boost::filesystem::current_path(originalWorkingDirectory);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
fs::current_path(originalWorkingDirectory);
|
||||
boost::filesystem::current_path(originalWorkingDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user