mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Support compilation fail scenarios in ASTJSON tests
This commit is contained in:
parent
38639417e1
commit
f431c6f058
@ -6,3 +6,4 @@ contract C is NotExisting.X
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ----
|
// ----
|
||||||
|
// failAfter: Parsed
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <boost/algorithm/string/predicate.hpp>
|
#include <boost/algorithm/string/predicate.hpp>
|
||||||
#include <boost/algorithm/string/replace.hpp>
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
|
#include <boost/algorithm/string/trim.hpp>
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
#include <boost/throw_exception.hpp>
|
#include <boost/throw_exception.hpp>
|
||||||
|
|
||||||
@ -49,6 +50,15 @@ namespace
|
|||||||
|
|
||||||
string const sourceDelimiter("==== Source: ");
|
string const sourceDelimiter("==== Source: ");
|
||||||
|
|
||||||
|
const map<string, CompilerStack::State> compilerStateMap = {
|
||||||
|
{"Empty", CompilerStack::State::Empty},
|
||||||
|
{"SourcesSet", CompilerStack::State::SourcesSet},
|
||||||
|
{"Parsed", CompilerStack::State::Parsed},
|
||||||
|
{"ParsedAndImported", CompilerStack::State::ParsedAndImported},
|
||||||
|
{"AnalysisPerformed", CompilerStack::State::AnalysisPerformed},
|
||||||
|
{"CompilationSuccessful", CompilerStack::State::CompilationSuccessful}
|
||||||
|
};
|
||||||
|
|
||||||
void replaceVersionWithTag(string& _input)
|
void replaceVersionWithTag(string& _input)
|
||||||
{
|
{
|
||||||
boost::algorithm::replace_all(
|
boost::algorithm::replace_all(
|
||||||
@ -92,6 +102,7 @@ ASTJSONTest::ASTJSONTest(string const& _filename)
|
|||||||
string source;
|
string source;
|
||||||
string line;
|
string line;
|
||||||
string const delimiter("// ----");
|
string const delimiter("// ----");
|
||||||
|
string const failMarker("// failAfter:");
|
||||||
while (getline(file, line))
|
while (getline(file, line))
|
||||||
{
|
{
|
||||||
if (boost::algorithm::starts_with(line, sourceDelimiter))
|
if (boost::algorithm::starts_with(line, sourceDelimiter))
|
||||||
@ -105,6 +116,16 @@ ASTJSONTest::ASTJSONTest(string const& _filename)
|
|||||||
);
|
);
|
||||||
source = string();
|
source = string();
|
||||||
}
|
}
|
||||||
|
else if (boost::algorithm::starts_with(line, failMarker))
|
||||||
|
{
|
||||||
|
string state = line.substr(failMarker.size());
|
||||||
|
boost::algorithm::trim(state);
|
||||||
|
if (compilerStateMap.find(state) == compilerStateMap.end())
|
||||||
|
BOOST_THROW_EXCEPTION(runtime_error("Unsupported compiler state (" + state + ") in test contract file"));
|
||||||
|
if (m_expectedFailAfter.has_value())
|
||||||
|
BOOST_THROW_EXCEPTION(runtime_error("Duplicated \"failAfter\" directive"));
|
||||||
|
m_expectedFailAfter = compilerStateMap.at(state);
|
||||||
|
}
|
||||||
else if (!line.empty() && !boost::algorithm::starts_with(line, delimiter))
|
else if (!line.empty() && !boost::algorithm::starts_with(line, delimiter))
|
||||||
source += line + "\n";
|
source += line + "\n";
|
||||||
}
|
}
|
||||||
@ -141,8 +162,7 @@ TestCase::TestResult ASTJSONTest::run(ostream& _stream, string const& _linePrefi
|
|||||||
|
|
||||||
if (!c.parseAndAnalyze(variant.stopAfter))
|
if (!c.parseAndAnalyze(variant.stopAfter))
|
||||||
{
|
{
|
||||||
// We just want to export so raise fatal analysis errors only
|
if (!m_expectedFailAfter.has_value() || m_expectedFailAfter.value() + 1 != c.state())
|
||||||
if (c.state() < CompilerStack::State::ParsedAndImported)
|
|
||||||
{
|
{
|
||||||
SourceReferenceFormatter formatter(_stream, c, _formatted, false);
|
SourceReferenceFormatter formatter(_stream, c, _formatted, false);
|
||||||
formatter.printErrorInformation(c.errors());
|
formatter.printErrorInformation(c.errors());
|
||||||
|
@ -90,6 +90,7 @@ private:
|
|||||||
) const;
|
) const;
|
||||||
|
|
||||||
std::vector<TestVariant> m_variants;
|
std::vector<TestVariant> m_variants;
|
||||||
|
std::optional<CompilerStack::State> m_expectedFailAfter;
|
||||||
|
|
||||||
std::vector<std::pair<std::string, std::string>> m_sources;
|
std::vector<std::pair<std::string, std::string>> m_sources;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user