diff options
-rw-r--r-- | SolidityNameAndTypeResolution.cpp | 119 | ||||
-rw-r--r-- | SolidityNatspecJSON.cpp | 12 |
2 files changed, 50 insertions, 81 deletions
diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp index 6e6254eb..c3a4a337 100644 --- a/SolidityNameAndTypeResolution.cpp +++ b/SolidityNameAndTypeResolution.cpp @@ -28,7 +28,7 @@ #include <libsolidity/Parser.h> #include <libsolidity/NameAndTypeResolver.h> #include <libsolidity/Exceptions.h> -#include <boost/test/unit_test.hpp> +#include "TestHelper.h" using namespace std; @@ -58,30 +58,6 @@ ASTPointer<SourceUnit> parseTextAndResolveNames(std::string const& _source) return sourceUnit; } -ASTPointer<SourceUnit> parseTextAndResolveNamesWithChecks(std::string const& _source) -{ - Parser parser; - ASTPointer<SourceUnit> sourceUnit; - try - { - sourceUnit = parser.parse(std::make_shared<Scanner>(CharStream(_source))); - NameAndTypeResolver resolver({}); - resolver.registerDeclarations(*sourceUnit); - for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes()) - if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get())) - resolver.resolveNamesAndTypes(*contract); - for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes()) - if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get())) - resolver.checkTypeRequirements(*contract); - } - catch(boost::exception const& _e) - { - auto msg = std::string("Parsing text and resolving names failed with: \n") + boost::diagnostic_information(_e); - BOOST_FAIL(msg); - } - return sourceUnit; -} - static ContractDefinition const* retrieveContract(ASTPointer<SourceUnit> _source, unsigned index) { ContractDefinition* contract; @@ -109,7 +85,7 @@ BOOST_AUTO_TEST_CASE(smoke_test) " uint256 stateVariable1;\n" " function fun(uint256 arg1) { var x; uint256 y; }" "}\n"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNamesWithChecks(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(double_stateVariable_declaration) @@ -144,7 +120,7 @@ BOOST_AUTO_TEST_CASE(name_shadowing) " uint256 variable;\n" " function f() { uint32 variable ; }" "}\n"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(name_references) @@ -153,7 +129,7 @@ BOOST_AUTO_TEST_CASE(name_references) " uint256 variable;\n" " function f(uint256 arg) returns (uint out) { f(variable); test; out; }" "}\n"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(undeclared_name) @@ -171,7 +147,7 @@ BOOST_AUTO_TEST_CASE(reference_to_later_declaration) " function g() { f(); }" " function f() { }" "}\n"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(struct_definition_directly_recursive) @@ -209,7 +185,7 @@ BOOST_AUTO_TEST_CASE(struct_definition_recursion_via_mapping) " mapping(uint => MyStructName1) x;\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(type_inference_smoke_test) @@ -217,7 +193,7 @@ BOOST_AUTO_TEST_CASE(type_inference_smoke_test) char const* text = "contract test {\n" " function f(uint256 arg1, uint32 arg2) returns (bool ret) { var x = arg1 + arg2 == 8; ret = x; }" "}\n"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(type_checking_return) @@ -225,7 +201,7 @@ BOOST_AUTO_TEST_CASE(type_checking_return) char const* text = "contract test {\n" " function f() returns (bool r) { return 1 >= 2; }" "}\n"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(type_checking_return_wrong_number) @@ -250,7 +226,7 @@ BOOST_AUTO_TEST_CASE(type_checking_function_call) " function f() returns (bool r) { return g(12, true) == 3; }\n" " function g(uint256 a, bool b) returns (uint256 r) { }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(type_conversion_for_comparison) @@ -258,7 +234,7 @@ BOOST_AUTO_TEST_CASE(type_conversion_for_comparison) char const* text = "contract test {\n" " function f() { uint32(2) == int64(2); }" "}\n"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(type_conversion_for_comparison_invalid) @@ -274,7 +250,7 @@ BOOST_AUTO_TEST_CASE(type_inference_explicit_conversion) char const* text = "contract test {\n" " function f() returns (int256 r) { var x = int256(uint32(2)); return x; }" "}\n"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(large_string_literal) @@ -292,7 +268,7 @@ BOOST_AUTO_TEST_CASE(balance) " uint256 x = address(0).balance;\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(balance_invalid) @@ -332,7 +308,7 @@ BOOST_AUTO_TEST_CASE(assignment_to_struct) " data = a;\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(returns_in_constructor) @@ -356,7 +332,7 @@ BOOST_AUTO_TEST_CASE(forward_function_reference) " if (First(2).fun() == true) return 1;\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(comparison_bitop_precedence) @@ -366,7 +342,7 @@ BOOST_AUTO_TEST_CASE(comparison_bitop_precedence) " return 1 & 2 == 8 & 9 && 1 ^ 2 < 4 | 6;\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(function_canonical_signature) @@ -423,7 +399,7 @@ BOOST_AUTO_TEST_CASE(inheritance_basic) function f() { baseMember = 7; } } )"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(inheritance_diamond_basic) @@ -436,7 +412,7 @@ BOOST_AUTO_TEST_CASE(inheritance_diamond_basic) function g() { f(); rootFunction(); } } )"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNamesWithChecks(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(cyclic_inheritance) @@ -492,7 +468,7 @@ BOOST_AUTO_TEST_CASE(complex_inheritance) contract B { function f() {} function g() returns (uint8 r) {} } contract C is A, B { } )"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(constructor_visibility) @@ -502,7 +478,7 @@ BOOST_AUTO_TEST_CASE(constructor_visibility) contract A { function A() { } } contract B is A { function f() { A x = A(0); } } )"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(overriding_constructor) @@ -512,7 +488,7 @@ BOOST_AUTO_TEST_CASE(overriding_constructor) contract A { function A() { } } contract B is A { function A() returns (uint8 r) {} } )"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(missing_base_constructor_arguments) @@ -541,7 +517,7 @@ BOOST_AUTO_TEST_CASE(implicit_derived_to_base_conversion) function f() { A a = B(1); } } )"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(implicit_base_to_derived_conversion) @@ -564,7 +540,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_invocation) modifier mod2(string7 a) { while (a == "1234567") _ } } )"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(invalid_function_modifier_type) @@ -587,7 +563,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_invocation_parameters) modifier mod2(string7 a) { while (a == "1234567") _ } } )"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(function_modifier_invocation_local_variables) @@ -598,7 +574,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_invocation_local_variables) modifier mod(uint a) { if (a > 0) _ } } )"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(legal_modifier_override) @@ -607,7 +583,7 @@ BOOST_AUTO_TEST_CASE(legal_modifier_override) contract A { modifier mod(uint a) {} } contract B is A { modifier mod(uint a) {} } )"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(illegal_modifier_override) @@ -661,7 +637,7 @@ BOOST_AUTO_TEST_CASE(state_variable_accessors) ASTPointer<SourceUnit> source; ContractDefinition const* contract; - BOOST_CHECK_NO_THROW(source = parseTextAndResolveNamesWithChecks(text)); + ETH_TEST_CHECK_NO_THROW(source = parseTextAndResolveNames(text), "Parsing and Resolving names failed"); BOOST_REQUIRE((contract = retrieveContract(source, 0)) != nullptr); FunctionTypePointer function = retrieveFunctionBySignature(contract, "foo()"); BOOST_REQUIRE(function && function->hasDeclaration()); @@ -711,7 +687,7 @@ BOOST_AUTO_TEST_CASE(private_state_variable) ASTPointer<SourceUnit> source; ContractDefinition const* contract; - BOOST_CHECK_NO_THROW(source = parseTextAndResolveNamesWithChecks(text)); + ETH_TEST_CHECK_NO_THROW(source = parseTextAndResolveNames(text), "Parsing and Resolving names failed"); BOOST_CHECK((contract = retrieveContract(source, 0)) != nullptr); FunctionTypePointer function; function = retrieveFunctionBySignature(contract, "foo()"); @@ -729,7 +705,7 @@ BOOST_AUTO_TEST_CASE(base_class_state_variable_accessor) "contract Child is Parent{\n" " function foo() returns (uint256) { return Parent.m_aMember; }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNamesWithChecks(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(base_class_state_variable_internal_member) @@ -740,7 +716,7 @@ BOOST_AUTO_TEST_CASE(base_class_state_variable_internal_member) "contract Child is Parent{\n" " function foo() returns (uint256) { return Parent.m_aMember; }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNamesWithChecks(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(state_variable_member_of_wrong_class1) @@ -780,7 +756,7 @@ BOOST_AUTO_TEST_CASE(fallback_function) function() { x = 2; } } )"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(fallback_function_with_arguments) @@ -817,7 +793,7 @@ BOOST_AUTO_TEST_CASE(fallback_function_inheritance) function() { x = 2; } } )"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(event) @@ -827,7 +803,7 @@ BOOST_AUTO_TEST_CASE(event) event e(uint indexed a, string3 indexed s, bool indexed b); function f() { e(2, "abc", true); } })"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(event_too_many_indexed) @@ -847,7 +823,7 @@ BOOST_AUTO_TEST_CASE(event_call) event e(uint a, string3 indexed s, bool indexed b); function f() { e(2, "abc", true); } })"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(event_inheritance) @@ -859,7 +835,7 @@ BOOST_AUTO_TEST_CASE(event_inheritance) contract c is base { function f() { e(2, "abc", true); } })"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(multiple_events_argument_clash) @@ -869,7 +845,7 @@ BOOST_AUTO_TEST_CASE(multiple_events_argument_clash) event e1(uint a, uint e1, uint e2); event e2(uint a, uint e1, uint e2); })"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(access_to_default_function_visibility) @@ -881,7 +857,7 @@ BOOST_AUTO_TEST_CASE(access_to_default_function_visibility) contract d { function g() { c(0).f(); } })"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(access_to_internal_function) @@ -917,7 +893,7 @@ BOOST_AUTO_TEST_CASE(access_to_internal_state_variable) contract d { function g() { c(0).a(); } })"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(error_count_in_named_args) @@ -963,7 +939,7 @@ BOOST_AUTO_TEST_CASE(empty_name_input_parameter) function f(uint){ } })"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(empty_name_return_parameter) @@ -973,7 +949,7 @@ BOOST_AUTO_TEST_CASE(empty_name_return_parameter) function f() returns(bool){ } })"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(empty_name_input_parameter_with_named_one) @@ -984,7 +960,7 @@ BOOST_AUTO_TEST_CASE(empty_name_input_parameter_with_named_one) return k; } })"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(empty_name_return_parameter_with_named_one) @@ -1014,7 +990,8 @@ BOOST_AUTO_TEST_CASE(overflow_caused_by_ether_units) } uint256 a; })"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(sourceCodeFine)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(sourceCodeFine), + "Parsing and Resolving names failed"); char const* sourceCode = R"( contract c { function c () @@ -1056,7 +1033,7 @@ BOOST_AUTO_TEST_CASE(enum_member_access) ActionChoices choices; } )"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNamesWithChecks(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(enum_invalid_member_access) @@ -1088,7 +1065,7 @@ BOOST_AUTO_TEST_CASE(enum_explicit_conversion_is_okay) uint64 b; } )"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNamesWithChecks(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(int_to_enum_explicit_conversion_is_okay) @@ -1105,7 +1082,7 @@ BOOST_AUTO_TEST_CASE(int_to_enum_explicit_conversion_is_okay) ActionChoices b; } )"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNamesWithChecks(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(enum_implicit_conversion_is_not_okay) @@ -1225,7 +1202,7 @@ BOOST_AUTO_TEST_CASE(test_for_bug_override_function_with_bytearray_type) function f(bytes _a) external returns (uint256 r) {r = 42;} } )"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNamesWithChecks(sourceCode)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(sourceCode), "Parsing and Name Resolving failed"); } BOOST_AUTO_TEST_CASE(array_with_nonconstant_length) @@ -1267,7 +1244,7 @@ BOOST_AUTO_TEST_CASE(array_copy_with_different_types_conversion_possible) uint8[] b; function f() { a = b; } })"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(array_copy_with_different_types_static_dynamic) @@ -1278,7 +1255,7 @@ BOOST_AUTO_TEST_CASE(array_copy_with_different_types_static_dynamic) uint8[80] b; function f() { a = b; } })"; - BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(array_copy_with_different_types_dynamic_static) diff --git a/SolidityNatspecJSON.cpp b/SolidityNatspecJSON.cpp index d1a443c2..edfe8986 100644 --- a/SolidityNatspecJSON.cpp +++ b/SolidityNatspecJSON.cpp @@ -20,7 +20,7 @@ * Unit tests for the solidity compiler JSON Interface output. */ -#include <boost/test/unit_test.hpp> +#include "TestHelper.h" #include <json/json.h> #include <libsolidity/CompilerStack.h> #include <libsolidity/Exceptions.h> @@ -43,15 +43,7 @@ public: bool _userDocumentation) { std::string generatedDocumentationString; - try - { - m_compilerStack.parse(_code); - } - catch(boost::exception const& _e) - { - auto msg = std::string("Parsing contract failed with: ") + boost::diagnostic_information(_e); - BOOST_FAIL(msg); - } + ETH_TEST_REQUIRE_NO_THROW(m_compilerStack.parse(_code), "Parsing failed"); if (_userDocumentation) generatedDocumentationString = m_compilerStack.getMetadata("", DocumentationType::NatspecUser); |