mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
TemporaryDirectory: Add automatic conversions to boost::filesystem::path
This commit is contained in:
parent
5a0a0af48f
commit
9dc7360903
@ -44,6 +44,7 @@ public:
|
|||||||
~TemporaryDirectory();
|
~TemporaryDirectory();
|
||||||
|
|
||||||
boost::filesystem::path const& path() const { return m_path; }
|
boost::filesystem::path const& path() const { return m_path; }
|
||||||
|
operator boost::filesystem::path() const { return m_path; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
boost::filesystem::path m_path;
|
boost::filesystem::path m_path;
|
||||||
@ -59,6 +60,7 @@ public:
|
|||||||
~TemporaryWorkingDirectory();
|
~TemporaryWorkingDirectory();
|
||||||
|
|
||||||
boost::filesystem::path const& originalWorkingDirectory() const { return m_originalWorkingDirectory; }
|
boost::filesystem::path const& originalWorkingDirectory() const { return m_originalWorkingDirectory; }
|
||||||
|
operator boost::filesystem::path() const { return boost::filesystem::current_path(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
boost::filesystem::path m_originalWorkingDirectory;
|
boost::filesystem::path m_originalWorkingDirectory;
|
||||||
|
@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_redundant_slashes)
|
|||||||
BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_unc_path)
|
BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_unc_path)
|
||||||
{
|
{
|
||||||
TemporaryDirectory tempDir(TEST_CASE_NAME);
|
TemporaryDirectory tempDir(TEST_CASE_NAME);
|
||||||
TemporaryWorkingDirectory tempWorkDir(tempDir.path());
|
TemporaryWorkingDirectory tempWorkDir(tempDir);
|
||||||
|
|
||||||
// On Windows tempDir.path() normally contains the drive letter while the normalized path should not.
|
// On Windows tempDir.path() normally contains the drive letter while the normalized path should not.
|
||||||
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
|
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
|
||||||
@ -157,7 +157,7 @@ BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_unc_path)
|
|||||||
BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_root_name_only)
|
BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_root_name_only)
|
||||||
{
|
{
|
||||||
TemporaryDirectory tempDir(TEST_CASE_NAME);
|
TemporaryDirectory tempDir(TEST_CASE_NAME);
|
||||||
TemporaryWorkingDirectory tempWorkDir(tempDir.path());
|
TemporaryWorkingDirectory tempWorkDir(tempDir);
|
||||||
|
|
||||||
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
|
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
|
||||||
soltestAssert(expectedWorkDir.is_absolute() || expectedWorkDir.root_path() == "/", "");
|
soltestAssert(expectedWorkDir.is_absolute() || expectedWorkDir.root_path() == "/", "");
|
||||||
@ -187,7 +187,7 @@ BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_root_name_only)
|
|||||||
BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_stripping_root_name)
|
BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_stripping_root_name)
|
||||||
{
|
{
|
||||||
TemporaryDirectory tempDir(TEST_CASE_NAME);
|
TemporaryDirectory tempDir(TEST_CASE_NAME);
|
||||||
TemporaryWorkingDirectory tempWorkDir(tempDir.path());
|
TemporaryWorkingDirectory tempWorkDir(tempDir);
|
||||||
|
|
||||||
soltestAssert(boost::filesystem::current_path().is_absolute(), "");
|
soltestAssert(boost::filesystem::current_path().is_absolute(), "");
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
@ -234,7 +234,7 @@ BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_path_beyond_root)
|
|||||||
BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_case_sensitivity)
|
BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_case_sensitivity)
|
||||||
{
|
{
|
||||||
TemporaryDirectory tempDir(TEST_CASE_NAME);
|
TemporaryDirectory tempDir(TEST_CASE_NAME);
|
||||||
TemporaryWorkingDirectory tempWorkDir(tempDir.path());
|
TemporaryWorkingDirectory tempWorkDir(tempDir);
|
||||||
|
|
||||||
boost::filesystem::path expectedPrefix = "/" / tempDir.path().relative_path();
|
boost::filesystem::path expectedPrefix = "/" / tempDir.path().relative_path();
|
||||||
soltestAssert(expectedPrefix.is_absolute() || expectedPrefix.root_path() == "/", "");
|
soltestAssert(expectedPrefix.is_absolute() || expectedPrefix.root_path() == "/", "");
|
||||||
|
@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE(readFileAsString_regular_file)
|
|||||||
BOOST_AUTO_TEST_CASE(readFileAsString_directory)
|
BOOST_AUTO_TEST_CASE(readFileAsString_directory)
|
||||||
{
|
{
|
||||||
TemporaryDirectory tempDir(TEST_CASE_NAME);
|
TemporaryDirectory tempDir(TEST_CASE_NAME);
|
||||||
BOOST_CHECK_THROW(readFileAsString(tempDir.path()), NotAFile);
|
BOOST_CHECK_THROW(readFileAsString(tempDir), NotAFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(readFileAsString_symlink)
|
BOOST_AUTO_TEST_CASE(readFileAsString_symlink)
|
||||||
|
@ -156,8 +156,8 @@ BOOST_AUTO_TEST_CASE(cli_input)
|
|||||||
{(expectedDir2 / "input2.sol").generic_string(), ""},
|
{(expectedDir2 / "input2.sol").generic_string(), ""},
|
||||||
};
|
};
|
||||||
PathSet expectedAllowedPaths = {
|
PathSet expectedAllowedPaths = {
|
||||||
boost::filesystem::canonical(tempDir1.path()),
|
boost::filesystem::canonical(tempDir1),
|
||||||
boost::filesystem::canonical(tempDir2.path()),
|
boost::filesystem::canonical(tempDir2),
|
||||||
"b/c",
|
"b/c",
|
||||||
"c/d/e",
|
"c/d/e",
|
||||||
};
|
};
|
||||||
@ -191,7 +191,7 @@ BOOST_AUTO_TEST_CASE(cli_ignore_missing_some_files_exist)
|
|||||||
|
|
||||||
// NOTE: Allowed paths should not be added for skipped files.
|
// NOTE: Allowed paths should not be added for skipped files.
|
||||||
map<string, string> expectedSources = {{(expectedDir1 / "input1.sol").generic_string(), ""}};
|
map<string, string> expectedSources = {{(expectedDir1 / "input1.sol").generic_string(), ""}};
|
||||||
PathSet expectedAllowedPaths = {boost::filesystem::canonical(tempDir1.path())};
|
PathSet expectedAllowedPaths = {boost::filesystem::canonical(tempDir1)};
|
||||||
|
|
||||||
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles({
|
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles({
|
||||||
"solc",
|
"solc",
|
||||||
@ -354,14 +354,14 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_no_base_path)
|
|||||||
{
|
{
|
||||||
TemporaryDirectory tempDirCurrent(TEST_CASE_NAME);
|
TemporaryDirectory tempDirCurrent(TEST_CASE_NAME);
|
||||||
TemporaryDirectory tempDirOther(TEST_CASE_NAME);
|
TemporaryDirectory tempDirOther(TEST_CASE_NAME);
|
||||||
TemporaryWorkingDirectory tempWorkDir(tempDirCurrent.path());
|
TemporaryWorkingDirectory tempWorkDir(tempDirCurrent);
|
||||||
soltestAssert(tempDirCurrent.path().is_absolute(), "");
|
soltestAssert(tempDirCurrent.path().is_absolute(), "");
|
||||||
soltestAssert(tempDirOther.path().is_absolute(), "");
|
soltestAssert(tempDirOther.path().is_absolute(), "");
|
||||||
|
|
||||||
// NOTE: On macOS the path usually contains symlinks which prevents base path from being stripped.
|
// NOTE: On macOS the path usually contains symlinks which prevents base path from being stripped.
|
||||||
// Use canonical() to resolve symnlinks and get consistent results on all platforms.
|
// Use canonical() to resolve symnlinks and get consistent results on all platforms.
|
||||||
boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent.path());
|
boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent);
|
||||||
boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther.path());
|
boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther);
|
||||||
|
|
||||||
boost::filesystem::path expectedOtherDir = "/" / otherDirNoSymlinks.relative_path();
|
boost::filesystem::path expectedOtherDir = "/" / otherDirNoSymlinks.relative_path();
|
||||||
soltestAssert(expectedOtherDir.is_absolute() || expectedOtherDir.root_path() == "/", "");
|
soltestAssert(expectedOtherDir.is_absolute() || expectedOtherDir.root_path() == "/", "");
|
||||||
@ -412,14 +412,14 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_base_path_same_as_work_dir)
|
|||||||
{
|
{
|
||||||
TemporaryDirectory tempDirCurrent(TEST_CASE_NAME);
|
TemporaryDirectory tempDirCurrent(TEST_CASE_NAME);
|
||||||
TemporaryDirectory tempDirOther(TEST_CASE_NAME);
|
TemporaryDirectory tempDirOther(TEST_CASE_NAME);
|
||||||
TemporaryWorkingDirectory tempWorkDir(tempDirCurrent.path());
|
TemporaryWorkingDirectory tempWorkDir(tempDirCurrent);
|
||||||
soltestAssert(tempDirCurrent.path().is_absolute(), "");
|
soltestAssert(tempDirCurrent.path().is_absolute(), "");
|
||||||
soltestAssert(tempDirOther.path().is_absolute(), "");
|
soltestAssert(tempDirOther.path().is_absolute(), "");
|
||||||
|
|
||||||
// NOTE: On macOS the path usually contains symlinks which prevents base path from being stripped.
|
// NOTE: On macOS the path usually contains symlinks which prevents base path from being stripped.
|
||||||
// Use canonical() to resolve symnlinks and get consistent results on all platforms.
|
// Use canonical() to resolve symnlinks and get consistent results on all platforms.
|
||||||
boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent.path());
|
boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent);
|
||||||
boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther.path());
|
boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther);
|
||||||
|
|
||||||
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
|
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
|
||||||
boost::filesystem::path expectedOtherDir = "/" / otherDirNoSymlinks.relative_path();
|
boost::filesystem::path expectedOtherDir = "/" / otherDirNoSymlinks.relative_path();
|
||||||
@ -475,16 +475,16 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_base_path_different_from_wor
|
|||||||
TemporaryDirectory tempDirCurrent(TEST_CASE_NAME);
|
TemporaryDirectory tempDirCurrent(TEST_CASE_NAME);
|
||||||
TemporaryDirectory tempDirOther(TEST_CASE_NAME);
|
TemporaryDirectory tempDirOther(TEST_CASE_NAME);
|
||||||
TemporaryDirectory tempDirBase(TEST_CASE_NAME);
|
TemporaryDirectory tempDirBase(TEST_CASE_NAME);
|
||||||
TemporaryWorkingDirectory tempWorkDir(tempDirCurrent.path());
|
TemporaryWorkingDirectory tempWorkDir(tempDirCurrent);
|
||||||
soltestAssert(tempDirCurrent.path().is_absolute(), "");
|
soltestAssert(tempDirCurrent.path().is_absolute(), "");
|
||||||
soltestAssert(tempDirOther.path().is_absolute(), "");
|
soltestAssert(tempDirOther.path().is_absolute(), "");
|
||||||
soltestAssert(tempDirBase.path().is_absolute(), "");
|
soltestAssert(tempDirBase.path().is_absolute(), "");
|
||||||
|
|
||||||
// NOTE: On macOS the path usually contains symlinks which prevents base path from being stripped.
|
// NOTE: On macOS the path usually contains symlinks which prevents base path from being stripped.
|
||||||
// Use canonical() to resolve symnlinks and get consistent results on all platforms.
|
// Use canonical() to resolve symnlinks and get consistent results on all platforms.
|
||||||
boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent.path());
|
boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent);
|
||||||
boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther.path());
|
boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther);
|
||||||
boost::filesystem::path baseDirNoSymlinks = boost::filesystem::canonical(tempDirBase.path());
|
boost::filesystem::path baseDirNoSymlinks = boost::filesystem::canonical(tempDirBase);
|
||||||
|
|
||||||
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
|
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
|
||||||
boost::filesystem::path expectedCurrentDir = "/" / currentDirNoSymlinks.relative_path();
|
boost::filesystem::path expectedCurrentDir = "/" / currentDirNoSymlinks.relative_path();
|
||||||
@ -547,14 +547,14 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_relative_base_path)
|
|||||||
{
|
{
|
||||||
TemporaryDirectory tempDirCurrent(TEST_CASE_NAME);
|
TemporaryDirectory tempDirCurrent(TEST_CASE_NAME);
|
||||||
TemporaryDirectory tempDirOther(TEST_CASE_NAME);
|
TemporaryDirectory tempDirOther(TEST_CASE_NAME);
|
||||||
TemporaryWorkingDirectory tempWorkDir(tempDirCurrent.path());
|
TemporaryWorkingDirectory tempWorkDir(tempDirCurrent);
|
||||||
soltestAssert(tempDirCurrent.path().is_absolute(), "");
|
soltestAssert(tempDirCurrent.path().is_absolute(), "");
|
||||||
soltestAssert(tempDirOther.path().is_absolute(), "");
|
soltestAssert(tempDirOther.path().is_absolute(), "");
|
||||||
|
|
||||||
// NOTE: On macOS the path usually contains symlinks which prevents base path from being stripped.
|
// NOTE: On macOS the path usually contains symlinks which prevents base path from being stripped.
|
||||||
// Use canonical() to resolve symnlinks and get consistent results on all platforms.
|
// Use canonical() to resolve symnlinks and get consistent results on all platforms.
|
||||||
boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent.path());
|
boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent);
|
||||||
boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther.path());
|
boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther);
|
||||||
|
|
||||||
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
|
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
|
||||||
boost::filesystem::path expectedOtherDir = "/" / otherDirNoSymlinks.relative_path();
|
boost::filesystem::path expectedOtherDir = "/" / otherDirNoSymlinks.relative_path();
|
||||||
@ -622,7 +622,7 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_normalization_and_weird_name
|
|||||||
string uncPath = "//" + tempDir.path().relative_path().generic_string();
|
string uncPath = "//" + tempDir.path().relative_path().generic_string();
|
||||||
soltestAssert(FileReader::isUNCPath(uncPath), "");
|
soltestAssert(FileReader::isUNCPath(uncPath), "");
|
||||||
|
|
||||||
boost::filesystem::path tempDirNoSymlinks = boost::filesystem::canonical(tempDir.path());
|
boost::filesystem::path tempDirNoSymlinks = boost::filesystem::canonical(tempDir);
|
||||||
|
|
||||||
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
|
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
|
||||||
soltestAssert(expectedWorkDir.is_absolute() || expectedWorkDir.root_path() == "/", "");
|
soltestAssert(expectedWorkDir.is_absolute() || expectedWorkDir.root_path() == "/", "");
|
||||||
@ -829,7 +829,7 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_symlinks)
|
|||||||
};
|
};
|
||||||
|
|
||||||
FileReader::FileSystemPathSet expectedAllowedDirectories = {
|
FileReader::FileSystemPathSet expectedAllowedDirectories = {
|
||||||
boost::filesystem::canonical(tempDir.path()) / "x/y/z",
|
boost::filesystem::canonical(tempDir) / "x/y/z",
|
||||||
};
|
};
|
||||||
|
|
||||||
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles(commandLine);
|
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles(commandLine);
|
||||||
@ -846,7 +846,7 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_symlinks)
|
|||||||
BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_base_path_and_stdin)
|
BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_base_path_and_stdin)
|
||||||
{
|
{
|
||||||
TemporaryDirectory tempDir(TEST_CASE_NAME);
|
TemporaryDirectory tempDir(TEST_CASE_NAME);
|
||||||
TemporaryWorkingDirectory tempWorkDir(tempDir.path());
|
TemporaryWorkingDirectory tempWorkDir(tempDir);
|
||||||
boost::filesystem::create_directories(tempDir.path() / "base");
|
boost::filesystem::create_directories(tempDir.path() / "base");
|
||||||
|
|
||||||
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
|
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
|
||||||
|
Loading…
Reference in New Issue
Block a user