diff options
author | chriseth <chris@ethereum.org> | 2017-09-29 18:41:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-29 18:41:26 +0800 |
commit | f3fe043cc13ac76a7ca02285a54f973a4dc4461d (patch) | |
tree | 84b91fd8fa32a40da6715f09806116c09976b028 /test/libsolidity/AnalysisFramework.cpp | |
parent | b92184688002c73fece4e8beb0beaa897649de4e (diff) | |
parent | 08effa0af54647971415cb66dc9181afad9642ee (diff) | |
download | dexon-solidity-f3fe043cc13ac76a7ca02285a54f973a4dc4461d.tar dexon-solidity-f3fe043cc13ac76a7ca02285a54f973a4dc4461d.tar.gz dexon-solidity-f3fe043cc13ac76a7ca02285a54f973a4dc4461d.tar.bz2 dexon-solidity-f3fe043cc13ac76a7ca02285a54f973a4dc4461d.tar.lz dexon-solidity-f3fe043cc13ac76a7ca02285a54f973a4dc4461d.tar.xz dexon-solidity-f3fe043cc13ac76a7ca02285a54f973a4dc4461d.tar.zst dexon-solidity-f3fe043cc13ac76a7ca02285a54f973a4dc4461d.zip |
Merge pull request #2989 from ethereum/filterMoreWarnigs
Allow frameworks to filter warnings.
Diffstat (limited to 'test/libsolidity/AnalysisFramework.cpp')
-rw-r--r-- | test/libsolidity/AnalysisFramework.cpp | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/test/libsolidity/AnalysisFramework.cpp b/test/libsolidity/AnalysisFramework.cpp index 5f5f6411..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(); @@ -56,15 +57,24 @@ AnalysisFramework::parseAnalyseAndReturnError( for (auto const& currentError: m_compiler.errors()) { solAssert(currentError->comment(), ""); - if (currentError->comment()->find("This is a pre-release compiler version") == 0) - continue; + if (currentError->type() == Error::Type::Warning) + { + bool ignoreWarning = false; + for (auto const& filter: m_warningsToFilter) + if (currentError->comment()->find(filter) == 0) + { + ignoreWarning = true; + break; + } + if (ignoreWarning) + continue; + } if (_reportWarnings || (currentError->type() != Error::Type::Warning)) { if (firstError && !_allowMultipleErrors) { - printErrors(); - BOOST_FAIL("Multiple errors found."); + BOOST_FAIL("Multiple errors found: " + formatErrors()); } if (!firstError) firstError = currentError; @@ -78,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; } @@ -91,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); } ); } |