diff --git a/test/TemporaryDirectory.h b/test/TemporaryDirectory.h index ac0a6810a..823251d8d 100644 --- a/test/TemporaryDirectory.h +++ b/test/TemporaryDirectory.h @@ -44,6 +44,7 @@ public: ~TemporaryDirectory(); boost::filesystem::path const& path() const { return m_path; } + operator boost::filesystem::path() const { return m_path; } private: boost::filesystem::path m_path; @@ -59,6 +60,7 @@ public: ~TemporaryWorkingDirectory(); boost::filesystem::path const& originalWorkingDirectory() const { return m_originalWorkingDirectory; } + operator boost::filesystem::path() const { return boost::filesystem::current_path(); } private: boost::filesystem::path m_originalWorkingDirectory; diff --git a/test/libsolidity/interface/FileReader.cpp b/test/libsolidity/interface/FileReader.cpp index be0cd32f9..1c6af8a5a 100644 --- a/test/libsolidity/interface/FileReader.cpp +++ b/test/libsolidity/interface/FileReader.cpp @@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_redundant_slashes) BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_unc_path) { 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. 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) { TemporaryDirectory tempDir(TEST_CASE_NAME); - TemporaryWorkingDirectory tempWorkDir(tempDir.path()); + TemporaryWorkingDirectory tempWorkDir(tempDir); boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_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) { TemporaryDirectory tempDir(TEST_CASE_NAME); - TemporaryWorkingDirectory tempWorkDir(tempDir.path()); + TemporaryWorkingDirectory tempWorkDir(tempDir); soltestAssert(boost::filesystem::current_path().is_absolute(), ""); #if defined(_WIN32) @@ -234,7 +234,7 @@ BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_path_beyond_root) BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_case_sensitivity) { TemporaryDirectory tempDir(TEST_CASE_NAME); - TemporaryWorkingDirectory tempWorkDir(tempDir.path()); + TemporaryWorkingDirectory tempWorkDir(tempDir); boost::filesystem::path expectedPrefix = "/" / tempDir.path().relative_path(); soltestAssert(expectedPrefix.is_absolute() || expectedPrefix.root_path() == "/", ""); diff --git a/test/libsolutil/CommonIO.cpp b/test/libsolutil/CommonIO.cpp index a0edb76b4..12b99df7b 100644 --- a/test/libsolutil/CommonIO.cpp +++ b/test/libsolutil/CommonIO.cpp @@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE(readFileAsString_regular_file) BOOST_AUTO_TEST_CASE(readFileAsString_directory) { TemporaryDirectory tempDir(TEST_CASE_NAME); - BOOST_CHECK_THROW(readFileAsString(tempDir.path()), NotAFile); + BOOST_CHECK_THROW(readFileAsString(tempDir), NotAFile); } BOOST_AUTO_TEST_CASE(readFileAsString_symlink) diff --git a/test/solc/CommandLineInterface.cpp b/test/solc/CommandLineInterface.cpp index 5ede475ab..321b33475 100644 --- a/test/solc/CommandLineInterface.cpp +++ b/test/solc/CommandLineInterface.cpp @@ -156,8 +156,8 @@ BOOST_AUTO_TEST_CASE(cli_input) {(expectedDir2 / "input2.sol").generic_string(), ""}, }; PathSet expectedAllowedPaths = { - boost::filesystem::canonical(tempDir1.path()), - boost::filesystem::canonical(tempDir2.path()), + boost::filesystem::canonical(tempDir1), + boost::filesystem::canonical(tempDir2), "b/c", "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. map expectedSources = {{(expectedDir1 / "input1.sol").generic_string(), ""}}; - PathSet expectedAllowedPaths = {boost::filesystem::canonical(tempDir1.path())}; + PathSet expectedAllowedPaths = {boost::filesystem::canonical(tempDir1)}; OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles({ "solc", @@ -354,14 +354,14 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_no_base_path) { TemporaryDirectory tempDirCurrent(TEST_CASE_NAME); TemporaryDirectory tempDirOther(TEST_CASE_NAME); - TemporaryWorkingDirectory tempWorkDir(tempDirCurrent.path()); + TemporaryWorkingDirectory tempWorkDir(tempDirCurrent); soltestAssert(tempDirCurrent.path().is_absolute(), ""); soltestAssert(tempDirOther.path().is_absolute(), ""); // 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. - boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent.path()); - boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther.path()); + boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent); + boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther); boost::filesystem::path expectedOtherDir = "/" / otherDirNoSymlinks.relative_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 tempDirOther(TEST_CASE_NAME); - TemporaryWorkingDirectory tempWorkDir(tempDirCurrent.path()); + TemporaryWorkingDirectory tempWorkDir(tempDirCurrent); soltestAssert(tempDirCurrent.path().is_absolute(), ""); soltestAssert(tempDirOther.path().is_absolute(), ""); // 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. - boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent.path()); - boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther.path()); + boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent); + boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther); boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().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 tempDirOther(TEST_CASE_NAME); TemporaryDirectory tempDirBase(TEST_CASE_NAME); - TemporaryWorkingDirectory tempWorkDir(tempDirCurrent.path()); + TemporaryWorkingDirectory tempWorkDir(tempDirCurrent); soltestAssert(tempDirCurrent.path().is_absolute(), ""); soltestAssert(tempDirOther.path().is_absolute(), ""); soltestAssert(tempDirBase.path().is_absolute(), ""); // 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. - boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent.path()); - boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther.path()); - boost::filesystem::path baseDirNoSymlinks = boost::filesystem::canonical(tempDirBase.path()); + boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent); + boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther); + boost::filesystem::path baseDirNoSymlinks = boost::filesystem::canonical(tempDirBase); boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().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 tempDirOther(TEST_CASE_NAME); - TemporaryWorkingDirectory tempWorkDir(tempDirCurrent.path()); + TemporaryWorkingDirectory tempWorkDir(tempDirCurrent); soltestAssert(tempDirCurrent.path().is_absolute(), ""); soltestAssert(tempDirOther.path().is_absolute(), ""); // 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. - boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent.path()); - boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther.path()); + boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent); + boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther); boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().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(); 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(); 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 = { - boost::filesystem::canonical(tempDir.path()) / "x/y/z", + boost::filesystem::canonical(tempDir) / "x/y/z", }; 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) { TemporaryDirectory tempDir(TEST_CASE_NAME); - TemporaryWorkingDirectory tempWorkDir(tempDir.path()); + TemporaryWorkingDirectory tempWorkDir(tempDir); boost::filesystem::create_directories(tempDir.path() / "base"); boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();