aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-06-29 01:30:13 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-07-01 03:47:33 +0800
commit0c92f5394456cb0818a53ceaab05199246b7a274 (patch)
treec13218e7467c03e31af6dc90a560d3f20dc7cf6a /test/libsolidity
parentd4fecc7b11586a108578a1834b634981bc854f91 (diff)
downloaddexon-solidity-0c92f5394456cb0818a53ceaab05199246b7a274.tar
dexon-solidity-0c92f5394456cb0818a53ceaab05199246b7a274.tar.gz
dexon-solidity-0c92f5394456cb0818a53ceaab05199246b7a274.tar.bz2
dexon-solidity-0c92f5394456cb0818a53ceaab05199246b7a274.tar.lz
dexon-solidity-0c92f5394456cb0818a53ceaab05199246b7a274.tar.xz
dexon-solidity-0c92f5394456cb0818a53ceaab05199246b7a274.tar.zst
dexon-solidity-0c92f5394456cb0818a53ceaab05199246b7a274.zip
Correctly check for jump warnings
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/InlineAssembly.cpp56
1 files changed, 29 insertions, 27 deletions
diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp
index 345ccfde..5197f649 100644
--- a/test/libsolidity/InlineAssembly.cpp
+++ b/test/libsolidity/InlineAssembly.cpp
@@ -67,23 +67,19 @@ boost::optional<Error> parseAndReturnFirstError(
BOOST_FAIL("Fatal error leaked.");
success = false;
}
- if (!success)
+ shared_ptr<Error const> error;
+ for (auto const& e: stack.errors())
{
- BOOST_REQUIRE_EQUAL(stack.errors().size(), 1);
- return *stack.errors().front();
- }
- else
- {
- // If success is true, there might still be an error in the assembly stage.
- if (_allowWarnings && Error::containsOnlyWarnings(stack.errors()))
- return {};
- else if (!stack.errors().empty())
- {
- if (!_allowWarnings)
- BOOST_CHECK_EQUAL(stack.errors().size(), 1);
- return *stack.errors().front();
- }
+ if (_allowWarnings && e->type() == Error::Type::Warning)
+ continue;
+ if (error)
+ BOOST_FAIL("Found more than one error.");
+ error = e;
}
+ if (!success)
+ BOOST_REQUIRE(error);
+ if (error)
+ return *error;
return {};
}
@@ -111,29 +107,35 @@ Error expectError(std::string const& _source, bool _assemble, bool _allowWarning
return *error;
}
-void parsePrintCompare(string const& _source)
+void parsePrintCompare(string const& _source, bool _canWarn = false)
{
AssemblyStack stack;
BOOST_REQUIRE(stack.parseAndAnalyze("", _source));
- BOOST_REQUIRE(stack.errors().empty());
+ if (_canWarn)
+ BOOST_REQUIRE(Error::containsOnlyWarnings(stack.errors()));
+ else
+ BOOST_REQUIRE(stack.errors().empty());
BOOST_CHECK_EQUAL(stack.print(), _source);
}
}
-#define CHECK_ERROR(text, assemble, typ, substring) \
+#define CHECK_ERROR(text, assemble, typ, substring, warnings) \
do \
{ \
- Error err = expectError((text), (assemble), false); \
+ Error err = expectError((text), (assemble), warnings); \
BOOST_CHECK(err.type() == (Error::Type::typ)); \
BOOST_CHECK(searchErrorMessage(err, (substring))); \
} while(0)
#define CHECK_PARSE_ERROR(text, type, substring) \
-CHECK_ERROR(text, false, type, substring)
+CHECK_ERROR(text, false, type, substring, false)
+
+#define CHECK_PARSE_WARNING(text, type, substring) \
+CHECK_ERROR(text, false, type, substring, false)
#define CHECK_ASSEMBLE_ERROR(text, type, substring) \
-CHECK_ERROR(text, true, type, substring)
+CHECK_ERROR(text, true, type, substring, false)
@@ -411,7 +413,7 @@ BOOST_AUTO_TEST_CASE(print_functional)
BOOST_AUTO_TEST_CASE(print_label)
{
- parsePrintCompare("{\n loop:\n jump(loop)\n}");
+ parsePrintCompare("{\n loop:\n jump(loop)\n}", true);
}
BOOST_AUTO_TEST_CASE(print_assignments)
@@ -515,7 +517,7 @@ BOOST_AUTO_TEST_CASE(imbalanced_stack)
BOOST_AUTO_TEST_CASE(error_tag)
{
- CHECK_ASSEMBLE_ERROR("{ jump(invalidJumpLabel) }", DeclarationError, "Identifier not found");
+ CHECK_ERROR("{ jump(invalidJumpLabel) }", true, DeclarationError, "Identifier not found", true);
}
BOOST_AUTO_TEST_CASE(designated_invalid_instruction)
@@ -632,10 +634,10 @@ BOOST_AUTO_TEST_CASE(create2)
BOOST_AUTO_TEST_CASE(jump_warning)
{
- CHECK_PARSE_ERROR("{ 1 jump }", Warning, "Jump instructions");
- CHECK_PARSE_ERROR("{ 1 2 jumpi }", Warning, "Jump instructions");
- CHECK_PARSE_ERROR("{ a: jump(a) }", Warning, "Jump instructions");
- CHECK_PARSE_ERROR("{ a: jumpi(a, 2) }", Warning, "Jump instructions");
+ CHECK_PARSE_WARNING("{ 1 jump }", Warning, "Jump instructions");
+ CHECK_PARSE_WARNING("{ 1 2 jumpi }", Warning, "Jump instructions");
+ CHECK_PARSE_WARNING("{ a: jump(a) }", Warning, "Jump instructions");
+ CHECK_PARSE_WARNING("{ a: jumpi(a, 2) }", Warning, "Jump instructions");
}
BOOST_AUTO_TEST_SUITE_END()