mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
FileReader: Normalize base path and strip it from normalized source paths
This commit is contained in:
@@ -103,6 +103,7 @@ set(libsolidity_sources
|
||||
libsolidity/SyntaxTest.h
|
||||
libsolidity/ViewPureChecker.cpp
|
||||
libsolidity/analysis/FunctionCallGraph.cpp
|
||||
libsolidity/interface/FileReader.cpp
|
||||
)
|
||||
detect_stray_source_files("${libsolidity_sources}" "libsolidity/")
|
||||
|
||||
|
||||
@@ -0,0 +1,450 @@
|
||||
/*
|
||||
This file is part of solidity.
|
||||
|
||||
solidity is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
solidity is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
|
||||
/// Unit tests for libsolidity/interface/FileReader.h
|
||||
|
||||
#include <libsolidity/interface/FileReader.h>
|
||||
|
||||
#include <test/Common.h>
|
||||
#include <test/FilesystemUtils.h>
|
||||
#include <test/TemporaryDirectory.h>
|
||||
#include <test/libsolidity/util/SoltestErrors.h>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace solidity::test;
|
||||
|
||||
#define TEST_CASE_NAME (boost::unit_test::framework::current_test_case().p_name)
|
||||
|
||||
namespace solidity::frontend::test
|
||||
{
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(FileReaderTest)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_absolute_path)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/"), "/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/."), "/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/./"), "/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/./."), "/");
|
||||
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/a"), "/a");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/a/"), "/a/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/a/."), "/a/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/./a"), "/a");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/./a/"), "/a/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/./a/."), "/a/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/a/b"), "/a/b");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/a/b/"), "/a/b/");
|
||||
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/a/./b/"), "/a/b/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/a/../a/b/"), "/a/b/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/a/b/c/.."), "/a/b");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/a/b/c/../"), "/a/b/");
|
||||
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/a/b/c/../../.."), "/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/a/b/c/../../../"), "/");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_relative_path)
|
||||
{
|
||||
TemporaryDirectory tempDir(TEST_CASE_NAME);
|
||||
boost::filesystem::create_directories(tempDir.path() / "x/y/z");
|
||||
TemporaryWorkingDirectory tempWorkDir(tempDir.path() / "x/y/z");
|
||||
|
||||
// NOTE: If path to work dir contains symlinks (often the case on macOS), boost might resolve
|
||||
// them, making the path different from tempDirPath.
|
||||
boost::filesystem::path expectedPrefix = boost::filesystem::current_path().parent_path().parent_path().parent_path();
|
||||
// On Windows tempDir.path() normally contains the drive letter while the normalized path should not.
|
||||
expectedPrefix = "/" / expectedPrefix.relative_path();
|
||||
soltestAssert(expectedPrefix.is_absolute() || expectedPrefix.root_path() == "/", "");
|
||||
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("."), expectedPrefix / "x/y/z/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("./"), expectedPrefix / "x/y/z/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS(".//"), expectedPrefix / "x/y/z/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS(".."), expectedPrefix / "x/y");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("../"), expectedPrefix / "x/y/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("..//"), expectedPrefix / "x/y/");
|
||||
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("a"), expectedPrefix / "x/y/z/a");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("a/"), expectedPrefix / "x/y/z/a/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("a/."), expectedPrefix / "x/y/z/a/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("./a"), expectedPrefix / "x/y/z/a");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("./a/"), expectedPrefix / "x/y/z/a/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("./a/."), expectedPrefix / "x/y/z/a/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("./a/./"), expectedPrefix / "x/y/z/a/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("./a/.//"), expectedPrefix / "x/y/z/a/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("./a/./."), expectedPrefix / "x/y/z/a/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("./a/././"), expectedPrefix / "x/y/z/a/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("./a/././/"), expectedPrefix / "x/y/z/a/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("a/b"), expectedPrefix / "x/y/z/a/b");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("a/b/"), expectedPrefix / "x/y/z/a/b/");
|
||||
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("../a/b"), expectedPrefix / "x/y/a/b");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("../../a/b"), expectedPrefix / "x/a/b");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("./a/b"), expectedPrefix / "x/y/z/a/b");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("././a/b"), expectedPrefix / "x/y/z/a/b");
|
||||
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("a/./b/"), expectedPrefix / "x/y/z/a/b/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("a/../a/b/"), expectedPrefix / "x/y/z/a/b/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("a/b/c/.."), expectedPrefix / "x/y/z/a/b");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("a/b/c/../"), expectedPrefix / "x/y/z/a/b/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("a/b/c/..//"), expectedPrefix / "x/y/z/a/b/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("a/b/c/../.."), expectedPrefix / "x/y/z/a");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("a/b/c/../../"), expectedPrefix / "x/y/z/a/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("a/b/c/../..//"), expectedPrefix / "x/y/z/a/");
|
||||
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("../../a/.././../p/../q/../a/b"), expectedPrefix / "a/b");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_redundant_slashes)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("///"), "/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("////"), "/");
|
||||
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("////a/b/"), "/a/b/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/a//b/"), "/a/b/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/a////b/"), "/a/b/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/a/b//"), "/a/b/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/a/b////"), "/a/b/");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_unc_path)
|
||||
{
|
||||
TemporaryDirectory tempDir(TEST_CASE_NAME);
|
||||
TemporaryWorkingDirectory tempWorkDir(tempDir.path());
|
||||
|
||||
// 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();
|
||||
soltestAssert(expectedWorkDir.is_absolute() || expectedWorkDir.root_path() == "/", "");
|
||||
|
||||
// UNC paths start with // or \\ followed by a name. They are used for network shares on Windows.
|
||||
// On UNIX systems they are not supported but still treated in a special way.
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("//host/"), "//host/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("//host/a/b"), "//host/a/b");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("//host/a/b/"), "//host/a/b/");
|
||||
|
||||
#if defined(_WIN32)
|
||||
// On Windows an UNC path can also start with \\ instead of //
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("\\\\host/"), "//host/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("\\\\host/a/b"), "//host/a/b");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("\\\\host/a/b/"), "//host/a/b/");
|
||||
#else
|
||||
// On UNIX systems it's just a fancy relative path instead
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("\\\\host/"), expectedWorkDir / "\\\\host/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("\\\\host/a/b"), expectedWorkDir / "\\\\host/a/b");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("\\\\host/a/b/"), expectedWorkDir / "\\\\host/a/b/");
|
||||
#endif
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_root_name_only)
|
||||
{
|
||||
TemporaryDirectory tempDir(TEST_CASE_NAME);
|
||||
TemporaryWorkingDirectory tempWorkDir(tempDir.path());
|
||||
|
||||
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
|
||||
soltestAssert(expectedWorkDir.is_absolute() || expectedWorkDir.root_path() == "/", "");
|
||||
|
||||
// A root **path** consists of a directory name (typically / or \) and the root name (drive
|
||||
// letter (C:), UNC host name (//host), etc.). Either can be empty. Root path as a whole may be
|
||||
// an absolute path but root name on its own is considered relative. For example on Windows
|
||||
// C:\ represents the root directory of drive C: but C: on its own refers to the current working
|
||||
// directory.
|
||||
|
||||
// UNC paths
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("//"), "//" / expectedWorkDir);
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("//host"), "//host" / expectedWorkDir);
|
||||
|
||||
// On UNIX systems root name is empty.
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS(""), expectedWorkDir);
|
||||
|
||||
#if defined(_WIN32)
|
||||
boost::filesystem::path driveLetter = boost::filesystem::current_path().root_name();
|
||||
solAssert(!driveLetter.empty(), "");
|
||||
solAssert(driveLetter.is_relative(), "");
|
||||
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS(driveLetter), expectedWorkDir);
|
||||
#endif
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_stripping_root_name)
|
||||
{
|
||||
TemporaryDirectory tempDir(TEST_CASE_NAME);
|
||||
TemporaryWorkingDirectory tempWorkDir(tempDir.path());
|
||||
|
||||
soltestAssert(boost::filesystem::current_path().is_absolute(), "");
|
||||
#if defined(_WIN32)
|
||||
soltestAssert(!boost::filesystem::current_path().root_name().empty(), "");
|
||||
#endif
|
||||
|
||||
boost::filesystem::path normalizedPath = FileReader::normalizeCLIPathForVFS(boost::filesystem::current_path());
|
||||
BOOST_CHECK_EQUAL(normalizedPath, "/" / boost::filesystem::current_path().relative_path());
|
||||
BOOST_TEST(normalizedPath.root_name().empty());
|
||||
BOOST_CHECK_EQUAL(normalizedPath.root_directory(), "/");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_path_beyond_root)
|
||||
{
|
||||
TemporaryWorkingDirectory tempWorkDir("/");
|
||||
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/.."), "/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/../"), "/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/../."), "/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/../.."), "/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/../a"), "/a");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/../a/.."), "/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/../a/../.."), "/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/../../a"), "/a");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/../../a/.."), "/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/../../a/../.."), "/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/a/../.."), "/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("/a/../../b/../.."), "/");
|
||||
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS(".."), "/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("../"), "/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("../."), "/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("../.."), "/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("../a"), "/a");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("../a/.."), "/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("../a/../.."), "/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("../../a"), "/a");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("../../a/.."), "/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("../../a/../.."), "/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("a/../.."), "/");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("a/../../b/../.."), "/");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_case_sensitivity)
|
||||
{
|
||||
TemporaryDirectory tempDir(TEST_CASE_NAME);
|
||||
TemporaryWorkingDirectory tempWorkDir(tempDir.path());
|
||||
|
||||
boost::filesystem::path expectedPrefix = "/" / tempDir.path().relative_path();
|
||||
soltestAssert(expectedPrefix.is_absolute() || expectedPrefix.root_path() == "/", "");
|
||||
|
||||
BOOST_TEST(FileReader::normalizeCLIPathForVFS(tempDir.path() / "abc") == expectedPrefix / "abc");
|
||||
BOOST_TEST(FileReader::normalizeCLIPathForVFS(tempDir.path() / "abc") != expectedPrefix / "ABC");
|
||||
BOOST_TEST(FileReader::normalizeCLIPathForVFS(tempDir.path() / "ABC") != expectedPrefix / "abc");
|
||||
BOOST_TEST(FileReader::normalizeCLIPathForVFS(tempDir.path() / "ABC") == expectedPrefix / "ABC");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_path_separators)
|
||||
{
|
||||
// Even on Windows we want / as a separator.
|
||||
BOOST_TEST((FileReader::normalizeCLIPathForVFS("/a/b/c").native() == boost::filesystem::path("/a/b/c").native()));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_should_not_resolve_symlinks)
|
||||
{
|
||||
TemporaryDirectory tempDir(TEST_CASE_NAME);
|
||||
soltestAssert(tempDir.path().is_absolute(), "");
|
||||
boost::filesystem::create_directories(tempDir.path() / "abc");
|
||||
|
||||
if (!createSymlinkIfSupportedByFilesystem(tempDir.path() / "abc", tempDir.path() / "sym", true))
|
||||
return;
|
||||
|
||||
boost::filesystem::path expectedPrefix = "/" / tempDir.path().relative_path();
|
||||
soltestAssert(expectedPrefix.is_absolute() || expectedPrefix.root_path() == "/", "");
|
||||
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS(tempDir.path() / "sym/contract.sol"), expectedPrefix / "sym/contract.sol");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS(tempDir.path() / "abc/contract.sol"), expectedPrefix / "abc/contract.sol");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_should_resolve_symlinks_in_workdir_when_path_is_relative)
|
||||
{
|
||||
TemporaryDirectory tempDir(TEST_CASE_NAME);
|
||||
soltestAssert(tempDir.path().is_absolute(), "");
|
||||
boost::filesystem::create_directories(tempDir.path() / "abc");
|
||||
|
||||
if (!createSymlinkIfSupportedByFilesystem(tempDir.path() / "abc", tempDir.path() / "sym", true))
|
||||
return;
|
||||
|
||||
TemporaryWorkingDirectory tempWorkDir(tempDir.path() / "sym");
|
||||
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::weakly_canonical(boost::filesystem::current_path()).relative_path();
|
||||
soltestAssert(expectedWorkDir.is_absolute() || expectedWorkDir.root_path() == "/", "");
|
||||
|
||||
boost::filesystem::path expectedPrefix = "/" / tempDir.path().relative_path();
|
||||
soltestAssert(expectedPrefix.is_absolute() || expectedPrefix.root_path() == "/", "");
|
||||
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS("contract.sol"), expectedWorkDir / "contract.sol");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS(tempDir.path() / "sym/contract.sol"), expectedPrefix / "sym/contract.sol");
|
||||
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS(tempDir.path() / "abc/contract.sol"), expectedPrefix / "abc/contract.sol");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(isPathPrefix_file_prefix)
|
||||
{
|
||||
BOOST_TEST(FileReader::isPathPrefix("/", "/contract.sol"));
|
||||
BOOST_TEST(FileReader::isPathPrefix("/contract.sol", "/contract.sol"));
|
||||
BOOST_TEST(FileReader::isPathPrefix("/contract.sol/", "/contract.sol"));
|
||||
BOOST_TEST(FileReader::isPathPrefix("/contract.sol/.", "/contract.sol"));
|
||||
|
||||
BOOST_TEST(FileReader::isPathPrefix("/", "/a/bc/def/contract.sol"));
|
||||
BOOST_TEST(FileReader::isPathPrefix("/a", "/a/bc/def/contract.sol"));
|
||||
BOOST_TEST(FileReader::isPathPrefix("/a/", "/a/bc/def/contract.sol"));
|
||||
BOOST_TEST(FileReader::isPathPrefix("/a/bc", "/a/bc/def/contract.sol"));
|
||||
BOOST_TEST(FileReader::isPathPrefix("/a/bc/def/contract.sol", "/a/bc/def/contract.sol"));
|
||||
|
||||
BOOST_TEST(FileReader::isPathPrefix("/", "/a/bc/def/contract.sol"));
|
||||
BOOST_TEST(FileReader::isPathPrefix("/a", "/a/bc/def/contract.sol"));
|
||||
BOOST_TEST(FileReader::isPathPrefix("/a/", "/a/bc/def/contract.sol"));
|
||||
BOOST_TEST(FileReader::isPathPrefix("/a/bc", "/a/bc/def/contract.sol"));
|
||||
BOOST_TEST(FileReader::isPathPrefix("/a/bc/def/contract.sol", "/a/bc/def/contract.sol"));
|
||||
|
||||
BOOST_TEST(!FileReader::isPathPrefix("/contract.sol", "/token.sol"));
|
||||
BOOST_TEST(!FileReader::isPathPrefix("/contract", "/contract.sol"));
|
||||
BOOST_TEST(!FileReader::isPathPrefix("/contract.sol", "/contract"));
|
||||
BOOST_TEST(!FileReader::isPathPrefix("/contract.so", "/contract.sol"));
|
||||
BOOST_TEST(!FileReader::isPathPrefix("/contract.sol", "/contract.so"));
|
||||
|
||||
BOOST_TEST(!FileReader::isPathPrefix("/a/b/c/contract.sol", "/a/b/contract.sol"));
|
||||
BOOST_TEST(!FileReader::isPathPrefix("/a/b/contract.sol", "/a/b/c/contract.sol"));
|
||||
BOOST_TEST(!FileReader::isPathPrefix("/a/b/c/contract.sol", "/a/b/c/d/contract.sol"));
|
||||
BOOST_TEST(!FileReader::isPathPrefix("/a/b/c/d/contract.sol", "/a/b/c/contract.sol"));
|
||||
BOOST_TEST(!FileReader::isPathPrefix("/a/b/c/contract.sol", "/contract.sol"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(isPathPrefix_directory_prefix)
|
||||
{
|
||||
BOOST_TEST(FileReader::isPathPrefix("/", "/"));
|
||||
BOOST_TEST(!FileReader::isPathPrefix("/a/b/c/", "/"));
|
||||
BOOST_TEST(!FileReader::isPathPrefix("/a/b/c", "/"));
|
||||
|
||||
BOOST_TEST(FileReader::isPathPrefix("/", "/a/bc/"));
|
||||
BOOST_TEST(FileReader::isPathPrefix("/a", "/a/bc/"));
|
||||
BOOST_TEST(FileReader::isPathPrefix("/a/", "/a/bc/"));
|
||||
BOOST_TEST(FileReader::isPathPrefix("/a/bc", "/a/bc/"));
|
||||
BOOST_TEST(FileReader::isPathPrefix("/a/bc/", "/a/bc/"));
|
||||
|
||||
BOOST_TEST(!FileReader::isPathPrefix("/a", "/b/"));
|
||||
BOOST_TEST(!FileReader::isPathPrefix("/a/", "/b/"));
|
||||
BOOST_TEST(!FileReader::isPathPrefix("/a/contract.sol", "/a/b/"));
|
||||
|
||||
BOOST_TEST(!FileReader::isPathPrefix("/a/b/c/", "/a/b/"));
|
||||
BOOST_TEST(!FileReader::isPathPrefix("/a/b/c", "/a/b/"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(isPathPrefix_unc_path)
|
||||
{
|
||||
BOOST_TEST(FileReader::isPathPrefix("//host/a/b/", "//host/a/b/"));
|
||||
BOOST_TEST(FileReader::isPathPrefix("//host/a/b", "//host/a/b/"));
|
||||
BOOST_TEST(FileReader::isPathPrefix("//host/a/", "//host/a/b/"));
|
||||
BOOST_TEST(FileReader::isPathPrefix("//host/a", "//host/a/b/"));
|
||||
BOOST_TEST(FileReader::isPathPrefix("//host/", "//host/a/b/"));
|
||||
|
||||
// NOTE: //host and // cannot be passed to isPathPrefix() because they are considered relative.
|
||||
|
||||
BOOST_TEST(!FileReader::isPathPrefix("//host1/", "//host2/"));
|
||||
BOOST_TEST(!FileReader::isPathPrefix("//host1/a/b/", "//host2/a/b/"));
|
||||
|
||||
BOOST_TEST(!FileReader::isPathPrefix("/a/b/c/", "//a/b/c/"));
|
||||
BOOST_TEST(!FileReader::isPathPrefix("//a/b/c/", "/a/b/c/"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(isPathPrefix_case_sensitivity)
|
||||
{
|
||||
BOOST_TEST(!FileReader::isPathPrefix("/a.sol", "/A.sol"));
|
||||
BOOST_TEST(!FileReader::isPathPrefix("/A.sol", "/a.sol"));
|
||||
BOOST_TEST(!FileReader::isPathPrefix("/A/", "/a/"));
|
||||
BOOST_TEST(!FileReader::isPathPrefix("/a/", "/A/"));
|
||||
BOOST_TEST(!FileReader::isPathPrefix("/a/BC/def/", "/a/bc/def/contract.sol"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(stripPrefixIfPresent_file_prefix)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/", "/contract.sol"), "contract.sol");
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/contract.sol", "/contract.sol"), ".");
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/contract.sol/", "/contract.sol"), ".");
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/contract.sol/.", "/contract.sol"), ".");
|
||||
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/", "/a/bc/def/contract.sol"), "a/bc/def/contract.sol");
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/a", "/a/bc/def/contract.sol"), "bc/def/contract.sol");
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/a/", "/a/bc/def/contract.sol"), "bc/def/contract.sol");
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/a/bc", "/a/bc/def/contract.sol"), "def/contract.sol");
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/a/bc/def/", "/a/bc/def/contract.sol"), "contract.sol");
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/a/bc/def/contract.sol", "/a/bc/def/contract.sol"), ".");
|
||||
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/contract.sol", "/token.sol"), "/token.sol");
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/contract", "/contract.sol"), "/contract.sol");
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/contract.sol", "/contract"), "/contract");
|
||||
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/a/b/c/contract.sol", "/a/b/contract.sol"), "/a/b/contract.sol");
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/a/b/contract.sol", "/a/b/c/contract.sol"), "/a/b/c/contract.sol");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(stripPrefixIfPresent_directory_prefix)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/", "/"), ".");
|
||||
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/", "/a/bc/def/"), "a/bc/def/");
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/a", "/a/bc/def/"), "bc/def/");
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/a/", "/a/bc/def/"), "bc/def/");
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/a/bc", "/a/bc/def/"), "def/");
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/a/bc/def/", "/a/bc/def/"), ".");
|
||||
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/a", "/b/"), "/b/");
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/a/", "/b/"), "/b/");
|
||||
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/a/b/c/", "/a/b/"), "/a/b/");
|
||||
BOOST_CHECK_EQUAL(FileReader::stripPrefixIfPresent("/a/b/c", "/a/b/"), "/a/b/");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(isUNCPath)
|
||||
{
|
||||
BOOST_TEST(FileReader::isUNCPath("//"));
|
||||
BOOST_TEST(FileReader::isUNCPath("//root"));
|
||||
BOOST_TEST(FileReader::isUNCPath("//root/"));
|
||||
|
||||
#if defined(_WIN32)
|
||||
// On Windows boost sees these as ///, which is equivalent to /
|
||||
BOOST_TEST(!FileReader::isUNCPath("//\\"));
|
||||
BOOST_TEST(!FileReader::isUNCPath("\\\\/"));
|
||||
BOOST_TEST(!FileReader::isUNCPath("\\/\\"));
|
||||
|
||||
BOOST_TEST(FileReader::isUNCPath("\\\\"));
|
||||
BOOST_TEST(FileReader::isUNCPath("\\\\root"));
|
||||
BOOST_TEST(FileReader::isUNCPath("\\\\root/"));
|
||||
#else
|
||||
// On UNIX it's actually an UNC path
|
||||
BOOST_TEST(FileReader::isUNCPath("//\\"));
|
||||
|
||||
// On UNIX these are just weird relative directory names consisting only of backslashes.
|
||||
BOOST_TEST(!FileReader::isUNCPath("\\\\/"));
|
||||
BOOST_TEST(!FileReader::isUNCPath("\\/\\"));
|
||||
|
||||
BOOST_TEST(!FileReader::isUNCPath("\\\\"));
|
||||
BOOST_TEST(!FileReader::isUNCPath("\\\\root"));
|
||||
BOOST_TEST(!FileReader::isUNCPath("\\\\root/"));
|
||||
#endif
|
||||
|
||||
BOOST_TEST(!FileReader::isUNCPath("\\/"));
|
||||
BOOST_TEST(!FileReader::isUNCPath("/\\"));
|
||||
|
||||
BOOST_TEST(!FileReader::isUNCPath(""));
|
||||
BOOST_TEST(!FileReader::isUNCPath("."));
|
||||
BOOST_TEST(!FileReader::isUNCPath(".."));
|
||||
BOOST_TEST(!FileReader::isUNCPath("/"));
|
||||
BOOST_TEST(!FileReader::isUNCPath("a"));
|
||||
BOOST_TEST(!FileReader::isUNCPath("a/b/c"));
|
||||
BOOST_TEST(!FileReader::isUNCPath("contract.sol"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
} // namespace solidity::frontend::test
|
||||
@@ -141,14 +141,19 @@ BOOST_AUTO_TEST_CASE(cli_input)
|
||||
createFilesWithParentDirs({tempDir1.path() / "input1.sol"});
|
||||
createFilesWithParentDirs({tempDir2.path() / "input2.sol"});
|
||||
|
||||
boost::filesystem::path expectedDir1 = "/" / tempDir1.path().relative_path();
|
||||
boost::filesystem::path expectedDir2 = "/" / tempDir2.path().relative_path();
|
||||
soltestAssert(expectedDir1.is_absolute() || expectedDir1.root_path() == "/", "");
|
||||
soltestAssert(expectedDir2.is_absolute() || expectedDir2.root_path() == "/", "");
|
||||
|
||||
vector<ImportRemapper::Remapping> expectedRemappings = {
|
||||
{"", "a", "b/c/d"},
|
||||
{"a", "b", "c/d/e/"},
|
||||
};
|
||||
map<string, string> expectedSources = {
|
||||
{"<stdin>", "\n"},
|
||||
{(tempDir1.path() / "input1.sol").generic_string(), ""},
|
||||
{(tempDir2.path() / "input2.sol").generic_string(), ""},
|
||||
{(expectedDir1 / "input1.sol").generic_string(), ""},
|
||||
{(expectedDir2 / "input2.sol").generic_string(), ""},
|
||||
};
|
||||
PathSet expectedAllowedPaths = {
|
||||
boost::filesystem::canonical(tempDir1.path()),
|
||||
@@ -181,8 +186,11 @@ BOOST_AUTO_TEST_CASE(cli_ignore_missing_some_files_exist)
|
||||
TemporaryDirectory tempDir2(TEST_CASE_NAME);
|
||||
createFilesWithParentDirs({tempDir1.path() / "input1.sol"});
|
||||
|
||||
boost::filesystem::path expectedDir1 = "/" / tempDir1.path().relative_path();
|
||||
soltestAssert(expectedDir1.is_absolute() || expectedDir1.root_path() == "/", "");
|
||||
|
||||
// NOTE: Allowed paths should not be added for skipped files.
|
||||
map<string, string> expectedSources = {{(tempDir1.path() / "input1.sol").generic_string(), ""}};
|
||||
map<string, string> expectedSources = {{(expectedDir1 / "input1.sol").generic_string(), ""}};
|
||||
PathSet expectedAllowedPaths = {boost::filesystem::canonical(tempDir1.path())};
|
||||
|
||||
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles({
|
||||
@@ -232,6 +240,7 @@ BOOST_AUTO_TEST_CASE(cli_not_a_file)
|
||||
BOOST_AUTO_TEST_CASE(standard_json_base_path)
|
||||
{
|
||||
TemporaryDirectory tempDir(TEST_CASE_NAME);
|
||||
TemporaryWorkingDirectory tempWorkDir(tempDir.path().root_path());
|
||||
|
||||
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles({
|
||||
"solc",
|
||||
@@ -245,7 +254,7 @@ BOOST_AUTO_TEST_CASE(standard_json_base_path)
|
||||
BOOST_TEST(result.options.input.paths.empty());
|
||||
BOOST_TEST(result.reader.sourceCodes().empty());
|
||||
BOOST_TEST(result.reader.allowedDirectories().empty());
|
||||
BOOST_TEST(result.reader.basePath() == tempDir.path());
|
||||
BOOST_TEST(result.reader.basePath() == "/" / tempDir.path().relative_path());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(standard_json_no_input_file)
|
||||
@@ -354,6 +363,9 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_no_base_path)
|
||||
boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent.path());
|
||||
boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther.path());
|
||||
|
||||
boost::filesystem::path expectedOtherDir = "/" / otherDirNoSymlinks.relative_path();
|
||||
soltestAssert(expectedOtherDir.is_absolute() || expectedOtherDir.root_path() == "/", "");
|
||||
|
||||
vector<string> commandLine = {
|
||||
"solc",
|
||||
"contract1.sol", // Relative path
|
||||
@@ -374,8 +386,8 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_no_base_path)
|
||||
map<string, string> expectedSources = {
|
||||
{"contract1.sol", ""},
|
||||
{"c/d/contract2.sol", ""},
|
||||
{currentDirNoSymlinks.generic_string() + "/contract3.sol", ""},
|
||||
{otherDirNoSymlinks.generic_string() + "/contract4.sol", ""},
|
||||
{"contract3.sol", ""},
|
||||
{expectedOtherDir.generic_string() + "/contract4.sol", ""},
|
||||
};
|
||||
|
||||
FileReader::FileSystemPathSet expectedAllowedDirectories = {
|
||||
@@ -409,6 +421,11 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_base_path_same_as_work_dir)
|
||||
boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent.path());
|
||||
boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther.path());
|
||||
|
||||
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
|
||||
boost::filesystem::path expectedOtherDir = "/" / otherDirNoSymlinks.relative_path();
|
||||
soltestAssert(expectedWorkDir.is_absolute() || expectedWorkDir.root_path() == "/", "");
|
||||
soltestAssert(expectedOtherDir.is_absolute() || expectedOtherDir.root_path() == "/", "");
|
||||
|
||||
vector<string> commandLine = {
|
||||
"solc",
|
||||
"--base-path=" + currentDirNoSymlinks.string(),
|
||||
@@ -431,8 +448,8 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_base_path_same_as_work_dir)
|
||||
map<string, string> expectedSources = {
|
||||
{"contract1.sol", ""},
|
||||
{"c/d/contract2.sol", ""},
|
||||
{currentDirNoSymlinks.generic_string() + "/contract3.sol", ""},
|
||||
{otherDirNoSymlinks.generic_string() + "/contract4.sol", ""},
|
||||
{"contract3.sol", ""},
|
||||
{expectedOtherDir.generic_string() + "/contract4.sol", ""},
|
||||
};
|
||||
|
||||
FileReader::FileSystemPathSet expectedAllowedDirectories = {
|
||||
@@ -450,7 +467,7 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_base_path_same_as_work_dir)
|
||||
BOOST_TEST(result.options == expectedOptions);
|
||||
BOOST_TEST(result.reader.sourceCodes() == expectedSources);
|
||||
BOOST_TEST(result.reader.allowedDirectories() == expectedAllowedDirectories);
|
||||
BOOST_TEST(result.reader.basePath() == expectedOptions.input.basePath);
|
||||
BOOST_TEST(result.reader.basePath() == expectedWorkDir);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_base_path_different_from_work_dir)
|
||||
@@ -469,6 +486,15 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_base_path_different_from_wor
|
||||
boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther.path());
|
||||
boost::filesystem::path baseDirNoSymlinks = boost::filesystem::canonical(tempDirBase.path());
|
||||
|
||||
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
|
||||
boost::filesystem::path expectedCurrentDir = "/" / currentDirNoSymlinks.relative_path();
|
||||
boost::filesystem::path expectedOtherDir = "/" / otherDirNoSymlinks.relative_path();
|
||||
boost::filesystem::path expectedBaseDir = "/" / baseDirNoSymlinks.relative_path();
|
||||
soltestAssert(expectedWorkDir.is_absolute() || expectedWorkDir.root_path() == "/", "");
|
||||
soltestAssert(expectedCurrentDir.is_absolute() || expectedCurrentDir.root_path() == "/", "");
|
||||
soltestAssert(expectedOtherDir.is_absolute() || expectedOtherDir.root_path() == "/", "");
|
||||
soltestAssert(expectedBaseDir.is_absolute() || expectedBaseDir.root_path() == "/", "");
|
||||
|
||||
vector<string> commandLine = {
|
||||
"solc",
|
||||
"--base-path=" + baseDirNoSymlinks.string(),
|
||||
@@ -491,11 +517,11 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_base_path_different_from_wor
|
||||
expectedOptions.modelChecker.initialize = true;
|
||||
|
||||
map<string, string> expectedSources = {
|
||||
{"contract1.sol", ""},
|
||||
{"c/d/contract2.sol", ""},
|
||||
{currentDirNoSymlinks.generic_string() + "/contract3.sol", ""},
|
||||
{otherDirNoSymlinks.generic_string() + "/contract4.sol", ""},
|
||||
{baseDirNoSymlinks.generic_string() + "/contract5.sol", ""},
|
||||
{expectedWorkDir.generic_string() + "/contract1.sol", ""},
|
||||
{expectedWorkDir.generic_string() + "/c/d/contract2.sol", ""},
|
||||
{expectedCurrentDir.generic_string() + "/contract3.sol", ""},
|
||||
{expectedOtherDir.generic_string() + "/contract4.sol", ""},
|
||||
{"contract5.sol", ""},
|
||||
};
|
||||
|
||||
FileReader::FileSystemPathSet expectedAllowedDirectories = {
|
||||
@@ -514,7 +540,7 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_base_path_different_from_wor
|
||||
BOOST_TEST(result.options == expectedOptions);
|
||||
BOOST_TEST(result.reader.sourceCodes() == expectedSources);
|
||||
BOOST_TEST(result.reader.allowedDirectories() == expectedAllowedDirectories);
|
||||
BOOST_TEST(result.reader.basePath() == expectedOptions.input.basePath);
|
||||
BOOST_TEST(result.reader.basePath() == expectedBaseDir);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_relative_base_path)
|
||||
@@ -530,6 +556,11 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_relative_base_path)
|
||||
boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent.path());
|
||||
boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther.path());
|
||||
|
||||
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
|
||||
boost::filesystem::path expectedOtherDir = "/" / otherDirNoSymlinks.relative_path();
|
||||
soltestAssert(expectedWorkDir.is_absolute() || expectedWorkDir.root_path() == "/", "");
|
||||
soltestAssert(expectedOtherDir.is_absolute() || expectedOtherDir.root_path() == "/", "");
|
||||
|
||||
vector<string> commandLine = {
|
||||
"solc",
|
||||
"--base-path=base",
|
||||
@@ -554,12 +585,12 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_relative_base_path)
|
||||
expectedOptions.modelChecker.initialize = true;
|
||||
|
||||
map<string, string> expectedSources = {
|
||||
{"contract1.sol", ""},
|
||||
{"base/contract2.sol", ""},
|
||||
{currentDirNoSymlinks.generic_string() + "/contract3.sol", ""},
|
||||
{currentDirNoSymlinks.generic_string() + "/base/contract4.sol", ""},
|
||||
{otherDirNoSymlinks.generic_string() + "/contract5.sol", ""},
|
||||
{otherDirNoSymlinks.generic_string() + "/base/contract6.sol", ""},
|
||||
{expectedWorkDir.generic_string() + "/contract1.sol", ""},
|
||||
{"contract2.sol", ""},
|
||||
{expectedWorkDir.generic_string() + "/contract3.sol", ""},
|
||||
{"contract4.sol", ""},
|
||||
{expectedOtherDir.generic_string() + "/contract5.sol", ""},
|
||||
{expectedOtherDir.generic_string() + "/base/contract6.sol", ""},
|
||||
};
|
||||
|
||||
FileReader::FileSystemPathSet expectedAllowedDirectories = {
|
||||
@@ -578,7 +609,7 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_relative_base_path)
|
||||
BOOST_TEST(result.options == expectedOptions);
|
||||
BOOST_TEST(result.reader.sourceCodes() == expectedSources);
|
||||
BOOST_TEST(result.reader.allowedDirectories() == expectedAllowedDirectories);
|
||||
BOOST_TEST(result.reader.basePath() == expectedOptions.input.basePath);
|
||||
BOOST_TEST(result.reader.basePath() == expectedWorkDir / "base");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_normalization_and_weird_names)
|
||||
@@ -589,11 +620,13 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_normalization_and_weird_name
|
||||
soltestAssert(tempDir.path().is_absolute(), "");
|
||||
|
||||
string uncPath = "//" + tempDir.path().relative_path().generic_string();
|
||||
soltestAssert(uncPath[0] == '/' && uncPath[1] == '/', "");
|
||||
soltestAssert(uncPath[2] != '/', "");
|
||||
soltestAssert(FileReader::isUNCPath(uncPath), "");
|
||||
|
||||
boost::filesystem::path tempDirNoSymlinks = boost::filesystem::canonical(tempDir.path());
|
||||
|
||||
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
|
||||
soltestAssert(expectedWorkDir.is_absolute() || expectedWorkDir.root_path() == "/", "");
|
||||
|
||||
vector<string> commandLine = {
|
||||
"solc",
|
||||
|
||||
@@ -684,30 +717,29 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_normalization_and_weird_name
|
||||
|
||||
map<string, string> expectedSources = {
|
||||
#if !defined(_WIN32)
|
||||
{"file://c/d/contract1.sol", ""},
|
||||
{"file:///c/d/contract2.sol", ""},
|
||||
{"https://example.com/contract3.sol", ""},
|
||||
{"file:/c/d/contract1.sol", ""},
|
||||
{"file:/c/d/contract2.sol", ""},
|
||||
{"https:/example.com/contract3.sol", ""},
|
||||
#endif
|
||||
|
||||
{"a/b//contract4.sol", ""},
|
||||
{"a/b///contract5.sol", ""},
|
||||
{"a/b////contract6.sol", ""},
|
||||
{"a/b/contract4.sol", ""},
|
||||
{"a/b/contract5.sol", ""},
|
||||
{"a/b/contract6.sol", ""},
|
||||
|
||||
{"./a/b/contract7.sol", ""},
|
||||
{"././a/b/contract8.sol", ""},
|
||||
{"a/./b/contract9.sol", ""},
|
||||
{"a/././b/contract10.sol", ""},
|
||||
{"a/b/contract7.sol", ""},
|
||||
{"a/b/contract8.sol", ""},
|
||||
{"a/b/contract9.sol", ""},
|
||||
{"a/b/contract10.sol", ""},
|
||||
|
||||
{"../a/b/contract11.sol", ""},
|
||||
{"../../a/b/contract12.sol", ""},
|
||||
{"a/../b/contract13.sol", ""},
|
||||
{"a/b/../../contract14.sol", ""},
|
||||
{tempDirNoSymlinks.string() + "/x/y/z/a/../b/contract15.sol", ""},
|
||||
{tempDirNoSymlinks.string() + "/x/y/z/a/b/../../contract16.sol", ""},
|
||||
|
||||
{"/../" + tempDir.path().relative_path().generic_string() + "/contract17.sol", ""},
|
||||
{"/../../" + tempDir.path().relative_path().generic_string() + "/contract18.sol", ""},
|
||||
{expectedWorkDir.parent_path().generic_string() + "/a/b/contract11.sol", ""},
|
||||
{expectedWorkDir.parent_path().parent_path().generic_string() + "/a/b/contract12.sol", ""},
|
||||
{"b/contract13.sol", ""},
|
||||
{"contract14.sol", ""},
|
||||
{"b/contract15.sol", ""},
|
||||
{"contract16.sol", ""},
|
||||
|
||||
{"/" + tempDir.path().relative_path().generic_string() + "/contract17.sol", ""},
|
||||
{"/" + tempDir.path().relative_path().generic_string() + "/contract18.sol", ""},
|
||||
|
||||
#if !defined(_WIN32)
|
||||
{"<stdin>", ""},
|
||||
@@ -766,6 +798,8 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_symlinks)
|
||||
)
|
||||
return;
|
||||
|
||||
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
|
||||
soltestAssert(expectedWorkDir.is_absolute() || expectedWorkDir.root_path() == "/", "");
|
||||
|
||||
vector<string> commandLine = {
|
||||
"solc",
|
||||
@@ -788,10 +822,10 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_symlinks)
|
||||
expectedOptions.modelChecker.initialize = true;
|
||||
|
||||
map<string, string> expectedSources = {
|
||||
{"sym/z/contract.sol", ""},
|
||||
{"../x/y/z/contract.sol", ""},
|
||||
{"sym/z/contract_symlink.sol", ""},
|
||||
{"../x/y/z/contract_symlink.sol", ""},
|
||||
{"contract.sol", ""},
|
||||
{(expectedWorkDir.parent_path() / "x/y/z/contract.sol").generic_string(), ""},
|
||||
{"contract_symlink.sol", ""},
|
||||
{(expectedWorkDir.parent_path() / "x/y/z/contract_symlink.sol").generic_string(), ""},
|
||||
};
|
||||
|
||||
FileReader::FileSystemPathSet expectedAllowedDirectories = {
|
||||
@@ -806,7 +840,7 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_symlinks)
|
||||
BOOST_TEST(result.options == expectedOptions);
|
||||
BOOST_TEST(result.reader.sourceCodes() == expectedSources);
|
||||
BOOST_TEST(result.reader.allowedDirectories() == expectedAllowedDirectories);
|
||||
BOOST_TEST(result.reader.basePath() == expectedOptions.input.basePath);
|
||||
BOOST_TEST(result.reader.basePath() == expectedWorkDir / "sym/z/");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_base_path_and_stdin)
|
||||
@@ -838,7 +872,7 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_base_path_and_stdin)
|
||||
BOOST_TEST(result.options == expectedOptions);
|
||||
BOOST_TEST(result.reader.sourceCodes() == expectedSources);
|
||||
BOOST_TEST(result.reader.allowedDirectories() == expectedAllowedDirectories);
|
||||
BOOST_TEST(result.reader.basePath() == "base");
|
||||
BOOST_TEST(result.reader.basePath() == expectedWorkDir / "base");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
Reference in New Issue
Block a user