25
25
26
26
#include < libsolidity/ast/AST.h>
27
27
28
+ #include < libsolidity/parsing/Scanner.h>
29
+
28
30
#include < libdevcore/SHA3.h>
29
31
30
32
#include < boost/test/unit_test.hpp>
@@ -46,8 +48,7 @@ AnalysisFramework::parseAnalyseAndReturnError(
46
48
m_compiler.addSource (" " , _insertVersionPragma ? " pragma solidity >=0.0;\n " + _source : _source);
47
49
if (!m_compiler.parse ())
48
50
{
49
- printErrors ();
50
- BOOST_ERROR (" Parsing contract failed in analysis test suite." );
51
+ BOOST_ERROR (" Parsing contract failed in analysis test suite:" + formatErrors ());
51
52
}
52
53
53
54
m_compiler.analyze ();
@@ -73,8 +74,7 @@ AnalysisFramework::parseAnalyseAndReturnError(
73
74
{
74
75
if (firstError && !_allowMultipleErrors)
75
76
{
76
- printErrors ();
77
- BOOST_FAIL (" Multiple errors found." );
77
+ BOOST_FAIL (" Multiple errors found: " + formatErrors ());
78
78
}
79
79
if (!firstError)
80
80
firstError = currentError;
@@ -88,7 +88,10 @@ SourceUnit const* AnalysisFramework::parseAndAnalyse(string const& _source)
88
88
{
89
89
auto sourceAndError = parseAnalyseAndReturnError (_source);
90
90
BOOST_REQUIRE (!!sourceAndError.first );
91
- BOOST_REQUIRE (!sourceAndError.second );
91
+ string message;
92
+ if (sourceAndError.second )
93
+ message = " Unexpected error: " + formatError (*sourceAndError.second );
94
+ BOOST_REQUIRE_MESSAGE (!sourceAndError.second , message);
92
95
return sourceAndError.first ;
93
96
}
94
97
@@ -101,17 +104,23 @@ Error AnalysisFramework::expectError(std::string const& _source, bool _warning,
101
104
{
102
105
auto sourceAndError = parseAnalyseAndReturnError (_source, _warning, true , _allowMultiple);
103
106
BOOST_REQUIRE (!!sourceAndError.second );
104
- BOOST_REQUIRE (!!sourceAndError.first );
107
+ BOOST_REQUIRE_MESSAGE (!!sourceAndError.first , " Expected error, but no error happened. " );
105
108
return *sourceAndError.second ;
106
109
}
107
110
108
- void AnalysisFramework::printErrors ()
111
+ string AnalysisFramework::formatErrors ()
109
112
{
113
+ string message;
110
114
for (auto const & error: m_compiler.errors ())
111
- SourceReferenceFormatter::printExceptionInformation (
112
- std::cerr,
113
- *error,
114
- (error->type () == Error::Type::Warning) ? " Warning" : " Error" ,
115
+ message += formatError (*error);
116
+ return message;
117
+ }
118
+
119
+ string AnalysisFramework::formatError (Error const & _error)
120
+ {
121
+ return SourceReferenceFormatter::formatExceptionInformation (
122
+ _error,
123
+ (_error.type () == Error::Type::Warning) ? " Warning" : " Error" ,
115
124
[&](std::string const & _sourceName) -> solidity::Scanner const & { return m_compiler.scanner (_sourceName); }
116
125
);
117
126
}
0 commit comments