mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Allow test cases to indicate fatal errors.
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include <test/libsolidity/ASTJSONTest.h>
|
||||
#include <test/Options.h>
|
||||
#include <libdevcore/AnsiColorized.h>
|
||||
#include <liblangutil/SourceReferenceFormatterHuman.h>
|
||||
#include <libsolidity/ast/ASTJsonConverter.h>
|
||||
#include <libsolidity/interface/CompilerStack.h>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
@@ -27,6 +28,7 @@
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace langutil;
|
||||
using namespace dev::solidity;
|
||||
using namespace dev::solidity::test;
|
||||
using namespace dev::formatting;
|
||||
@@ -88,7 +90,7 @@ ASTJSONTest::ASTJSONTest(string const& _filename)
|
||||
}
|
||||
}
|
||||
|
||||
bool ASTJSONTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted)
|
||||
TestCase::TestResult ASTJSONTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted)
|
||||
{
|
||||
CompilerStack c;
|
||||
|
||||
@@ -101,7 +103,15 @@ bool ASTJSONTest::run(ostream& _stream, string const& _linePrefix, bool const _f
|
||||
}
|
||||
c.setSources(sources);
|
||||
c.setEVMVersion(dev::test::Options::get().evmVersion());
|
||||
c.parseAndAnalyze();
|
||||
if (c.parse())
|
||||
c.analyze();
|
||||
else
|
||||
{
|
||||
SourceReferenceFormatterHuman formatter(_stream, _formatted);
|
||||
for (auto const& error: c.errors())
|
||||
formatter.printErrorInformation(*error);
|
||||
return TestResult::FatalError;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < m_sources.size(); i++)
|
||||
{
|
||||
@@ -169,7 +179,7 @@ bool ASTJSONTest::run(ostream& _stream, string const& _linePrefix, bool const _f
|
||||
resultsMatch = false;
|
||||
}
|
||||
|
||||
return resultsMatch;
|
||||
return resultsMatch ? TestResult::Success : TestResult::Failure;
|
||||
}
|
||||
|
||||
void ASTJSONTest::printSource(ostream& _stream, string const& _linePrefix, bool const) const
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
{ return std::unique_ptr<TestCase>(new ASTJSONTest(_config.filename)); }
|
||||
ASTJSONTest(std::string const& _filename);
|
||||
|
||||
bool run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) override;
|
||||
TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) override;
|
||||
|
||||
void printSource(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) const override;
|
||||
void printUpdatedExpectations(std::ostream& _stream, std::string const& _linePrefix) const override;
|
||||
|
||||
@@ -158,7 +158,7 @@ void GasTest::printUpdatedExpectations(std::ostream& _stream, std::string const&
|
||||
}
|
||||
|
||||
|
||||
bool GasTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
|
||||
TestCase::TestResult GasTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
|
||||
{
|
||||
string const versionPragma = "pragma solidity >=0.0;\n";
|
||||
compiler().reset();
|
||||
@@ -174,10 +174,10 @@ bool GasTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
|
||||
|
||||
if (!compiler().parseAndAnalyze() || !compiler().compile())
|
||||
{
|
||||
SourceReferenceFormatterHuman formatter(cerr, _formatted);
|
||||
SourceReferenceFormatterHuman formatter(_stream, _formatted);
|
||||
for (auto const& error: compiler().errors())
|
||||
formatter.printErrorInformation(*error);
|
||||
BOOST_THROW_EXCEPTION(runtime_error("Test contract does not compile."));
|
||||
return TestResult::FatalError;
|
||||
}
|
||||
|
||||
Json::Value estimates = compiler().gasEstimates(compiler().lastContractName());
|
||||
@@ -226,7 +226,7 @@ bool GasTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
|
||||
printUpdatedExpectations(_stream, _linePrefix + " ");
|
||||
}
|
||||
|
||||
return success;
|
||||
return success ? TestResult::Success : TestResult::Failure;
|
||||
}
|
||||
|
||||
void GasTest::printSource(ostream& _stream, string const& _linePrefix, bool) const
|
||||
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
{ return std::make_unique<GasTest>(_config.filename); }
|
||||
GasTest(std::string const& _filename);
|
||||
|
||||
bool run(std::ostream& _stream, std::string const& _linePrefix = "", bool _formatted = false) override;
|
||||
TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool _formatted = false) override;
|
||||
|
||||
void printSource(std::ostream &_stream, std::string const &_linePrefix = "", bool _formatted = false) const override;
|
||||
void printUpdatedExpectations(std::ostream& _stream, std::string const& _linePrefix) const override;
|
||||
|
||||
@@ -49,7 +49,7 @@ SMTCheckerTest::SMTCheckerTest(string const& _filename, langutil::EVMVersion _ev
|
||||
BOOST_THROW_EXCEPTION(runtime_error("Invalid JSON file."));
|
||||
}
|
||||
|
||||
bool SMTCheckerTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
|
||||
TestCase::TestResult SMTCheckerTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
|
||||
{
|
||||
StandardCompiler compiler;
|
||||
|
||||
@@ -121,7 +121,7 @@ bool SMTCheckerTest::run(ostream& _stream, string const& _linePrefix, bool _form
|
||||
}
|
||||
}
|
||||
|
||||
return printExpectationAndError(_stream, _linePrefix, _formatted);
|
||||
return printExpectationAndError(_stream, _linePrefix, _formatted) ? TestResult::Success : TestResult::Failure;
|
||||
}
|
||||
|
||||
vector<string> SMTCheckerTest::hashesFromJson(Json::Value const& _jsonObj, string const& _auxInput, string const& _smtlib)
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
}
|
||||
SMTCheckerTest(std::string const& _filename, langutil::EVMVersion _evmVersion);
|
||||
|
||||
bool run(std::ostream& _stream, std::string const& _linePrefix = "", bool _formatted = false) override;
|
||||
TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool _formatted = false) override;
|
||||
|
||||
private:
|
||||
std::vector<std::string> hashesFromJson(Json::Value const& _jsonObj, std::string const& _auxInput, std::string const& _smtlib);
|
||||
|
||||
@@ -53,7 +53,7 @@ SemanticTest::SemanticTest(string const& _filename, string const& _ipcPath, lang
|
||||
parseExpectations(file);
|
||||
}
|
||||
|
||||
bool SemanticTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
|
||||
TestCase::TestResult SemanticTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
|
||||
{
|
||||
soltestAssert(deploy("", 0, bytes()), "Failed to deploy contract.");
|
||||
|
||||
@@ -96,9 +96,9 @@ bool SemanticTest::run(ostream& _stream, string const& _linePrefix, bool _format
|
||||
}
|
||||
AnsiColorized(_stream, _formatted, {BOLD, RED}) << _linePrefix << endl << _linePrefix
|
||||
<< "Attention: Updates on the test will apply the detected format displayed." << endl;
|
||||
return false;
|
||||
return TestResult::Failure;
|
||||
}
|
||||
return true;
|
||||
return TestResult::Success;
|
||||
}
|
||||
|
||||
void SemanticTest::printSource(ostream& _stream, string const& _linePrefix, bool) const
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
|
||||
explicit SemanticTest(std::string const& _filename, std::string const& _ipcPath, langutil::EVMVersion _evmVersion);
|
||||
|
||||
bool run(std::ostream& _stream, std::string const& _linePrefix = "", bool _formatted = false) override;
|
||||
TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool _formatted = false) override;
|
||||
void printSource(std::ostream &_stream, std::string const& _linePrefix = "", bool _formatted = false) const override;
|
||||
void printUpdatedExpectations(std::ostream& _stream, std::string const& _linePrefix = "") const override;
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ SyntaxTest::SyntaxTest(string const& _filename, langutil::EVMVersion _evmVersion
|
||||
m_expectations = parseExpectations(file);
|
||||
}
|
||||
|
||||
bool SyntaxTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
|
||||
TestCase::TestResult SyntaxTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
|
||||
{
|
||||
string const versionPragma = "pragma solidity >=0.0;\n";
|
||||
compiler().reset();
|
||||
@@ -92,7 +92,7 @@ bool SyntaxTest::run(ostream& _stream, string const& _linePrefix, bool _formatte
|
||||
});
|
||||
}
|
||||
|
||||
return printExpectationAndError(_stream, _linePrefix, _formatted);
|
||||
return printExpectationAndError(_stream, _linePrefix, _formatted) ? TestResult::Success : TestResult::Failure;
|
||||
}
|
||||
|
||||
bool SyntaxTest::printExpectationAndError(ostream& _stream, string const& _linePrefix, bool _formatted)
|
||||
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
{ return std::make_unique<SyntaxTest>(_config.filename, _config.evmVersion); }
|
||||
SyntaxTest(std::string const& _filename, langutil::EVMVersion _evmVersion);
|
||||
|
||||
bool run(std::ostream& _stream, std::string const& _linePrefix = "", bool _formatted = false) override;
|
||||
TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool _formatted = false) override;
|
||||
|
||||
void printSource(std::ostream &_stream, std::string const &_linePrefix = "", bool _formatted = false) const override;
|
||||
void printUpdatedExpectations(std::ostream& _stream, std::string const& _linePrefix) const override
|
||||
|
||||
Reference in New Issue
Block a user