Add tests

This commit is contained in:
chriseth 2016-11-15 09:16:33 +01:00
parent dad33f80dd
commit dce80911e1

View File

@ -41,7 +41,7 @@ namespace test
namespace
{
bool successParse(std::string const& _source, bool _assemble = false)
bool successParse(std::string const& _source, bool _assemble = false, bool _allowWarnings = true)
{
assembly::InlineAssemblyStack stack;
try
@ -51,8 +51,9 @@ bool successParse(std::string const& _source, bool _assemble = false)
if (_assemble)
{
stack.assemble();
if (!stack.errors().empty() && !Error::containsOnlyWarnings(stack.errors()))
return false;
if (!stack.errors().empty())
if (!_allowWarnings || !Error::containsOnlyWarnings(stack.errors()))
return false;
}
}
catch (FatalError const&)
@ -67,9 +68,9 @@ bool successParse(std::string const& _source, bool _assemble = false)
return true;
}
bool successAssemble(string const& _source)
bool successAssemble(string const& _source, bool _allowWarnings = true)
{
return successParse(_source, true);
return successParse(_source, true, _allowWarnings);
}
}
@ -169,6 +170,13 @@ BOOST_AUTO_TEST_CASE(magic_variables)
BOOST_CHECK(successAssemble("{ let ecrecover := 1 ecrecover }"));
}
BOOST_AUTO_TEST_CASE(imbalanced_stack)
{
BOOST_CHECK(successAssemble("{ 1 2 mul pop }", false));
BOOST_CHECK(!successAssemble("{ 1 }", false));
BOOST_CHECK(successAssemble("{ let x := 4 7 add }", false));
}
BOOST_AUTO_TEST_SUITE_END()
}