Merge pull request #4941 from liangdzou/properly_truncate_referenced_src

Properly truncate referenced src
This commit is contained in:
chriseth 2018-09-13 09:43:47 +02:00 committed by GitHub
commit 15c8c0d2cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 90 additions and 4 deletions

View File

@ -55,8 +55,14 @@ void SourceReferenceFormatter::printSourceLocation(SourceLocation const* _locati
}
if (line.length() > 150)
{
line = " ... " + line.substr(startColumn, locationLength) + " ... ";
startColumn = 5;
int len = line.length();
line = line.substr(max(0, startColumn - 35), min(startColumn, 35) + min(locationLength + 35, len - startColumn));
if (startColumn + locationLength + 35 < len)
line += " ...";
if (startColumn > 35) {
line = " ... " + line;
startColumn = 40;
}
endColumn = startColumn + locationLength;
}

View File

@ -0,0 +1,4 @@
contract C {
function ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff(announcementType Type, string Announcement, string Link, bool Oppositable, string _str, uint256 _uint, address _addr) onlyOwner external {
}
}

View File

@ -0,0 +1,7 @@
too_long_line.sol:1:1: Warning: Source file does not specify required compiler version!
contract C {
^ (Relevant source part starts here and spans across multiple lines).
too_long_line.sol:2:164: Error: Identifier not found or not unique.
... ffffffffffffffffffffffffffffffffff(announcementType Type, string Announcement, string ...
^--------------^

View File

@ -0,0 +1,5 @@
contract C {
function f(announcementTypeXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Type,
string Announcement, string Link, bool Oppositable, string _str, uint256 _uint, address _addr) onlyOwner external {
}
}

View File

@ -0,0 +1,7 @@
too_long_line_both_sides_short.sol:1:1: Warning: Source file does not specify required compiler version!
contract C {
^ (Relevant source part starts here and spans across multiple lines).
too_long_line_both_sides_short.sol:2:15: Error: Identifier not found or not unique.
function f(announcementTypeXXXXXXXXXXXXXXXXXXX ... XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Type,
^-------------------------------------------------------------------------^

View File

@ -0,0 +1,4 @@
contract C {
function ffffffffffffffffffffff(announcementTypeTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT Ty, string A) onlyOwner external {
}
}

View File

@ -0,0 +1,7 @@
too_long_line_edge_in.sol:1:1: Warning: Source file does not specify required compiler version!
contract C {
^ (Relevant source part starts here and spans across multiple lines).
too_long_line_edge_in.sol:2:36: Error: Identifier not found or not unique.
function ffffffffffffffffffffff(announcementTypeTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT Ty, string A) onlyOwner external {
^----------------------------------------------------------------------------------------------^

View File

@ -0,0 +1,4 @@
contract C {
function fffffffffffffffffffffff(announcementTypeTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT Typ, string A) onlyOwner external {
}
}

View File

@ -0,0 +1,7 @@
too_long_line_edge_out.sol:1:1: Warning: Source file does not specify required compiler version!
contract C {
^ (Relevant source part starts here and spans across multiple lines).
too_long_line_edge_out.sol:2:37: Error: Identifier not found or not unique.
... function fffffffffffffffffffffff(announcementTypeTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT Typ, string A) onlyOwner external ...
^----------------------------------------------------------------------------------------------^

View File

@ -0,0 +1,4 @@
contract C {
function f(announcementType Type, string Announcement, string Link, bool Oppositable, string _str, uint256 _uint, address _addr) onlyOwner external {
}
}

View File

@ -0,0 +1,7 @@
too_long_line_left_short.sol:1:1: Warning: Source file does not specify required compiler version!
contract C {
^ (Relevant source part starts here and spans across multiple lines).
too_long_line_left_short.sol:2:15: Error: Identifier not found or not unique.
function f(announcementType Type, string Announcement, string ...
^--------------^

View File

@ -0,0 +1,5 @@
contract C {
function ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff(announcementType Type,
string Announcement, string Link, bool Oppositable, string _str, uint256 _uint, address _addr) onlyOwner external {
}
}

View File

@ -0,0 +1,7 @@
too_long_line_right_short.sol:1:1: Warning: Source file does not specify required compiler version!
contract C {
^ (Relevant source part starts here and spans across multiple lines).
too_long_line_right_short.sol:2:164: Error: Identifier not found or not unique.
... ffffffffffffffffffffffffffffffffff(announcementType Type,
^--------------^

View File

@ -117,6 +117,8 @@ test_solc_file_input_failures() {
exitCode=$?
set -e
stderr=`sed 's/.*This is a pre-release compiler version, please do not use it in production.*$//' $stderr_path`
if [[ $exitCode -eq 0 ]]; then
printError "Incorrect exit code. Expected failure (non-zero) but got success (0)."
rm -f $stdout_path $stderr_path
@ -133,12 +135,12 @@ test_solc_file_input_failures() {
exit 1
fi
if [[ "$(cat $stderr_path)" != "${stderr_expected}" ]]; then
if [[ "$stderr" != "${stderr_expected}" ]]; then
printError "Incorrect output on stderr received. Expected:"
echo -e "${stderr_expected}"
printError "But got:"
cat $stderr_path
echo $stderr
rm -f $stdout_path $stderr_path
exit 1
fi
@ -156,6 +158,16 @@ printTask "Testing passing empty remappings..."
test_solc_file_input_failures "${0}" "=/some/remapping/target" "" "Invalid remapping: \"=/some/remapping/target\"."
test_solc_file_input_failures "${0}" "ctx:=/some/remapping/target" "" "Invalid remapping: \"ctx:=/some/remapping/target\"."
printTask "Testing passing location printing..."
(
cd "$REPO_ROOT"/test/cmdlineErrorReports/
for file in *.sol
do
ret=`cat $file.ref`
test_solc_file_input_failures "$file" "" "" "$ret"
done
)
printTask "Compiling various other contracts and libraries..."
(
cd "$REPO_ROOT"/test/compilationTests/