From 558a4ac49c40761697580e0915490714c4370767 Mon Sep 17 00:00:00 2001 From: liangdzou Date: Tue, 11 Sep 2018 03:22:13 +0800 Subject: [PATCH] give more information (at most 35 chars before and after) for too long lines add tests for giving more informations for too long lines add edge tests for giving more informations for too long lines avoid printing out tailing white space update test case after avoiding printing out trailing whitespace update test case for removing the pre-release warning from reference refactor the code to if-else flavor rename folder to cmdlineErrorReports under test rename folder to cmdlineErrorReports under test ignore whitespace for reference files avoiding to modify the file stderr_path by call sed without -i option print ' ...' instead of ' ... ' at the end of a line --- .../interface/SourceReferenceFormatter.cpp | 10 ++++++++-- test/cmdlineErrorReports/too_long_line.sol | 4 ++++ test/cmdlineErrorReports/too_long_line.sol.ref | 7 +++++++ .../too_long_line_both_sides_short.sol | 5 +++++ .../too_long_line_both_sides_short.sol.ref | 7 +++++++ .../too_long_line_edge_in.sol | 4 ++++ .../too_long_line_edge_in.sol.ref | 7 +++++++ .../too_long_line_edge_out.sol | 4 ++++ .../too_long_line_edge_out.sol.ref | 7 +++++++ .../too_long_line_left_short.sol | 4 ++++ .../too_long_line_left_short.sol.ref | 7 +++++++ .../too_long_line_right_short.sol | 5 +++++ .../too_long_line_right_short.sol.ref | 7 +++++++ test/cmdlineTests.sh | 16 ++++++++++++++-- 14 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 test/cmdlineErrorReports/too_long_line.sol create mode 100644 test/cmdlineErrorReports/too_long_line.sol.ref create mode 100644 test/cmdlineErrorReports/too_long_line_both_sides_short.sol create mode 100644 test/cmdlineErrorReports/too_long_line_both_sides_short.sol.ref create mode 100644 test/cmdlineErrorReports/too_long_line_edge_in.sol create mode 100644 test/cmdlineErrorReports/too_long_line_edge_in.sol.ref create mode 100644 test/cmdlineErrorReports/too_long_line_edge_out.sol create mode 100644 test/cmdlineErrorReports/too_long_line_edge_out.sol.ref create mode 100644 test/cmdlineErrorReports/too_long_line_left_short.sol create mode 100644 test/cmdlineErrorReports/too_long_line_left_short.sol.ref create mode 100644 test/cmdlineErrorReports/too_long_line_right_short.sol create mode 100644 test/cmdlineErrorReports/too_long_line_right_short.sol.ref diff --git a/libsolidity/interface/SourceReferenceFormatter.cpp b/libsolidity/interface/SourceReferenceFormatter.cpp index 0f0143721..4724fc7f2 100644 --- a/libsolidity/interface/SourceReferenceFormatter.cpp +++ b/libsolidity/interface/SourceReferenceFormatter.cpp @@ -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; } diff --git a/test/cmdlineErrorReports/too_long_line.sol b/test/cmdlineErrorReports/too_long_line.sol new file mode 100644 index 000000000..7df1057a9 --- /dev/null +++ b/test/cmdlineErrorReports/too_long_line.sol @@ -0,0 +1,4 @@ +contract C { + function ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff(announcementType Type, string Announcement, string Link, bool Oppositable, string _str, uint256 _uint, address _addr) onlyOwner external { +} +} diff --git a/test/cmdlineErrorReports/too_long_line.sol.ref b/test/cmdlineErrorReports/too_long_line.sol.ref new file mode 100644 index 000000000..7cad93eea --- /dev/null +++ b/test/cmdlineErrorReports/too_long_line.sol.ref @@ -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 ... + ^--------------^ diff --git a/test/cmdlineErrorReports/too_long_line_both_sides_short.sol b/test/cmdlineErrorReports/too_long_line_both_sides_short.sol new file mode 100644 index 000000000..062f02925 --- /dev/null +++ b/test/cmdlineErrorReports/too_long_line_both_sides_short.sol @@ -0,0 +1,5 @@ +contract C { + function f(announcementTypeXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Type, + string Announcement, string Link, bool Oppositable, string _str, uint256 _uint, address _addr) onlyOwner external { +} +} diff --git a/test/cmdlineErrorReports/too_long_line_both_sides_short.sol.ref b/test/cmdlineErrorReports/too_long_line_both_sides_short.sol.ref new file mode 100644 index 000000000..f2ea427ac --- /dev/null +++ b/test/cmdlineErrorReports/too_long_line_both_sides_short.sol.ref @@ -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, + ^-------------------------------------------------------------------------^ diff --git a/test/cmdlineErrorReports/too_long_line_edge_in.sol b/test/cmdlineErrorReports/too_long_line_edge_in.sol new file mode 100644 index 000000000..6f181c832 --- /dev/null +++ b/test/cmdlineErrorReports/too_long_line_edge_in.sol @@ -0,0 +1,4 @@ +contract C { + function ffffffffffffffffffffff(announcementTypeTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT Ty, string A) onlyOwner external { +} +} diff --git a/test/cmdlineErrorReports/too_long_line_edge_in.sol.ref b/test/cmdlineErrorReports/too_long_line_edge_in.sol.ref new file mode 100644 index 000000000..b66999335 --- /dev/null +++ b/test/cmdlineErrorReports/too_long_line_edge_in.sol.ref @@ -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 { + ^----------------------------------------------------------------------------------------------^ diff --git a/test/cmdlineErrorReports/too_long_line_edge_out.sol b/test/cmdlineErrorReports/too_long_line_edge_out.sol new file mode 100644 index 000000000..29d3cee60 --- /dev/null +++ b/test/cmdlineErrorReports/too_long_line_edge_out.sol @@ -0,0 +1,4 @@ +contract C { + function fffffffffffffffffffffff(announcementTypeTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT Typ, string A) onlyOwner external { +} +} diff --git a/test/cmdlineErrorReports/too_long_line_edge_out.sol.ref b/test/cmdlineErrorReports/too_long_line_edge_out.sol.ref new file mode 100644 index 000000000..76df589ad --- /dev/null +++ b/test/cmdlineErrorReports/too_long_line_edge_out.sol.ref @@ -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 ... + ^----------------------------------------------------------------------------------------------^ diff --git a/test/cmdlineErrorReports/too_long_line_left_short.sol b/test/cmdlineErrorReports/too_long_line_left_short.sol new file mode 100644 index 000000000..2accfcce6 --- /dev/null +++ b/test/cmdlineErrorReports/too_long_line_left_short.sol @@ -0,0 +1,4 @@ +contract C { + function f(announcementType Type, string Announcement, string Link, bool Oppositable, string _str, uint256 _uint, address _addr) onlyOwner external { +} +} diff --git a/test/cmdlineErrorReports/too_long_line_left_short.sol.ref b/test/cmdlineErrorReports/too_long_line_left_short.sol.ref new file mode 100644 index 000000000..efaa559d4 --- /dev/null +++ b/test/cmdlineErrorReports/too_long_line_left_short.sol.ref @@ -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 ... + ^--------------^ diff --git a/test/cmdlineErrorReports/too_long_line_right_short.sol b/test/cmdlineErrorReports/too_long_line_right_short.sol new file mode 100644 index 000000000..936b39613 --- /dev/null +++ b/test/cmdlineErrorReports/too_long_line_right_short.sol @@ -0,0 +1,5 @@ +contract C { + function ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff(announcementType Type, + string Announcement, string Link, bool Oppositable, string _str, uint256 _uint, address _addr) onlyOwner external { +} +} diff --git a/test/cmdlineErrorReports/too_long_line_right_short.sol.ref b/test/cmdlineErrorReports/too_long_line_right_short.sol.ref new file mode 100644 index 000000000..2b0c6d8c2 --- /dev/null +++ b/test/cmdlineErrorReports/too_long_line_right_short.sol.ref @@ -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, + ^--------------^ diff --git a/test/cmdlineTests.sh b/test/cmdlineTests.sh index 6f8a8ac12..f7577cb37 100755 --- a/test/cmdlineTests.sh +++ b/test/cmdlineTests.sh @@ -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/