aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-09-28 16:59:15 +0800
committerchriseth <chris@ethereum.org>2017-09-29 18:05:45 +0800
commit08effa0af54647971415cb66dc9181afad9642ee (patch)
tree84b91fd8fa32a40da6715f09806116c09976b028 /test/libsolidity
parent9d8edb46f24517dc5a0dbc0b496caad75cf39ca3 (diff)
downloaddexon-solidity-08effa0af54647971415cb66dc9181afad9642ee.tar.gz
dexon-solidity-08effa0af54647971415cb66dc9181afad9642ee.tar.zst
dexon-solidity-08effa0af54647971415cb66dc9181afad9642ee.zip
More verbose error messages.
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/AnalysisFramework.cpp31
-rw-r--r--test/libsolidity/AnalysisFramework.h8
2 files changed, 26 insertions, 13 deletions
diff --git a/test/libsolidity/AnalysisFramework.cpp b/test/libsolidity/AnalysisFramework.cpp
index 67cc027e..3bdc40a0 100644
--- a/test/libsolidity/AnalysisFramework.cpp
+++ b/test/libsolidity/AnalysisFramework.cpp
@@ -25,6 +25,8 @@
#include <libsolidity/ast/AST.h>
+#include <libsolidity/parsing/Scanner.h>
+
#include <libdevcore/SHA3.h>
#include <boost/test/unit_test.hpp>
@@ -46,8 +48,7 @@ AnalysisFramework::parseAnalyseAndReturnError(
m_compiler.addSource("", _insertVersionPragma ? "pragma solidity >=0.0;\n" + _source : _source);
if (!m_compiler.parse())
{
- printErrors();
- BOOST_ERROR("Parsing contract failed in analysis test suite.");
+ BOOST_ERROR("Parsing contract failed in analysis test suite:" + formatErrors());
}
m_compiler.analyze();
@@ -73,8 +74,7 @@ AnalysisFramework::parseAnalyseAndReturnError(
{
if (firstError && !_allowMultipleErrors)
{
- printErrors();
- BOOST_FAIL("Multiple errors found.");
+ BOOST_FAIL("Multiple errors found: " + formatErrors());
}
if (!firstError)
firstError = currentError;
@@ -88,7 +88,10 @@ SourceUnit const* AnalysisFramework::parseAndAnalyse(string const& _source)
{
auto sourceAndError = parseAnalyseAndReturnError(_source);
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;
}
@@ -101,17 +104,23 @@ Error AnalysisFramework::expectError(std::string const& _source, bool _warning,
{
auto sourceAndError = parseAnalyseAndReturnError(_source, _warning, true, _allowMultiple);
BOOST_REQUIRE(!!sourceAndError.second);
- BOOST_REQUIRE(!!sourceAndError.first);
+ BOOST_REQUIRE_MESSAGE(!!sourceAndError.first, "Expected error, but no error happened.");
return *sourceAndError.second;
}
-void AnalysisFramework::printErrors()
+string AnalysisFramework::formatErrors()
{
+ string message;
for (auto const& error: m_compiler.errors())
- SourceReferenceFormatter::printExceptionInformation(
- std::cerr,
- *error,
- (error->type() == Error::Type::Warning) ? "Warning" : "Error",
+ message += formatError(*error);
+ return message;
+}
+
+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); }
);
}
diff --git a/test/libsolidity/AnalysisFramework.h b/test/libsolidity/AnalysisFramework.h
index 07e28f2b..a566ba1d 100644
--- a/test/libsolidity/AnalysisFramework.h
+++ b/test/libsolidity/AnalysisFramework.h
@@ -57,7 +57,8 @@ protected:
bool success(std::string const& _source);
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 FunctionTypePointer retrieveFunctionBySignature(
@@ -105,7 +106,10 @@ CHECK_ERROR_OR_WARNING(text, Warning, substring, true, true)
do \
{ \
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)