From 1ddfc7463a94096eedc8012eccd6c144ac2cf577 Mon Sep 17 00:00:00 2001 From: Bhargava Shastry Date: Wed, 3 Feb 2021 15:54:45 +0100 Subject: [PATCH] Tests: Do not remove filename from boost filesystem path for corner cases. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kamil ƚliwak --- libsolutil/CommonIO.cpp | 6 +++++- scripts/ASTImportTest.sh | 5 ++++- .../syntaxTests/imports/boost_filesystem_bug.sol | 4 ++++ test/stopAfterParseTests.sh | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 test/libsolidity/syntaxTests/imports/boost_filesystem_bug.sol diff --git a/libsolutil/CommonIO.cpp b/libsolutil/CommonIO.cpp index 3cf83a826..c933c552e 100644 --- a/libsolutil/CommonIO.cpp +++ b/libsolutil/CommonIO.cpp @@ -137,7 +137,11 @@ string solidity::util::absolutePath(string const& _path, string const& _referenc if (p.begin() == p.end() || (*p.begin() != "." && *p.begin() != "..")) return _path; boost::filesystem::path result(_reference); - result.remove_filename(); + + // If filename is "/", then remove_filename() throws. + // See: https://github.com/boostorg/filesystem/issues/176 + if (result.filename() != boost::filesystem::path("/")) + result.remove_filename(); for (boost::filesystem::path::iterator it = p.begin(); it != p.end(); ++it) if (*it == "..") result = result.parent_path(); diff --git a/scripts/ASTImportTest.sh b/scripts/ASTImportTest.sh index 2850ff0b2..e69aa65b3 100755 --- a/scripts/ASTImportTest.sh +++ b/scripts/ASTImportTest.sh @@ -84,7 +84,10 @@ echo "Looking at $NSOURCES .sol files..." WORKINGDIR=$PWD # for solfile in $(find $DEV_DIR -name *.sol) -for solfile in $(find "$SYNTAXTESTS_DIR" "$ASTJSONTESTS_DIR" -name *.sol) +# boost_filesystem_bug specifically tests a local fix for a boost::filesystem +# bug. Since the test involves a malformed path, there is no point in running +# AST tests on it. See https://github.com/boostorg/filesystem/issues/176 +for solfile in $(find "$SYNTAXTESTS_DIR" "$ASTJSONTESTS_DIR" -name *.sol -and -not -name "boost_filesystem_bug.sol") do echo -n "." # create a temporary sub-directory diff --git a/test/libsolidity/syntaxTests/imports/boost_filesystem_bug.sol b/test/libsolidity/syntaxTests/imports/boost_filesystem_bug.sol new file mode 100644 index 000000000..622b03062 --- /dev/null +++ b/test/libsolidity/syntaxTests/imports/boost_filesystem_bug.sol @@ -0,0 +1,4 @@ +==== Source://// ==== +// This test used to throw due to a bug in boost::filesystem. +// See https://github.com/boostorg/filesystem/issues/176 +import "."; diff --git a/test/stopAfterParseTests.sh b/test/stopAfterParseTests.sh index 8320aeb75..8df15e842 100755 --- a/test/stopAfterParseTests.sh +++ b/test/stopAfterParseTests.sh @@ -70,5 +70,5 @@ while read -r file; do echo "$file" exit 1 fi -done < <(find "${REPO_ROOT}/test" -iname "*.sol" -and -not -name "documentation.sol") +done < <(find "${REPO_ROOT}/test" -iname "*.sol" -and -not -name "documentation.sol" -and -not -name "boost_filesystem_bug.sol") echo