aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity/ErrorCheck.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/libsolidity/ErrorCheck.cpp')
-rw-r--r--test/libsolidity/ErrorCheck.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/libsolidity/ErrorCheck.cpp b/test/libsolidity/ErrorCheck.cpp
index b1e94061..fba2c897 100644
--- a/test/libsolidity/ErrorCheck.cpp
+++ b/test/libsolidity/ErrorCheck.cpp
@@ -23,8 +23,19 @@
#include <libdevcore/Exceptions.h>
#include <string>
+#include <set>
using namespace std;
+using namespace dev;
+using namespace dev::solidity;
+
+namespace
+{
+std::string errorMessage(Error const& _e)
+{
+ return _e.comment() ? *_e.comment() : "NONE";
+}
+}
bool dev::solidity::searchErrorMessage(Error const& _err, std::string const& _substr)
{
@@ -41,3 +52,31 @@ bool dev::solidity::searchErrorMessage(Error const& _err, std::string const& _su
cout << "Expected error message but found none." << endl;
return _substr.empty();
}
+
+string dev::solidity::searchErrors(ErrorList const& _errors, vector<pair<Error::Type, string>> const& _expectations)
+{
+ auto expectations = _expectations;
+ for (auto const& error: _errors)
+ {
+ string msg = errorMessage(*error);
+ bool found = false;
+ for (auto it = expectations.begin(); it != expectations.end(); ++it)
+ if (msg.find(it->second) != string::npos && error->type() == it->first)
+ {
+ found = true;
+ expectations.erase(it);
+ break;
+ }
+ if (!found)
+ return "Unexpected error: " + error->typeName() + ": " + msg;
+ }
+ if (!expectations.empty())
+ {
+ string msg = "Expected error(s) not present:\n";
+ for (auto const& expectation: expectations)
+ msg += expectation.second + "\n";
+ return msg;
+ }
+
+ return "";
+}