diff --git a/Changelog.md b/Changelog.md index eb35652f5..9a910a1ac 100644 --- a/Changelog.md +++ b/Changelog.md @@ -11,6 +11,7 @@ Features: * Optimizer: Optimize across ``mload`` if ``msize()`` is not used. * Static Analyzer: Error on duplicated super constructor calls as experimental 0.5.0 feature. * Syntax Checker: Issue warning for empty structs (or error as experimental 0.5.0 feature). + * Syntax Tests: Add source locations to syntax test expectations. * General: Introduce new constructor syntax using the ``constructor`` keyword as experimental 0.5.0 feature. * Inheritance: Error when using empty parentheses for base class constructors that require arguments as experimental 0.5.0 feature. * Inheritance: Error when using no parentheses in modifier-style constructor calls as experimental 0.5.0 feature. diff --git a/test/libsolidity/FormattedScope.h b/test/libsolidity/FormattedScope.h index 78560848e..923404f0c 100644 --- a/test/libsolidity/FormattedScope.h +++ b/test/libsolidity/FormattedScope.h @@ -38,6 +38,8 @@ static constexpr char const* GREEN = "\033[1;32m"; static constexpr char const* YELLOW = "\033[1;33m"; static constexpr char const* CYAN = "\033[1;36m"; static constexpr char const* BOLD = "\033[1m"; +static constexpr char const* RED_BACKGROUND = "\033[48;5;160m"; +static constexpr char const* ORANGE_BACKGROUND = "\033[48;5;166m"; static constexpr char const* INVERSE = "\033[7m"; } diff --git a/test/libsolidity/SyntaxTest.cpp b/test/libsolidity/SyntaxTest.cpp index 329543bfb..1c2355d5f 100644 --- a/test/libsolidity/SyntaxTest.cpp +++ b/test/libsolidity/SyntaxTest.cpp @@ -34,17 +34,38 @@ namespace fs = boost::filesystem; using namespace boost::unit_test; template -void skipWhitespace(IteratorType& it, IteratorType end) +void skipWhitespace(IteratorType& _it, IteratorType _end) { - while (it != end && isspace(*it)) - ++it; + while (_it != _end && isspace(*_it)) + ++_it; } template -void skipSlashes(IteratorType& it, IteratorType end) +void skipSlashes(IteratorType& _it, IteratorType _end) { - while (it != end && *it == '/') - ++it; + while (_it != _end && *_it == '/') + ++_it; +} + +void expect(string::iterator& _it, string::iterator _end, string::value_type _c) +{ + if (_it == _end || *_it != _c) + throw runtime_error(string("Invalid test expectation. Expected: \"") + _c + "\"."); + ++_it; +} + +int parseUnsignedInteger(string::iterator &_it, string::iterator _end) +{ + if (_it == _end || !isdigit(*_it)) + throw runtime_error("Invalid test expectation. Source location expected."); + int result = 0; + while (_it != _end && isdigit(*_it)) + { + result *= 10; + result += *_it - '0'; + ++_it; + } + return result; } SyntaxTest::SyntaxTest(string const& _filename) @@ -60,22 +81,39 @@ SyntaxTest::SyntaxTest(string const& _filename) bool SyntaxTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted) { + string const versionPragma = "pragma solidity >=0.0;\n"; m_compiler.reset(); - m_compiler.addSource("", "pragma solidity >=0.0;\n" + m_source); + m_compiler.addSource("", versionPragma + m_source); m_compiler.setEVMVersion(dev::test::Options::get().evmVersion()); if (m_compiler.parse()) m_compiler.analyze(); for (auto const& currentError: filterErrors(m_compiler.errors(), true)) - m_errorList.emplace_back(SyntaxTestError{currentError->typeName(), errorMessage(*currentError)}); + { + int locationStart = -1, locationEnd = -1; + if (auto location = boost::get_error_info(*currentError)) + { + // ignore the version pragma inserted by the testing tool when calculating locations. + if (location->start >= static_cast(versionPragma.size())) + locationStart = location->start - versionPragma.size(); + if (location->end >= static_cast(versionPragma.size())) + locationEnd = location->end - versionPragma.size(); + } + m_errorList.emplace_back(SyntaxTestError{ + currentError->typeName(), + errorMessage(*currentError), + locationStart, + locationEnd + }); + } if (m_expectations != m_errorList) { string nextIndentLevel = _linePrefix + " "; FormattedScope(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Expected result:" << endl; printErrorList(_stream, m_expectations, nextIndentLevel, _formatted); - FormattedScope(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Obtained result:\n"; + FormattedScope(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Obtained result:" << endl; printErrorList(_stream, m_errorList, nextIndentLevel, _formatted); return false; } @@ -99,6 +137,16 @@ void SyntaxTest::printErrorList( _stream << _linePrefix; _stream << error.type << ": "; } + if (error.locationStart >= 0 || error.locationEnd >= 0) + { + _stream << "("; + if (error.locationStart >= 0) + _stream << error.locationStart; + _stream << "-"; + if (error.locationEnd >= 0) + _stream << error.locationEnd; + _stream << "): "; + } _stream << error.message << endl; } } @@ -147,8 +195,28 @@ vector SyntaxTest::parseExpectations(istream& _stream) skipWhitespace(it, line.end()); + int locationStart = -1; + int locationEnd = -1; + + if (it != line.end() && *it == '(') + { + ++it; + locationStart = parseUnsignedInteger(it, line.end()); + expect(it, line.end(), '-'); + locationEnd = parseUnsignedInteger(it, line.end()); + expect(it, line.end(), ')'); + expect(it, line.end(), ':'); + } + + skipWhitespace(it, line.end()); + string errorMessage(it, line.end()); - expectations.emplace_back(SyntaxTestError{move(errorType), move(errorMessage)}); + expectations.emplace_back(SyntaxTestError{ + move(errorType), + move(errorMessage), + locationStart, + locationEnd + }); } return expectations; } diff --git a/test/libsolidity/SyntaxTest.h b/test/libsolidity/SyntaxTest.h index dddd86ef4..6159e7894 100644 --- a/test/libsolidity/SyntaxTest.h +++ b/test/libsolidity/SyntaxTest.h @@ -40,9 +40,14 @@ struct SyntaxTestError { std::string type; std::string message; + int locationStart; + int locationEnd; bool operator==(SyntaxTestError const& _rhs) const { - return type == _rhs.type && message == _rhs.message; + return type == _rhs.type && + message == _rhs.message && + locationStart == _rhs.locationStart && + locationEnd == _rhs.locationEnd; } }; diff --git a/test/libsolidity/syntaxTests/constants/cyclic_dependency_1.sol b/test/libsolidity/syntaxTests/constants/cyclic_dependency_1.sol index 2b6aa0883..cb553fbe4 100644 --- a/test/libsolidity/syntaxTests/constants/cyclic_dependency_1.sol +++ b/test/libsolidity/syntaxTests/constants/cyclic_dependency_1.sol @@ -2,4 +2,4 @@ contract C { uint constant a = a; } // ---- -// TypeError: The value of the constant a has a cyclic dependency via a. +// TypeError: (17-36): The value of the constant a has a cyclic dependency via a. diff --git a/test/libsolidity/syntaxTests/constants/cyclic_dependency_2.sol b/test/libsolidity/syntaxTests/constants/cyclic_dependency_2.sol index 461979f85..00f9bb0f1 100644 --- a/test/libsolidity/syntaxTests/constants/cyclic_dependency_2.sol +++ b/test/libsolidity/syntaxTests/constants/cyclic_dependency_2.sol @@ -5,6 +5,6 @@ contract C { uint constant d = 2 + a; } // ---- -// TypeError: The value of the constant a has a cyclic dependency via c. -// TypeError: The value of the constant c has a cyclic dependency via d. -// TypeError: The value of the constant d has a cyclic dependency via a. +// TypeError: (17-40): The value of the constant a has a cyclic dependency via c. +// TypeError: (71-111): The value of the constant c has a cyclic dependency via d. +// TypeError: (117-140): The value of the constant d has a cyclic dependency via a. diff --git a/test/libsolidity/syntaxTests/constants/cyclic_dependency_3.sol b/test/libsolidity/syntaxTests/constants/cyclic_dependency_3.sol index f63be05e3..969ed50d3 100644 --- a/test/libsolidity/syntaxTests/constants/cyclic_dependency_3.sol +++ b/test/libsolidity/syntaxTests/constants/cyclic_dependency_3.sol @@ -5,7 +5,7 @@ contract C { uint constant c = b; } // ---- -// TypeError: The value of the constant x has a cyclic dependency via a. -// TypeError: The value of the constant a has a cyclic dependency via b. -// TypeError: The value of the constant b has a cyclic dependency via c. -// TypeError: The value of the constant c has a cyclic dependency via b. +// TypeError: (17-36): The value of the constant x has a cyclic dependency via a. +// TypeError: (42-65): The value of the constant a has a cyclic dependency via b. +// TypeError: (71-90): The value of the constant b has a cyclic dependency via c. +// TypeError: (96-115): The value of the constant c has a cyclic dependency via b. diff --git a/test/libsolidity/syntaxTests/double_stateVariable_declaration.sol b/test/libsolidity/syntaxTests/double_stateVariable_declaration.sol index c5507b649..fda4a17ab 100644 --- a/test/libsolidity/syntaxTests/double_stateVariable_declaration.sol +++ b/test/libsolidity/syntaxTests/double_stateVariable_declaration.sol @@ -3,4 +3,4 @@ contract test { uint128 variable; } // ---- -// DeclarationError: Identifier already declared. +// DeclarationError: (36-52): Identifier already declared. diff --git a/test/libsolidity/syntaxTests/double_variable_declaration.sol b/test/libsolidity/syntaxTests/double_variable_declaration.sol index 3349cfece..9ab87959c 100644 --- a/test/libsolidity/syntaxTests/double_variable_declaration.sol +++ b/test/libsolidity/syntaxTests/double_variable_declaration.sol @@ -5,4 +5,4 @@ contract test { } } // ---- -// DeclarationError: Identifier already declared. +// DeclarationError: (71-80): Identifier already declared. diff --git a/test/libsolidity/syntaxTests/double_variable_declaration_050.sol b/test/libsolidity/syntaxTests/double_variable_declaration_050.sol index 9c2d40d52..2f47e6dc9 100644 --- a/test/libsolidity/syntaxTests/double_variable_declaration_050.sol +++ b/test/libsolidity/syntaxTests/double_variable_declaration_050.sol @@ -6,6 +6,6 @@ contract test { } } // ---- -// Warning: This declaration shadows an existing declaration. -// Warning: Unused local variable. -// Warning: Unused local variable. +// Warning: (101-110): This declaration shadows an existing declaration. +// Warning: (76-85): Unused local variable. +// Warning: (101-110): Unused local variable. diff --git a/test/libsolidity/syntaxTests/empty_struct.sol b/test/libsolidity/syntaxTests/empty_struct.sol index dcced618a..12655309f 100644 --- a/test/libsolidity/syntaxTests/empty_struct.sol +++ b/test/libsolidity/syntaxTests/empty_struct.sol @@ -2,4 +2,4 @@ contract test { struct A {} } // ---- -// Warning: Defining empty structs is deprecated. +// Warning: (17-28): Defining empty structs is deprecated. diff --git a/test/libsolidity/syntaxTests/empty_struct_050.sol b/test/libsolidity/syntaxTests/empty_struct_050.sol index dbec93c49..886f1f838 100644 --- a/test/libsolidity/syntaxTests/empty_struct_050.sol +++ b/test/libsolidity/syntaxTests/empty_struct_050.sol @@ -3,4 +3,4 @@ contract test { struct A {} } // ---- -// SyntaxError: Defining empty structs is disallowed. +// SyntaxError: (47-58): Defining empty structs is disallowed. diff --git a/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses.sol b/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses.sol index b3fbd04ac..0b18b995b 100644 --- a/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses.sol +++ b/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses.sol @@ -4,4 +4,4 @@ contract Base { contract Derived is Base(2) { } contract Derived2 is Base(), Derived() { } // ---- -// Warning: Wrong argument count for constructor call: 0 arguments given but expected 1. +// Warning: (101-107): Wrong argument count for constructor call: 0 arguments given but expected 1. diff --git a/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses_V050.sol b/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses_V050.sol index b37286347..db04ab8c9 100644 --- a/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses_V050.sol +++ b/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses_V050.sol @@ -6,4 +6,4 @@ contract Base { contract Derived is Base(2) { } contract Derived2 is Base(), Derived() { } // ---- -// TypeError: Wrong argument count for constructor call: 0 arguments given but expected 1. +// TypeError: (132-138): Wrong argument count for constructor call: 0 arguments given but expected 1. diff --git a/test/libsolidity/syntaxTests/inheritance/base_arguments_multiple_inheritance.sol b/test/libsolidity/syntaxTests/inheritance/base_arguments_multiple_inheritance.sol index 5483d5d7d..015b33e59 100644 --- a/test/libsolidity/syntaxTests/inheritance/base_arguments_multiple_inheritance.sol +++ b/test/libsolidity/syntaxTests/inheritance/base_arguments_multiple_inheritance.sol @@ -6,4 +6,4 @@ contract Derived is Base, Base1 { constructor(uint i) Base(i) public {} } // ---- -// Warning: Base constructor arguments given twice. +// Warning: (138-145): Base constructor arguments given twice. diff --git a/test/libsolidity/syntaxTests/inheritance/disallow_modifier_style_without_parentheses.sol b/test/libsolidity/syntaxTests/inheritance/disallow_modifier_style_without_parentheses.sol index 0c159a228..6cf68d2aa 100644 --- a/test/libsolidity/syntaxTests/inheritance/disallow_modifier_style_without_parentheses.sol +++ b/test/libsolidity/syntaxTests/inheritance/disallow_modifier_style_without_parentheses.sol @@ -1,4 +1,4 @@ contract A { constructor() public { } } contract B is A { constructor() A public { } } // ---- -// Warning: Modifier-style base constructor call without arguments. +// Warning: (72-73): Modifier-style base constructor call without arguments. diff --git a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor.sol b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor.sol index 8b1af2456..24cff54de 100644 --- a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor.sol +++ b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor.sol @@ -2,4 +2,4 @@ contract A { constructor(uint) public { } } contract B is A(2) { constructor() public { } } contract C is B { constructor() A(3) public { } } // ---- -// Warning: Base constructor arguments given twice. +// Warning: (125-129): Base constructor arguments given twice. diff --git a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor_V050.sol b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor_V050.sol index 6616c9a9f..8d5df5bf5 100644 --- a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor_V050.sol +++ b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor_V050.sol @@ -4,4 +4,4 @@ contract A { constructor(uint) public { } } contract B is A(2) { constructor() public { } } contract C is B { constructor() A(3) public { } } // ---- -// DeclarationError: Base constructor arguments given twice. +// DeclarationError: (156-160): Base constructor arguments given twice. diff --git a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base.sol b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base.sol index 1fb504fe1..9ceaea5ea 100644 --- a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base.sol +++ b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base.sol @@ -1,4 +1,4 @@ contract A { constructor(uint) public { } } contract B is A(2) { constructor() A(3) public { } } // ---- -// Warning: Base constructor arguments given twice. +// Warning: (79-83): Base constructor arguments given twice. diff --git a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_V050.sol b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_V050.sol index 96eb1bb12..f9325f99d 100644 --- a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_V050.sol +++ b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_V050.sol @@ -3,4 +3,4 @@ pragma experimental "v0.5.0"; contract A { constructor(uint) public { } } contract B is A(2) { constructor() A(3) public { } } // ---- -// DeclarationError: Base constructor arguments given twice. +// DeclarationError: (110-114): Base constructor arguments given twice. diff --git a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi.sol b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi.sol index db9ffc85e..e5c2aa365 100644 --- a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi.sol +++ b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi.sol @@ -3,5 +3,5 @@ contract A is C(2) {} contract B is C(2) {} contract D is A, B { constructor() C(3) public {} } // ---- -// Warning: Base constructor arguments given twice. -// Warning: Base constructor arguments given twice. +// Warning: (122-126): Base constructor arguments given twice. +// Warning: (122-126): Base constructor arguments given twice. diff --git a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor.sol b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor.sol index fe280ad59..1abf29926 100644 --- a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor.sol +++ b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor.sol @@ -3,4 +3,4 @@ contract A is C(2) {} contract B is C(2) {} contract D is A, B {} // ---- -// Warning: Base constructor arguments given twice. +// Warning: (87-108): Base constructor arguments given twice. diff --git a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor_modifier_style.sol b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor_modifier_style.sol index ea85aae77..e15242db0 100644 --- a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor_modifier_style.sol +++ b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor_modifier_style.sol @@ -3,4 +3,4 @@ contract A is C { constructor() C(2) public {} } contract B is C { constructor() C(2) public {} } contract D is A, B { } // ---- -// Warning: Base constructor arguments given twice. +// Warning: (141-163): Base constructor arguments given twice. diff --git a/test/libsolidity/syntaxTests/inheritance/too_few_base_arguments.sol b/test/libsolidity/syntaxTests/inheritance/too_few_base_arguments.sol index 45a0770f3..c55c41f2e 100644 --- a/test/libsolidity/syntaxTests/inheritance/too_few_base_arguments.sol +++ b/test/libsolidity/syntaxTests/inheritance/too_few_base_arguments.sol @@ -6,5 +6,5 @@ contract Derived2 is Base { constructor() Base(2) public { } } // ---- -// TypeError: Wrong argument count for constructor call: 1 arguments given but expected 2. -// TypeError: Wrong argument count for modifier invocation: 1 arguments given but expected 2. +// TypeError: (74-81): Wrong argument count for constructor call: 1 arguments given but expected 2. +// TypeError: (130-137): Wrong argument count for modifier invocation: 1 arguments given but expected 2. diff --git a/test/libsolidity/syntaxTests/parsing/missing_variable_name_in_declaration.sol b/test/libsolidity/syntaxTests/parsing/missing_variable_name_in_declaration.sol index c03fd97d1..fd3067e30 100644 --- a/test/libsolidity/syntaxTests/parsing/missing_variable_name_in_declaration.sol +++ b/test/libsolidity/syntaxTests/parsing/missing_variable_name_in_declaration.sol @@ -2,4 +2,4 @@ contract test { uint256 ; } // ---- -// ParserError: Expected identifier, got 'Semicolon' +// ParserError: (28-28): Expected identifier, got 'Semicolon' diff --git a/test/libsolidity/syntaxTests/scoping/double_function_declaration.sol b/test/libsolidity/syntaxTests/scoping/double_function_declaration.sol index 2841fd382..dfd67aaaf 100644 --- a/test/libsolidity/syntaxTests/scoping/double_function_declaration.sol +++ b/test/libsolidity/syntaxTests/scoping/double_function_declaration.sol @@ -3,4 +3,4 @@ contract test { function fun() public { } } // ---- -// DeclarationError: Function with same name and arguments defined twice. +// DeclarationError: (20-45): Function with same name and arguments defined twice. diff --git a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope.sol b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope.sol index ea61d0f37..d90ec2d77 100644 --- a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope.sol +++ b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope.sol @@ -5,4 +5,4 @@ contract test { } } // ---- -// DeclarationError: Identifier already declared. +// DeclarationError: (77-83): Identifier already declared. diff --git a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_050.sol b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_050.sol index 221959635..06bfe7be2 100644 --- a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_050.sol +++ b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_050.sol @@ -6,5 +6,5 @@ contract test { } } // ---- -// Warning: Unused local variable. -// Warning: Unused local variable. +// Warning: (87-93): Unused local variable. +// Warning: (107-113): Unused local variable. diff --git a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation.sol b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation.sol index 6af89c93d..1a5ff2f9c 100644 --- a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation.sol +++ b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation.sol @@ -5,4 +5,4 @@ contract test { } } // ---- -// DeclarationError: Identifier already declared. +// DeclarationError: (75-81): Identifier already declared. diff --git a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation_050.sol b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation_050.sol index 73cddfed5..20ea03498 100644 --- a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation_050.sol +++ b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation_050.sol @@ -6,5 +6,5 @@ contract test { } } // ---- -// Warning: Unused local variable. -// Warning: Unused local variable. +// Warning: (87-93): Unused local variable. +// Warning: (105-111): Unused local variable. diff --git a/test/libsolidity/syntaxTests/scoping/name_shadowing.sol b/test/libsolidity/syntaxTests/scoping/name_shadowing.sol index d16877f95..67ada4a43 100644 --- a/test/libsolidity/syntaxTests/scoping/name_shadowing.sol +++ b/test/libsolidity/syntaxTests/scoping/name_shadowing.sol @@ -3,5 +3,4 @@ contract test { function f() pure public { uint32 variable; variable = 2; } } // ---- -// Warning: This declaration shadows an existing declaration. - +// Warning: (69-84): This declaration shadows an existing declaration. diff --git a/test/libsolidity/syntaxTests/scoping/scoping.sol b/test/libsolidity/syntaxTests/scoping/scoping.sol index f47a3e99e..34b055d98 100644 --- a/test/libsolidity/syntaxTests/scoping/scoping.sol +++ b/test/libsolidity/syntaxTests/scoping/scoping.sol @@ -8,4 +8,4 @@ contract test { } } // ---- -// DeclarationError: Undeclared identifier. +// DeclarationError: (123-124): Undeclared identifier. diff --git a/test/libsolidity/syntaxTests/scoping/scoping_activation.sol b/test/libsolidity/syntaxTests/scoping/scoping_activation.sol index 0ed74a00d..7334bc49c 100644 --- a/test/libsolidity/syntaxTests/scoping/scoping_activation.sol +++ b/test/libsolidity/syntaxTests/scoping/scoping_activation.sol @@ -6,4 +6,4 @@ contract test { } } // ---- -// DeclarationError: Undeclared identifier. Did you mean "x"? +// DeclarationError: (85-86): Undeclared identifier. Did you mean "x"? diff --git a/test/libsolidity/syntaxTests/scoping/scoping_for3.sol b/test/libsolidity/syntaxTests/scoping/scoping_for3.sol index 9bc7d5695..1814cb475 100644 --- a/test/libsolidity/syntaxTests/scoping/scoping_for3.sol +++ b/test/libsolidity/syntaxTests/scoping/scoping_for3.sol @@ -8,4 +8,4 @@ contract test { } } // ---- -// DeclarationError: Undeclared identifier. +// DeclarationError: (154-155): Undeclared identifier. diff --git a/test/libsolidity/syntaxTests/scoping/scoping_for_decl_in_body.sol b/test/libsolidity/syntaxTests/scoping/scoping_for_decl_in_body.sol index 07503983e..3e80b3853 100644 --- a/test/libsolidity/syntaxTests/scoping/scoping_for_decl_in_body.sol +++ b/test/libsolidity/syntaxTests/scoping/scoping_for_decl_in_body.sol @@ -7,4 +7,4 @@ contract test { } } // ---- -// DeclarationError: Undeclared identifier. +// DeclarationError: (93-94): Undeclared identifier. diff --git a/test/libsolidity/syntaxTests/scoping/scoping_self_use_050.sol b/test/libsolidity/syntaxTests/scoping/scoping_self_use_050.sol index e942020e8..ab3dcefb9 100644 --- a/test/libsolidity/syntaxTests/scoping/scoping_self_use_050.sol +++ b/test/libsolidity/syntaxTests/scoping/scoping_self_use_050.sol @@ -5,4 +5,4 @@ contract test { } } // ---- -// DeclarationError: Undeclared identifier. Did you mean "a"? +// DeclarationError: (94-95): Undeclared identifier. Did you mean "a"? diff --git a/test/libsolidity/syntaxTests/smoke_test.sol b/test/libsolidity/syntaxTests/smoke_test.sol index 2d48098a1..6abaff183 100644 --- a/test/libsolidity/syntaxTests/smoke_test.sol +++ b/test/libsolidity/syntaxTests/smoke_test.sol @@ -3,4 +3,4 @@ contract test { function fun(uint256 arg1) public { uint256 y; y = arg1; } } // ---- -// Warning: Function state mutability can be restricted to pure +// Warning: (42-100): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol index 9f57c3a4a..c98d7a577 100644 --- a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol +++ b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol @@ -5,7 +5,7 @@ contract C { } } // ---- -// TypeError: This type cannot be encoded. -// TypeError: This type cannot be encoded. -// TypeError: This type cannot be encoded. -// TypeError: This type cannot be encoded. +// TypeError: (74-83): This type cannot be encoded. +// TypeError: (85-86): This type cannot be encoded. +// TypeError: (88-98): This type cannot be encoded. +// TypeError: (100-115): This type cannot be encoded. diff --git a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_special_types.sol b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_special_types.sol index a7d13215b..f1b5606ea 100644 --- a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_special_types.sol +++ b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_special_types.sol @@ -6,8 +6,8 @@ contract C { } } // ---- -// TypeError: This type cannot be encoded. -// TypeError: This type cannot be encoded. -// TypeError: This type cannot be encoded. -// TypeError: This type cannot be encoded. -// TypeError: This type cannot be encoded. +// TypeError: (80-106): This type cannot be encoded. +// TypeError: (108-113): This type cannot be encoded. +// TypeError: (160-164): This type cannot be encoded. +// TypeError: (166-168): This type cannot be encoded. +// TypeError: (170-176): This type cannot be encoded. diff --git a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs.sol b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs.sol index 378155e98..cc354819f 100644 --- a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs.sol +++ b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs.sol @@ -9,6 +9,6 @@ contract C { } } // ---- -// Warning: Defining empty structs is deprecated. -// TypeError: This type cannot be encoded. -// TypeError: This type cannot be encoded. +// Warning: (51-63): Defining empty structs is deprecated. +// TypeError: (131-132): This type cannot be encoded. +// TypeError: (134-135): This type cannot be encoded. diff --git a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_types.sol b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_types.sol index 6e073fd88..d10c17187 100644 --- a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_types.sol +++ b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_types.sol @@ -9,9 +9,9 @@ contract C { } } // ---- -// Warning: Defining empty structs is deprecated. -// TypeError: This type cannot be encoded. -// TypeError: This type cannot be encoded. -// TypeError: This type cannot be encoded. -// TypeError: This type cannot be encoded. -// TypeError: This type cannot be encoded. +// Warning: (51-63): Defining empty structs is deprecated. +// TypeError: (168-169): This type cannot be encoded. +// TypeError: (171-172): This type cannot be encoded. +// TypeError: (179-180): This type cannot be encoded. +// TypeError: (182-186): This type cannot be encoded. +// TypeError: (188-194): This type cannot be encoded. diff --git a/test/libsolidity/syntaxTests/structs/recursion/multi_struct_composition.sol b/test/libsolidity/syntaxTests/structs/recursion/multi_struct_composition.sol index 9a1c22f18..895bb6c58 100644 --- a/test/libsolidity/syntaxTests/structs/recursion/multi_struct_composition.sol +++ b/test/libsolidity/syntaxTests/structs/recursion/multi_struct_composition.sol @@ -12,4 +12,4 @@ contract C { function f(T) public pure { } } // ---- -// Warning: Experimental features are turned on. Do not use experimental features on live deployments. +// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments. diff --git a/test/libsolidity/syntaxTests/structs/recursion/parallel_structs.sol b/test/libsolidity/syntaxTests/structs/recursion/parallel_structs.sol index d4ad088dc..96362ef0c 100644 --- a/test/libsolidity/syntaxTests/structs/recursion/parallel_structs.sol +++ b/test/libsolidity/syntaxTests/structs/recursion/parallel_structs.sol @@ -12,4 +12,4 @@ contract TestContract function addTestStruct(TestStruct) public pure {} } // ---- -// Warning: Experimental features are turned on. Do not use experimental features on live deployments. +// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments. diff --git a/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs.sol b/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs.sol index c02a8aa48..4966a731e 100644 --- a/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs.sol +++ b/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs.sol @@ -4,4 +4,4 @@ contract C { } } // ---- -// TypeError: Internal or recursive type is not allowed for public or external functions. +// TypeError: (91-92): Internal or recursive type is not allowed for public or external functions. diff --git a/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs2.sol b/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs2.sol index e9488cf49..681139245 100644 --- a/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs2.sol +++ b/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs2.sol @@ -4,4 +4,4 @@ contract C { } } // ---- -// TypeError: Internal or recursive type is not allowed for public or external functions. +// TypeError: (94-95): Internal or recursive type is not allowed for public or external functions. diff --git a/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs3.sol b/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs3.sol index 6728baec6..47690d9bc 100644 --- a/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs3.sol +++ b/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs3.sol @@ -5,4 +5,4 @@ contract C { } } // ---- -// TypeError: Internal or recursive type is not allowed for public or external functions. +// TypeError: (119-122): Internal or recursive type is not allowed for public or external functions. diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_directly_recursive.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_directly_recursive.sol index cac2e23fd..bcffe3838 100644 --- a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_directly_recursive.sol +++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_directly_recursive.sol @@ -5,4 +5,4 @@ contract Test { } } // ---- -// TypeError: Recursive struct definition. +// TypeError: (20-93): Recursive struct definition. diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive.sol index 11fc63078..64dab8d00 100644 --- a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive.sol +++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive.sol @@ -9,4 +9,4 @@ contract Test { } } // ---- -// TypeError: Recursive struct definition. +// TypeError: (20-118): Recursive struct definition. diff --git a/test/libsolidity/syntaxTests/visibility/interface/function_default.sol b/test/libsolidity/syntaxTests/visibility/interface/function_default.sol index 7b9044dd2..72ce3b40c 100644 --- a/test/libsolidity/syntaxTests/visibility/interface/function_default.sol +++ b/test/libsolidity/syntaxTests/visibility/interface/function_default.sol @@ -2,5 +2,5 @@ interface I { function f(); } // ---- -// Warning: Functions in interfaces should be declared external. -// Warning: No visibility specified. Defaulting to "public". In interfaces it defaults to external. +// Warning: (15-28): Functions in interfaces should be declared external. +// Warning: (15-28): No visibility specified. Defaulting to "public". In interfaces it defaults to external. diff --git a/test/libsolidity/syntaxTests/visibility/interface/function_default050.sol b/test/libsolidity/syntaxTests/visibility/interface/function_default050.sol index 127d4e92a..513df26b3 100644 --- a/test/libsolidity/syntaxTests/visibility/interface/function_default050.sol +++ b/test/libsolidity/syntaxTests/visibility/interface/function_default050.sol @@ -3,5 +3,5 @@ interface I { function f(); } // ---- -// SyntaxError: No visibility specified. -// TypeError: Functions in interfaces must be declared external. +// SyntaxError: (45-58): No visibility specified. +// TypeError: (45-58): Functions in interfaces must be declared external. diff --git a/test/libsolidity/syntaxTests/visibility/interface/function_internal.sol b/test/libsolidity/syntaxTests/visibility/interface/function_internal.sol index a1cf52463..ac62e69b2 100644 --- a/test/libsolidity/syntaxTests/visibility/interface/function_internal.sol +++ b/test/libsolidity/syntaxTests/visibility/interface/function_internal.sol @@ -2,4 +2,4 @@ interface I { function f() internal; } // ---- -// TypeError: Functions in interfaces cannot be internal or private. +// TypeError: (15-37): Functions in interfaces cannot be internal or private. diff --git a/test/libsolidity/syntaxTests/visibility/interface/function_private.sol b/test/libsolidity/syntaxTests/visibility/interface/function_private.sol index 887ebd4bf..881e647e1 100644 --- a/test/libsolidity/syntaxTests/visibility/interface/function_private.sol +++ b/test/libsolidity/syntaxTests/visibility/interface/function_private.sol @@ -2,4 +2,4 @@ interface I { function f() private; } // ---- -// TypeError: Functions in interfaces cannot be internal or private. +// TypeError: (15-36): Functions in interfaces cannot be internal or private. diff --git a/test/libsolidity/syntaxTests/visibility/interface/function_public.sol b/test/libsolidity/syntaxTests/visibility/interface/function_public.sol index 146d4f5b5..891d9fdf3 100644 --- a/test/libsolidity/syntaxTests/visibility/interface/function_public.sol +++ b/test/libsolidity/syntaxTests/visibility/interface/function_public.sol @@ -2,4 +2,4 @@ interface I { function f() public; } // ---- -// Warning: Functions in interfaces should be declared external. \ No newline at end of file +// Warning: (15-35): Functions in interfaces should be declared external. diff --git a/test/libsolidity/syntaxTests/visibility/interface/function_public050.sol b/test/libsolidity/syntaxTests/visibility/interface/function_public050.sol index f957f0b4c..e0c040956 100644 --- a/test/libsolidity/syntaxTests/visibility/interface/function_public050.sol +++ b/test/libsolidity/syntaxTests/visibility/interface/function_public050.sol @@ -3,4 +3,4 @@ interface I { function f() public; } // ---- -// TypeError: Functions in interfaces must be declared external. \ No newline at end of file +// TypeError: (45-65): Functions in interfaces must be declared external. diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index 07df8f60a..7a147bd02 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -55,7 +55,6 @@ public: { Success, Failure, - InputOutputError, Exception }; @@ -90,11 +89,53 @@ string SyntaxTestTool::editor; void SyntaxTestTool::printContract() const { - stringstream stream(m_test->source()); - string line; - while (getline(stream, line)) - cout << " " << line << endl; - cout << endl; + if (m_formatted) + { + string const& source = m_test->source(); + if (source.empty()) + return; + + std::vector sourceFormatting(source.length(), formatting::RESET); + for (auto const& error: m_test->errorList()) + if (error.locationStart >= 0 && error.locationEnd >= 0) + { + assert(static_cast(error.locationStart) < source.length()); + assert(static_cast(error.locationEnd) < source.length()); + bool isWarning = error.type == "Warning"; + for (int i = error.locationStart; i < error.locationEnd; i++) + if (isWarning) + { + if (sourceFormatting[i] == formatting::RESET) + sourceFormatting[i] = formatting::ORANGE_BACKGROUND; + } + else + sourceFormatting[i] = formatting::RED_BACKGROUND; + } + + cout << " " << sourceFormatting.front() << source.front(); + for (size_t i = 1; i < source.length(); i++) + { + if (sourceFormatting[i] != sourceFormatting[i - 1]) + cout << sourceFormatting[i]; + if (source[i] != '\n') + cout << source[i]; + else + { + cout << formatting::RESET << endl; + if (i + 1 < source.length()) + cout << " " << sourceFormatting[i]; + } + } + cout << formatting::RESET << endl; + } + else + { + stringstream stream(m_test->source()); + string line; + while (getline(stream, line)) + cout << " " << line << endl; + cout << endl; + } } SyntaxTestTool::Result SyntaxTestTool::process() @@ -107,15 +148,6 @@ SyntaxTestTool::Result SyntaxTestTool::process() try { m_test = unique_ptr(new SyntaxTest(m_path.string())); - } - catch (std::exception const& _e) - { - FormattedScope(cout, m_formatted, {BOLD, RED}) << "cannot read test: " << _e.what() << endl; - return Result::InputOutputError; - } - - try - { success = m_test->run(outputMessages, " ", m_formatted); } catch(CompilerError const& _e) @@ -142,6 +174,11 @@ SyntaxTestTool::Result SyntaxTestTool::process() "UnimplementedFeatureError: " << SyntaxTest::errorMessage(_e) << endl; return Result::Exception; } + catch (std::exception const& _e) + { + FormattedScope(cout, m_formatted, {BOLD, RED}) << "Exception: " << _e.what() << endl; + return Result::Exception; + } catch(...) { FormattedScope(cout, m_formatted, {BOLD, RED}) << @@ -262,10 +299,6 @@ SyntaxTestStats SyntaxTestTool::processPath( paths.pop(); ++successCount; break; - default: - // non-recoverable error; continue with next test case - paths.pop(); - break; } } }