From 79bbe1e5d81947436b00febd7aa75246c47eabd6 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Fri, 6 Mar 2015 12:06:12 +0100 Subject: Move ETH_TEST() Macros to TestHelper.h - Also use them in Solidity Parser --- SolidityExpressionCompiler.cpp | 19 +----- SolidityInterface.cpp | 6 +- SolidityParser.cpp | 146 ++++++++++++++++++----------------------- TestHelper.h | 35 ++++++++++ 4 files changed, 104 insertions(+), 102 deletions(-) diff --git a/SolidityExpressionCompiler.cpp b/SolidityExpressionCompiler.cpp index e9d9a49e..7034085e 100644 --- a/SolidityExpressionCompiler.cpp +++ b/SolidityExpressionCompiler.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include "TestHelper.h" using namespace std; @@ -44,23 +44,6 @@ namespace test namespace { -// LTODO: Move to some more generic location. We really need it -/// Make sure that no Exception is thrown during testing. If one is thrown show its info. -/// @param _expression The expression for which to make sure no exceptions are thrown -/// @param _message A message to act as a prefix to the expression's error information -#define ETH_TEST_REQUIRE_NO_THROW(_expression, _message) \ - do { \ - try \ - { \ - _expression; \ - } \ - catch (boost::exception const& _e) \ - { \ - auto msg = std::string(_message) + boost::diagnostic_information(_e); \ - BOOST_FAIL(msg); \ - } \ - }while (0) - /// Helper class that extracts the first expression in an AST. class FirstExpressionExtractor: private ASTVisitor { diff --git a/SolidityInterface.cpp b/SolidityInterface.cpp index 35471518..ecab64c8 100644 --- a/SolidityInterface.cpp +++ b/SolidityInterface.cpp @@ -20,7 +20,7 @@ * Unit tests for generating source interfaces for Solidity contracts. */ -#include +#include "TestHelper.h" #include #include @@ -42,9 +42,9 @@ public: ContractDefinition const& checkInterface(string const& _code, string const& _contractName = "") { m_code = _code; - BOOST_REQUIRE_NO_THROW(m_compilerStack.parse(_code)); + ETH_TEST_REQUIRE_NO_THROW(m_compilerStack.parse(_code), "Parsing failed"); m_interface = m_compilerStack.getMetadata("", DocumentationType::ABISolidityInterface); - BOOST_REQUIRE_NO_THROW(m_reCompiler.parse(m_interface)); + ETH_TEST_REQUIRE_NO_THROW(m_reCompiler.parse(m_interface), "Interface parsing failed"); return m_reCompiler.getContractDefinition(_contractName); } diff --git a/SolidityParser.cpp b/SolidityParser.cpp index 28221cc6..88b86e63 100644 --- a/SolidityParser.cpp +++ b/SolidityParser.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include "TestHelper.h" using namespace std; @@ -50,22 +50,6 @@ ASTPointer parseText(std::string const& _source) return ASTPointer(); } -ASTPointer parseTextExplainError(std::string const& _source) -{ - try - { - return parseText(_source); - } - catch (Exception const& exception) - { - // LTODO: Print the error in a kind of a better way? - // In absence of CompilerStack we can't use SourceReferenceFormatter - cout << "Exception while parsing: " << diagnostic_information(exception); - // rethrow to signal test failure - throw exception; - } -} - static void checkFunctionNatspec(ASTPointer _function, std::string const& _expectedDoc) { @@ -84,7 +68,7 @@ BOOST_AUTO_TEST_CASE(smoke_test) char const* text = "contract test {\n" " uint256 stateVariable1;\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed."); } BOOST_AUTO_TEST_CASE(missing_variable_name_in_declaration) @@ -103,7 +87,7 @@ BOOST_AUTO_TEST_CASE(empty_function) " returns (int id)\n" " { }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed."); } BOOST_AUTO_TEST_CASE(no_function_params) @@ -112,7 +96,7 @@ BOOST_AUTO_TEST_CASE(no_function_params) " uint256 stateVar;\n" " function functionName() {}\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed."); } BOOST_AUTO_TEST_CASE(single_function_param) @@ -121,7 +105,7 @@ BOOST_AUTO_TEST_CASE(single_function_param) " uint256 stateVar;\n" " function functionName(hash hashin) returns (hash hashout) {}\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed."); } BOOST_AUTO_TEST_CASE(missing_parameter_name_in_named_args) @@ -151,9 +135,9 @@ BOOST_AUTO_TEST_CASE(function_natspec_documentation) " /// This is a test function\n" " function functionName(hash hashin) returns (hash hashout) {}\n" "}\n"; - BOOST_REQUIRE_NO_THROW(contract = parseText(text)); + ETH_TEST_REQUIRE_NO_THROW(contract = parseText(text), "Parsing failed"); auto functions = contract->getDefinedFunctions(); - BOOST_REQUIRE_NO_THROW(function = functions.at(0)); + ETH_TEST_REQUIRE_NO_THROW(function = functions.at(0), "Failed to retrieve function"); checkFunctionNatspec(function, "This is a test function"); } @@ -166,9 +150,9 @@ BOOST_AUTO_TEST_CASE(function_normal_comments) " // We won't see this comment\n" " function functionName(hash hashin) returns (hash hashout) {}\n" "}\n"; - BOOST_REQUIRE_NO_THROW(contract = parseText(text)); + ETH_TEST_REQUIRE_NO_THROW(contract = parseText(text), "Parsing failed"); auto functions = contract->getDefinedFunctions(); - BOOST_REQUIRE_NO_THROW(function = functions.at(0)); + ETH_TEST_REQUIRE_NO_THROW(function = functions.at(0), "Failed to retrieve function"); BOOST_CHECK_MESSAGE(function->getDocumentation() == nullptr, "Should not have gotten a Natspecc comment for this function"); } @@ -188,20 +172,20 @@ BOOST_AUTO_TEST_CASE(multiple_functions_natspec_documentation) " /// This is test function 4\n" " function functionName4(hash hashin) returns (hash hashout) {}\n" "}\n"; - BOOST_REQUIRE_NO_THROW(contract = parseText(text)); + ETH_TEST_REQUIRE_NO_THROW(contract = parseText(text), "Parsing failed"); auto functions = contract->getDefinedFunctions(); - BOOST_REQUIRE_NO_THROW(function = functions.at(0)); + ETH_TEST_REQUIRE_NO_THROW(function = functions.at(0), "Failed to retrieve function"); checkFunctionNatspec(function, "This is test function 1"); - BOOST_REQUIRE_NO_THROW(function = functions.at(1)); + ETH_TEST_REQUIRE_NO_THROW(function = functions.at(1), "Failed to retrieve function"); checkFunctionNatspec(function, "This is test function 2"); - BOOST_REQUIRE_NO_THROW(function = functions.at(2)); + ETH_TEST_REQUIRE_NO_THROW(function = functions.at(2), "Failed to retrieve function"); BOOST_CHECK_MESSAGE(function->getDocumentation() == nullptr, "Should not have gotten natspec comment for functionName3()"); - BOOST_REQUIRE_NO_THROW(function = functions.at(3)); + ETH_TEST_REQUIRE_NO_THROW(function = functions.at(3), "Failed to retrieve function"); checkFunctionNatspec(function, "This is test function 4"); } @@ -215,10 +199,10 @@ BOOST_AUTO_TEST_CASE(multiline_function_documentation) " /// and it has 2 lines\n" " function functionName1(hash hashin) returns (hash hashout) {}\n" "}\n"; - BOOST_REQUIRE_NO_THROW(contract = parseText(text)); + ETH_TEST_REQUIRE_NO_THROW(contract = parseText(text), "Parsing failed"); auto functions = contract->getDefinedFunctions(); - BOOST_REQUIRE_NO_THROW(function = functions.at(0)); + ETH_TEST_REQUIRE_NO_THROW(function = functions.at(0), "Failed to retrieve function"); checkFunctionNatspec(function, "This is a test function\n" " and it has 2 lines"); } @@ -240,13 +224,13 @@ BOOST_AUTO_TEST_CASE(natspec_comment_in_function_body) " /// and it has 2 lines\n" " function fun(hash hashin) returns (hash hashout) {}\n" "}\n"; - BOOST_REQUIRE_NO_THROW(contract = parseText(text)); + ETH_TEST_REQUIRE_NO_THROW(contract = parseText(text), "Parsing failed"); auto functions = contract->getDefinedFunctions(); - BOOST_REQUIRE_NO_THROW(function = functions.at(0)); + ETH_TEST_REQUIRE_NO_THROW(function = functions.at(0), "Failed to retrieve function"); checkFunctionNatspec(function, "fun1 description"); - BOOST_REQUIRE_NO_THROW(function = functions.at(1)); + ETH_TEST_REQUIRE_NO_THROW(function = functions.at(1), "Failed to retrieve function"); checkFunctionNatspec(function, "This is a test function\n" " and it has 2 lines"); } @@ -266,10 +250,10 @@ BOOST_AUTO_TEST_CASE(natspec_docstring_between_keyword_and_signature) " string name = \"Solidity\";" " }\n" "}\n"; - BOOST_REQUIRE_NO_THROW(contract = parseText(text)); + ETH_TEST_REQUIRE_NO_THROW(contract = parseText(text), "Parsing failed"); auto functions = contract->getDefinedFunctions(); - BOOST_REQUIRE_NO_THROW(function = functions.at(0)); + ETH_TEST_REQUIRE_NO_THROW(function = functions.at(0), "Failed to retrieve function"); BOOST_CHECK_MESSAGE(!function->getDocumentation(), "Shouldn't get natspec docstring for this function"); } @@ -289,10 +273,10 @@ BOOST_AUTO_TEST_CASE(natspec_docstring_after_signature) " string name = \"Solidity\";" " }\n" "}\n"; - BOOST_REQUIRE_NO_THROW(contract = parseText(text)); + ETH_TEST_REQUIRE_NO_THROW(contract = parseText(text), "Parsing failed"); auto functions = contract->getDefinedFunctions(); - BOOST_REQUIRE_NO_THROW(function = functions.at(0)); + ETH_TEST_REQUIRE_NO_THROW(function = functions.at(0), "Failed to retrieve function"); BOOST_CHECK_MESSAGE(!function->getDocumentation(), "Shouldn't get natspec docstring for this function"); } @@ -306,7 +290,7 @@ BOOST_AUTO_TEST_CASE(struct_definition) " uint256 count;\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(mapping) @@ -314,7 +298,7 @@ BOOST_AUTO_TEST_CASE(mapping) char const* text = "contract test {\n" " mapping(address => string) names;\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(mapping_in_struct) @@ -326,7 +310,7 @@ BOOST_AUTO_TEST_CASE(mapping_in_struct) " mapping(hash => test_struct) self_reference;\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(mapping_to_mapping_in_struct) @@ -337,7 +321,7 @@ BOOST_AUTO_TEST_CASE(mapping_to_mapping_in_struct) " mapping (uint64 => mapping (hash => uint)) complex_mapping;\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(variable_definition) @@ -350,7 +334,7 @@ BOOST_AUTO_TEST_CASE(variable_definition) " customtype varname;\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(variable_definition_with_initialization) @@ -364,7 +348,7 @@ BOOST_AUTO_TEST_CASE(variable_definition_with_initialization) " customtype varname;\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(variable_definition_in_function_parameter) @@ -408,7 +392,7 @@ BOOST_AUTO_TEST_CASE(operator_expression) " uint256 x = (1 + 4) || false && (1 - 12) + -9;\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(complex_expression) @@ -418,7 +402,7 @@ BOOST_AUTO_TEST_CASE(complex_expression) " uint256 x = (1 + 4).member(++67)[a/=9] || true;\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(exp_expression) @@ -429,7 +413,7 @@ BOOST_AUTO_TEST_CASE(exp_expression) uint256 x = 3 ** a; } })"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(while_loop) @@ -439,7 +423,7 @@ BOOST_AUTO_TEST_CASE(while_loop) " while (true) { uint256 x = 1; break; continue; } x = 9;\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(for_loop_vardef_initexpr) @@ -450,7 +434,7 @@ BOOST_AUTO_TEST_CASE(for_loop_vardef_initexpr) " { uint256 x = i; break; continue; }\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseTextExplainError(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(for_loop_simple_initexpr) @@ -462,7 +446,7 @@ BOOST_AUTO_TEST_CASE(for_loop_simple_initexpr) " { uint256 x = i; break; continue; }\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseTextExplainError(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(for_loop_simple_noexpr) @@ -474,7 +458,7 @@ BOOST_AUTO_TEST_CASE(for_loop_simple_noexpr) " { uint256 x = i; break; continue; }\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseTextExplainError(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(for_loop_single_stmt_body) @@ -486,7 +470,7 @@ BOOST_AUTO_TEST_CASE(for_loop_single_stmt_body) " continue;\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseTextExplainError(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(if_statement) @@ -496,7 +480,7 @@ BOOST_AUTO_TEST_CASE(if_statement) " if (a >= 8) return 2; else { var b = 7; }\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(else_if_statement) @@ -506,7 +490,7 @@ BOOST_AUTO_TEST_CASE(else_if_statement) " if (a < 0) b = 0x67; else if (a == 0) b = 0x12; else b = 0x78;\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(statement_starting_with_type_conversion) @@ -518,7 +502,7 @@ BOOST_AUTO_TEST_CASE(statement_starting_with_type_conversion) " uint64[](3);\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(type_conversion_to_dynamic_array) @@ -528,7 +512,7 @@ BOOST_AUTO_TEST_CASE(type_conversion_to_dynamic_array) " var x = uint64[](3);\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(import_directive) @@ -539,7 +523,7 @@ BOOST_AUTO_TEST_CASE(import_directive) " uint64(2);\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(multiple_contracts) @@ -554,7 +538,7 @@ BOOST_AUTO_TEST_CASE(multiple_contracts) " uint64(2);\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(multiple_contracts_and_imports) @@ -572,7 +556,7 @@ BOOST_AUTO_TEST_CASE(multiple_contracts_and_imports) " }\n" "}\n" "import \"ghi\";\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(contract_inheritance) @@ -587,7 +571,7 @@ BOOST_AUTO_TEST_CASE(contract_inheritance) " uint64(2);\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(contract_multiple_inheritance) @@ -602,7 +586,7 @@ BOOST_AUTO_TEST_CASE(contract_multiple_inheritance) " uint64(2);\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(contract_multiple_inheritance_with_arguments) @@ -617,7 +601,7 @@ BOOST_AUTO_TEST_CASE(contract_multiple_inheritance_with_arguments) " uint64(2);\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(placeholder_in_function_context) @@ -628,7 +612,7 @@ BOOST_AUTO_TEST_CASE(placeholder_in_function_context) " return _ + 1;" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(modifier) @@ -636,7 +620,7 @@ BOOST_AUTO_TEST_CASE(modifier) char const* text = "contract c {\n" " modifier mod { if (msg.sender == 0) _ }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(modifier_arguments) @@ -644,7 +628,7 @@ BOOST_AUTO_TEST_CASE(modifier_arguments) char const* text = "contract c {\n" " modifier mod(uint a) { if (msg.sender == a) _ }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(modifier_invocation) @@ -654,7 +638,7 @@ BOOST_AUTO_TEST_CASE(modifier_invocation) " modifier mod2 { if (msg.sender == 2) _ }\n" " function f() mod1(7) mod2 { }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(fallback_function) @@ -662,7 +646,7 @@ BOOST_AUTO_TEST_CASE(fallback_function) char const* text = "contract c {\n" " function() { }\n" "}\n"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(event) @@ -671,7 +655,7 @@ BOOST_AUTO_TEST_CASE(event) contract c { event e(); })"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(event_arguments) @@ -680,7 +664,7 @@ BOOST_AUTO_TEST_CASE(event_arguments) contract c { event e(uint a, string32 s); })"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(event_arguments_indexed) @@ -689,7 +673,7 @@ BOOST_AUTO_TEST_CASE(event_arguments_indexed) contract c { event e(uint a, string32 indexed s, bool indexed b); })"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(visibility_specifiers) @@ -705,7 +689,7 @@ BOOST_AUTO_TEST_CASE(visibility_specifiers) function f_public() public {} function f_internal() internal {} })"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(multiple_visibility_specifiers) @@ -733,7 +717,7 @@ BOOST_AUTO_TEST_CASE(literal_constants_with_ether_subdenominations) uint256 c; uint256 d; })"; - BOOST_CHECK_NO_THROW(parseTextExplainError(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(literal_constants_with_ether_subdenominations_in_expressions) @@ -746,7 +730,7 @@ BOOST_AUTO_TEST_CASE(literal_constants_with_ether_subdenominations_in_expression } uint256 a; })"; - BOOST_CHECK_NO_THROW(parseTextExplainError(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(enum_valid_declaration) @@ -760,7 +744,7 @@ BOOST_AUTO_TEST_CASE(enum_valid_declaration) } uint256 a; })"; - BOOST_CHECK_NO_THROW(parseTextExplainError(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(empty_enum_declaration) @@ -769,7 +753,7 @@ BOOST_AUTO_TEST_CASE(empty_enum_declaration) contract c { enum foo { } })"; - BOOST_CHECK_NO_THROW(parseTextExplainError(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(malformed_enum_declaration) @@ -787,7 +771,7 @@ BOOST_AUTO_TEST_CASE(external_function) contract c { function x() external {} })"; - BOOST_CHECK_NO_THROW(parseTextExplainError(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(external_variable) @@ -808,7 +792,7 @@ BOOST_AUTO_TEST_CASE(arrays_in_storage) struct x { uint[2**20] b; y[0] c; } struct y { uint d; mapping(uint=>x)[] e; } })"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(arrays_in_events) @@ -817,7 +801,7 @@ BOOST_AUTO_TEST_CASE(arrays_in_events) contract c { event e(uint[10] a, string7[8] indexed b, c[3] x); })"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(arrays_in_expressions) @@ -826,7 +810,7 @@ BOOST_AUTO_TEST_CASE(arrays_in_expressions) contract c { function f() { c[10] a = 7; uint8[10 * 2] x; } })"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_CASE(multi_arrays) @@ -835,7 +819,7 @@ BOOST_AUTO_TEST_CASE(multi_arrays) contract c { mapping(uint => mapping(uint => int8)[8][][9])[] x; })"; - BOOST_CHECK_NO_THROW(parseText(text)); + ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } BOOST_AUTO_TEST_SUITE_END() diff --git a/TestHelper.h b/TestHelper.h index 849f822b..37c90add 100644 --- a/TestHelper.h +++ b/TestHelper.h @@ -44,6 +44,41 @@ void connectClients(Client& c1, Client& c2); namespace test { +/// Make sure that no Exception is thrown during testing. If one is thrown show its info and fail the test. +/// Our version of BOOST_REQUIRE_NO_THROW() +/// @param _expression The expression for which to make sure no exceptions are thrown +/// @param _message A message to act as a prefix to the expression's error information +#define ETH_TEST_REQUIRE_NO_THROW(_expression, _message) \ + do { \ + try \ + { \ + _expression; \ + } \ + catch (boost::exception const& _e) \ + { \ + auto msg = std::string(_message) + boost::diagnostic_information(_e); \ + BOOST_FAIL(msg); \ + } \ + }while (0) + +/// Check if an Exception is thrown during testing. If one is thrown show its info and continue the test +/// Our version of BOOST_CHECK_NO_THROW() +/// @param _expression The expression for which to make sure no exceptions are thrown +/// @param _message A message to act as a prefix to the expression's error information +#define ETH_TEST_CHECK_NO_THROW(_expression, _message) \ + do { \ + try \ + { \ + _expression; \ + } \ + catch (boost::exception const& _e) \ + { \ + auto msg = std::string(_message) + boost::diagnostic_information(_e); \ + BOOST_MESSAGE(msg); \ + } \ + }while (0) + + class ImportTest { public: -- cgit