diff options
Diffstat (limited to 'test')
-rwxr-xr-x | test/externalTests.sh | 47 | ||||
-rw-r--r-- | test/libsolidity/Assembly.cpp | 54 | ||||
-rw-r--r-- | test/libsolidity/InlineAssembly.cpp | 8 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 14 | ||||
-rw-r--r-- | test/libsolidity/StandardCompiler.cpp | 30 |
5 files changed, 93 insertions, 60 deletions
diff --git a/test/externalTests.sh b/test/externalTests.sh index 1cc0af19..11972eae 100755 --- a/test/externalTests.sh +++ b/test/externalTests.sh @@ -44,53 +44,6 @@ DIR=$(mktemp -d) npm install find . -name soljson.js -exec cp "$SOLJSON" {} \; - # This is a patch that lets truffle ignore the pre-release compiler warning - cat > truffle.patch <<EOF ---- node_modules/truffle/build/cli.bundled.js 2017-11-27 16:56:47.114830112 +0100 -+++ /tmp/patched 2017-11-27 16:52:31.887064115 +0100 -@@ -313846,9 +313846,12 @@ - }); - - output = JSON.parse(output); -+ var errors = output.errors.filter(function(solidity_error) { -+ return solidity_error.formattedMessage.indexOf("pre-release compiler") < 0; -+ }); - -- if (output.errors) { -- throw new CompileError(output.errors[0].formattedMessage); -+ if (errors) { -+ throw new CompileError(errors[0].formattedMessage); - } - - return { -@@ -313901,9 +313904,13 @@ - return {error: importErrorKey}; - }); - -- output = JSON.parse(output); -+ output = JSON.parse(output); -+ -+ var errors = output.errors.filter(function(solidity_error) { -+ return solidity_error.formattedMessage.indexOf("pre-release compiler") < 0; -+ }); - -- var nonImportErrors = output.errors.filter(function(solidity_error) { -+ var nonImportErrors = errors.filter(function(solidity_error) { - // If the import error key is not found, we must not have an import error. - // This means we have a *different* parsing error which we should show to the user. - // Note: solc can return multiple parsing errors at once. -@@ -313917,7 +313924,7 @@ - - // Now, all errors must be import errors. - // Filter out our forced import, then get the import paths of the rest. -- var imports = output.errors.filter(function(solidity_error) { -+ var imports = errors.filter(function(solidity_error) { - return solidity_error.message.indexOf(failingImportFileName) < 0; - }).map(function(solidity_error) { - var matches = solidity_error.formattedMessage.match(/import[^'"]+("|')([^'"]+)("|');/); -EOF - - patch node_modules/truffle/build/cli.bundled.js ./truffle.patch npm run test ) rm -rf "$DIR" diff --git a/test/libsolidity/Assembly.cpp b/test/libsolidity/Assembly.cpp index 358d3c72..59af6d41 100644 --- a/test/libsolidity/Assembly.cpp +++ b/test/libsolidity/Assembly.cpp @@ -86,23 +86,59 @@ eth::AssemblyItems compileContract(const string& _sourceCode) return AssemblyItems(); } +void printAssemblyLocations(AssemblyItems const& _items) +{ + auto printRepeated = [](SourceLocation const& _loc, size_t _repetitions) + { + cout << + "\t\tvector<SourceLocation>(" << + _repetitions << + ", SourceLocation(" << + _loc.start << + ", " << + _loc.end << + ", make_shared<string>(\"" << + *_loc.sourceName << + "\"))) +" << endl; + }; + + vector<SourceLocation> locations; + for (auto const& item: _items) + locations.push_back(item.location()); + size_t repetitions = 0; + SourceLocation const* previousLoc = nullptr; + for (size_t i = 0; i < locations.size(); ++i) + { + SourceLocation& loc = locations[i]; + if (previousLoc && *previousLoc == loc) + repetitions++; + else + { + if (previousLoc) + printRepeated(*previousLoc, repetitions); + previousLoc = &loc; + repetitions = 1; + } + } + if (previousLoc) + printRepeated(*previousLoc, repetitions); +} + void checkAssemblyLocations(AssemblyItems const& _items, vector<SourceLocation> const& _locations) { BOOST_CHECK_EQUAL(_items.size(), _locations.size()); for (size_t i = 0; i < min(_items.size(), _locations.size()); ++i) { - BOOST_CHECK_MESSAGE( - _items[i].location() == _locations[i], - "Location mismatch for assembly item " + to_string(i) + ". Found: " + - (_items[i].location().sourceName ? *_items[i].location().sourceName + ":" : "(null source name)") + - to_string(_items[i].location().start) + "-" + - to_string(_items[i].location().end) + ", expected: " + - (_locations[i].sourceName ? *_locations[i].sourceName + ":" : "(null source name)") + - to_string(_locations[i].start) + "-" + - to_string(_locations[i].end)); + if (_items[i].location() != _locations[i]) + { + BOOST_CHECK_MESSAGE(false, "Location mismatch for item " + to_string(i) + ". Found the following locations:"); + printAssemblyLocations(_items); + return; + } } } + } // end anonymous namespace BOOST_AUTO_TEST_SUITE(Assembly) diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index 82bafd49..94e02b8f 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -266,7 +266,7 @@ BOOST_AUTO_TEST_CASE(if_statement_scope) BOOST_AUTO_TEST_CASE(if_statement_invalid) { - CHECK_PARSE_ERROR("{ if calldatasize {}", ParserError, "Instructions are not supported as conditions for if"); + CHECK_PARSE_ERROR("{ if mload {} }", ParserError, "Expected token \"(\""); BOOST_CHECK("{ if calldatasize() {}"); CHECK_PARSE_ERROR("{ if mstore(1, 1) {} }", ParserError, "Instruction \"mstore\" not allowed in this context"); CHECK_PARSE_ERROR("{ if 32 let x := 3 }", ParserError, "Expected token LBrace"); @@ -296,7 +296,7 @@ BOOST_AUTO_TEST_CASE(switch_duplicate_case) BOOST_AUTO_TEST_CASE(switch_invalid_expression) { CHECK_PARSE_ERROR("{ switch {} default {} }", ParserError, "Literal, identifier or instruction expected."); - CHECK_PARSE_ERROR("{ switch calldatasize default {} }", ParserError, "Instructions are not supported as expressions for switch"); + CHECK_PARSE_ERROR("{ switch mload default {} }", ParserError, "Expected token \"(\""); CHECK_PARSE_ERROR("{ switch mstore(1, 1) default {} }", ParserError, "Instruction \"mstore\" not allowed in this context"); } @@ -332,7 +332,7 @@ BOOST_AUTO_TEST_CASE(for_invalid_expression) CHECK_PARSE_ERROR("{ for 1 1 {} {} }", ParserError, "Expected token LBrace got 'Number'"); CHECK_PARSE_ERROR("{ for {} 1 1 {} }", ParserError, "Expected token LBrace got 'Number'"); CHECK_PARSE_ERROR("{ for {} 1 {} 1 }", ParserError, "Expected token LBrace got 'Number'"); - CHECK_PARSE_ERROR("{ for {} calldatasize {} {} }", ParserError, "Instructions are not supported as conditions for the for statement."); + CHECK_PARSE_ERROR("{ for {} mload {} {} }", ParserError, "Expected token \"(\""); CHECK_PARSE_ERROR("{ for {} mstore(1, 1) {} {} }", ParserError, "Instruction \"mstore\" not allowed in this context"); } @@ -540,7 +540,7 @@ BOOST_AUTO_TEST_CASE(function_calls) function g(a, b, c) { } - g(1, mul(2, address), f(mul(2, caller))) + g(1, mul(2, address()), f(mul(2, caller()))) y() })"; boost::replace_all(source, "\t", " "); diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 8f58dcb1..eb6a440e 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -3608,6 +3608,20 @@ BOOST_AUTO_TEST_CASE(invalid_args_creating_memory_array) CHECK_ERROR(text, TypeError, "Wrong argument count for function call: 0 arguments given but expected 1."); } +BOOST_AUTO_TEST_CASE(invalid_args_creating_struct) +{ + char const* text = R"( + contract C { + struct S { uint a; uint b; } + + function f() public { + var s = S({a: 1}); + } + } + )"; + CHECK_ERROR(text, TypeError, "Wrong argument count for struct constructor: 1 arguments given but expected 2."); +} + BOOST_AUTO_TEST_CASE(function_overload_array_type) { char const* text = R"( diff --git a/test/libsolidity/StandardCompiler.cpp b/test/libsolidity/StandardCompiler.cpp index dd0478c5..fa0f1e59 100644 --- a/test/libsolidity/StandardCompiler.cpp +++ b/test/libsolidity/StandardCompiler.cpp @@ -451,6 +451,36 @@ BOOST_AUTO_TEST_CASE(output_selection_dependent_contract_with_import) BOOST_CHECK_EQUAL(dev::jsonCompactPrint(contract["abi"]), "[{\"constant\":false,\"inputs\":[],\"name\":\"f\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"); } +BOOST_AUTO_TEST_CASE(filename_with_colon) +{ + char const* input = R"( + { + "language": "Solidity", + "settings": { + "outputSelection": { + "http://github.com/ethereum/solidity/std/StandardToken.sol": { + "A": [ + "abi" + ] + } + } + }, + "sources": { + "http://github.com/ethereum/solidity/std/StandardToken.sol": { + "content": "contract A { }" + } + } + } + )"; + Json::Value result = compile(input); + BOOST_CHECK(containsAtMostWarnings(result)); + Json::Value contract = getContractResult(result, "http://github.com/ethereum/solidity/std/StandardToken.sol", "A"); + BOOST_CHECK(contract.isObject()); + BOOST_CHECK(contract["abi"].isArray()); + BOOST_CHECK_EQUAL(dev::jsonCompactPrint(contract["abi"]), "[]"); +} + + BOOST_AUTO_TEST_SUITE_END() } |