mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
More verbose error messages.
This commit is contained in:
parent
9d8edb46f2
commit
08effa0af5
@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
#include <libsolidity/ast/AST.h>
|
#include <libsolidity/ast/AST.h>
|
||||||
|
|
||||||
|
#include <libsolidity/parsing/Scanner.h>
|
||||||
|
|
||||||
#include <libdevcore/SHA3.h>
|
#include <libdevcore/SHA3.h>
|
||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
@ -46,8 +48,7 @@ AnalysisFramework::parseAnalyseAndReturnError(
|
|||||||
m_compiler.addSource("", _insertVersionPragma ? "pragma solidity >=0.0;\n" + _source : _source);
|
m_compiler.addSource("", _insertVersionPragma ? "pragma solidity >=0.0;\n" + _source : _source);
|
||||||
if (!m_compiler.parse())
|
if (!m_compiler.parse())
|
||||||
{
|
{
|
||||||
printErrors();
|
BOOST_ERROR("Parsing contract failed in analysis test suite:" + formatErrors());
|
||||||
BOOST_ERROR("Parsing contract failed in analysis test suite.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_compiler.analyze();
|
m_compiler.analyze();
|
||||||
@ -73,8 +74,7 @@ AnalysisFramework::parseAnalyseAndReturnError(
|
|||||||
{
|
{
|
||||||
if (firstError && !_allowMultipleErrors)
|
if (firstError && !_allowMultipleErrors)
|
||||||
{
|
{
|
||||||
printErrors();
|
BOOST_FAIL("Multiple errors found: " + formatErrors());
|
||||||
BOOST_FAIL("Multiple errors found.");
|
|
||||||
}
|
}
|
||||||
if (!firstError)
|
if (!firstError)
|
||||||
firstError = currentError;
|
firstError = currentError;
|
||||||
@ -88,7 +88,10 @@ SourceUnit const* AnalysisFramework::parseAndAnalyse(string const& _source)
|
|||||||
{
|
{
|
||||||
auto sourceAndError = parseAnalyseAndReturnError(_source);
|
auto sourceAndError = parseAnalyseAndReturnError(_source);
|
||||||
BOOST_REQUIRE(!!sourceAndError.first);
|
BOOST_REQUIRE(!!sourceAndError.first);
|
||||||
BOOST_REQUIRE(!sourceAndError.second);
|
string message;
|
||||||
|
if (sourceAndError.second)
|
||||||
|
message = "Unexpected error: " + formatError(*sourceAndError.second);
|
||||||
|
BOOST_REQUIRE_MESSAGE(!sourceAndError.second, message);
|
||||||
return sourceAndError.first;
|
return sourceAndError.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,17 +104,23 @@ Error AnalysisFramework::expectError(std::string const& _source, bool _warning,
|
|||||||
{
|
{
|
||||||
auto sourceAndError = parseAnalyseAndReturnError(_source, _warning, true, _allowMultiple);
|
auto sourceAndError = parseAnalyseAndReturnError(_source, _warning, true, _allowMultiple);
|
||||||
BOOST_REQUIRE(!!sourceAndError.second);
|
BOOST_REQUIRE(!!sourceAndError.second);
|
||||||
BOOST_REQUIRE(!!sourceAndError.first);
|
BOOST_REQUIRE_MESSAGE(!!sourceAndError.first, "Expected error, but no error happened.");
|
||||||
return *sourceAndError.second;
|
return *sourceAndError.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnalysisFramework::printErrors()
|
string AnalysisFramework::formatErrors()
|
||||||
{
|
{
|
||||||
|
string message;
|
||||||
for (auto const& error: m_compiler.errors())
|
for (auto const& error: m_compiler.errors())
|
||||||
SourceReferenceFormatter::printExceptionInformation(
|
message += formatError(*error);
|
||||||
std::cerr,
|
return message;
|
||||||
*error,
|
}
|
||||||
(error->type() == Error::Type::Warning) ? "Warning" : "Error",
|
|
||||||
|
string AnalysisFramework::formatError(Error const& _error)
|
||||||
|
{
|
||||||
|
return SourceReferenceFormatter::formatExceptionInformation(
|
||||||
|
_error,
|
||||||
|
(_error.type() == Error::Type::Warning) ? "Warning" : "Error",
|
||||||
[&](std::string const& _sourceName) -> solidity::Scanner const& { return m_compiler.scanner(_sourceName); }
|
[&](std::string const& _sourceName) -> solidity::Scanner const& { return m_compiler.scanner(_sourceName); }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,8 @@ protected:
|
|||||||
bool success(std::string const& _source);
|
bool success(std::string const& _source);
|
||||||
Error expectError(std::string const& _source, bool _warning = false, bool _allowMultiple = false);
|
Error expectError(std::string const& _source, bool _warning = false, bool _allowMultiple = false);
|
||||||
|
|
||||||
void printErrors();
|
std::string formatErrors();
|
||||||
|
std::string formatError(Error const& _error);
|
||||||
|
|
||||||
static ContractDefinition const* retrieveContractByName(SourceUnit const& _source, std::string const& _name);
|
static ContractDefinition const* retrieveContractByName(SourceUnit const& _source, std::string const& _name);
|
||||||
static FunctionTypePointer retrieveFunctionBySignature(
|
static FunctionTypePointer retrieveFunctionBySignature(
|
||||||
@ -105,7 +106,10 @@ CHECK_ERROR_OR_WARNING(text, Warning, substring, true, true)
|
|||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
auto sourceAndError = parseAnalyseAndReturnError((text), true); \
|
auto sourceAndError = parseAnalyseAndReturnError((text), true); \
|
||||||
BOOST_CHECK(sourceAndError.second == nullptr); \
|
std::string message; \
|
||||||
|
if (sourceAndError.second) \
|
||||||
|
message = formatError(*sourceAndError.second); \
|
||||||
|
BOOST_CHECK_MESSAGE(!sourceAndError.second, message); \
|
||||||
} \
|
} \
|
||||||
while(0)
|
while(0)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user