mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Introduced TestCaseReader.
This commit is contained in:
@@ -36,15 +36,11 @@ using namespace solidity::util;
|
||||
using namespace solidity::frontend;
|
||||
using namespace solidity::frontend::test;
|
||||
|
||||
ABIJsonTest::ABIJsonTest(string const& _filename)
|
||||
ABIJsonTest::ABIJsonTest(string const& _filename):
|
||||
TestCase(_filename)
|
||||
{
|
||||
ifstream file(_filename);
|
||||
if (!file)
|
||||
BOOST_THROW_EXCEPTION(runtime_error("Cannot open test contract: \"" + _filename + "\"."));
|
||||
file.exceptions(ios::badbit);
|
||||
|
||||
m_source = parseSourceAndSettings(file);
|
||||
m_expectation = parseSimpleExpectations(file);
|
||||
m_source = m_reader.source();
|
||||
m_expectation = m_reader.simpleExpectations();
|
||||
}
|
||||
|
||||
TestCase::TestResult ABIJsonTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
|
||||
|
||||
@@ -36,35 +36,14 @@ using namespace std;
|
||||
namespace fs = boost::filesystem;
|
||||
using namespace boost::unit_test;
|
||||
|
||||
GasTest::GasTest(string const& _filename)
|
||||
GasTest::GasTest(string const& _filename):
|
||||
TestCase(_filename)
|
||||
{
|
||||
ifstream file(_filename);
|
||||
if (!file)
|
||||
BOOST_THROW_EXCEPTION(runtime_error("Cannot open test contract: \"" + _filename + "\"."));
|
||||
file.exceptions(ios::badbit);
|
||||
|
||||
m_source = parseSourceAndSettings(file);
|
||||
|
||||
if (m_settings.count("optimize"))
|
||||
{
|
||||
m_optimise = true;
|
||||
m_validatedSettings["optimize"] = "true";
|
||||
m_settings.erase("optimize");
|
||||
}
|
||||
if (m_settings.count("optimize-yul"))
|
||||
{
|
||||
m_optimiseYul = true;
|
||||
m_validatedSettings["optimize-yul"] = "true";
|
||||
m_settings.erase("optimize-yul");
|
||||
}
|
||||
if (m_settings.count("optimize-runs"))
|
||||
{
|
||||
m_optimiseRuns = stoul(m_settings["optimize-runs"]);
|
||||
m_validatedSettings["optimize-runs"] = m_settings["optimize-runs"];
|
||||
m_settings.erase("optimize-runs");
|
||||
}
|
||||
|
||||
parseExpectations(file);
|
||||
m_source = m_reader.source();
|
||||
m_optimise = m_reader.boolSetting("optimize", false);
|
||||
m_optimiseYul = m_reader.boolSetting("optimize-yul", false);
|
||||
m_optimiseRuns = m_reader.sizetSetting("optimize-runs", 200);
|
||||
parseExpectations(m_reader.stream());
|
||||
}
|
||||
|
||||
void GasTest::parseExpectations(std::istream& _stream)
|
||||
|
||||
@@ -28,22 +28,17 @@ using namespace solidity::frontend::test;
|
||||
|
||||
SMTCheckerTest::SMTCheckerTest(string const& _filename, langutil::EVMVersion _evmVersion): SyntaxTest(_filename, _evmVersion)
|
||||
{
|
||||
if (m_settings.count("SMTSolvers"))
|
||||
{
|
||||
auto const& choice = m_settings.at("SMTSolvers");
|
||||
if (choice == "any")
|
||||
m_enabledSolvers = smt::SMTSolverChoice::All();
|
||||
else if (choice == "z3")
|
||||
m_enabledSolvers = smt::SMTSolverChoice::Z3();
|
||||
else if (choice == "cvc4")
|
||||
m_enabledSolvers = smt::SMTSolverChoice::CVC4();
|
||||
else if (choice == "none")
|
||||
m_enabledSolvers = smt::SMTSolverChoice::None();
|
||||
else
|
||||
BOOST_THROW_EXCEPTION(runtime_error("Invalid SMT solver choice."));
|
||||
}
|
||||
else
|
||||
auto const& choice = m_reader.stringSetting("SMTSolvers", "any");
|
||||
if (choice == "any")
|
||||
m_enabledSolvers = smt::SMTSolverChoice::All();
|
||||
else if (choice == "z3")
|
||||
m_enabledSolvers = smt::SMTSolverChoice::Z3();
|
||||
else if (choice == "cvc4")
|
||||
m_enabledSolvers = smt::SMTSolverChoice::CVC4();
|
||||
else if (choice == "none")
|
||||
m_enabledSolvers = smt::SMTSolverChoice::None();
|
||||
else
|
||||
BOOST_THROW_EXCEPTION(runtime_error("Invalid SMT solver choice."));
|
||||
|
||||
auto available = ModelChecker::availableSolvers();
|
||||
if (!available.z3)
|
||||
|
||||
@@ -37,59 +37,39 @@ namespace fs = boost::filesystem;
|
||||
|
||||
|
||||
SemanticTest::SemanticTest(string const& _filename, langutil::EVMVersion _evmVersion):
|
||||
SolidityExecutionFramework(_evmVersion)
|
||||
SolidityExecutionFramework(_evmVersion),
|
||||
EVMVersionRestrictedTestCase(_filename)
|
||||
{
|
||||
ifstream file(_filename);
|
||||
soltestAssert(file, "Cannot open test contract: \"" + _filename + "\".");
|
||||
file.exceptions(ios::badbit);
|
||||
m_source = m_reader.source();
|
||||
m_lineOffset = m_reader.lineNumber();
|
||||
|
||||
std::tie(m_source, m_lineOffset) = parseSourceAndSettingsWithLineNumbers(file);
|
||||
|
||||
if (m_settings.count("compileViaYul"))
|
||||
if (m_reader.hasSetting("compileViaYul"))
|
||||
{
|
||||
if (m_settings["compileViaYul"] == "also")
|
||||
string choice = m_reader.stringSetting("compileViaYul", "");
|
||||
if (choice == "also")
|
||||
{
|
||||
m_validatedSettings["compileViaYul"] = m_settings["compileViaYul"];
|
||||
m_runWithYul = true;
|
||||
m_runWithoutYul = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_validatedSettings["compileViaYul"] = "only";
|
||||
m_reader.setSetting("compileViaYul", "only");
|
||||
m_runWithYul = true;
|
||||
m_runWithoutYul = false;
|
||||
}
|
||||
m_settings.erase("compileViaYul");
|
||||
}
|
||||
if (m_settings.count("ABIEncoderV1Only"))
|
||||
{
|
||||
if (m_settings["ABIEncoderV1Only"] == "true")
|
||||
{
|
||||
m_validatedSettings["ABIEncoderV1Only"] = "true";
|
||||
m_runWithABIEncoderV1Only = true;
|
||||
}
|
||||
m_settings.erase("ABIEncoderV1Only");
|
||||
}
|
||||
|
||||
m_runWithABIEncoderV1Only = m_reader.boolSetting("ABIEncoderV1Only", false);
|
||||
if (m_runWithABIEncoderV1Only && solidity::test::CommonOptions::get().useABIEncoderV2)
|
||||
m_shouldRun = false;
|
||||
|
||||
if (m_settings.count("revertStrings"))
|
||||
{
|
||||
auto revertStrings = revertStringsFromString(m_settings["revertStrings"]);
|
||||
if (revertStrings)
|
||||
m_revertStrings = *revertStrings;
|
||||
m_validatedSettings["revertStrings"] = revertStringsToString(m_revertStrings);
|
||||
m_settings.erase("revertStrings");
|
||||
}
|
||||
auto revertStrings = revertStringsFromString(m_reader.stringSetting("revertStrings", "default"));
|
||||
soltestAssert(revertStrings, "Invalid revertStrings setting.");
|
||||
m_revertStrings = revertStrings.value();
|
||||
|
||||
if (m_settings.count("allowNonExistingFunctions"))
|
||||
{
|
||||
m_validatedSettings["allowNonExistingFunctions"] = true;
|
||||
m_settings.erase("allowNonExistingFunctions");
|
||||
}
|
||||
m_allowNonExistingFunctions = m_reader.boolSetting("allowNonExistingFunctions", false);
|
||||
|
||||
parseExpectations(file);
|
||||
parseExpectations(m_reader.stream());
|
||||
soltestAssert(!m_tests.empty(), "No tests specified in " + _filename);
|
||||
}
|
||||
|
||||
@@ -152,7 +132,7 @@ TestCase::TestResult SemanticTest::run(ostream& _stream, string const& _linePref
|
||||
else
|
||||
{
|
||||
soltestAssert(
|
||||
m_validatedSettings.count("allowNonExistingFunctions") || m_compiler.methodIdentifiers(m_compiler.lastContractName()).isMember(test.call().signature),
|
||||
m_allowNonExistingFunctions || m_compiler.methodIdentifiers(m_compiler.lastContractName()).isMember(test.call().signature),
|
||||
"The function " + test.call().signature + " is not known to the compiler"
|
||||
);
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ private:
|
||||
bool m_runWithYul = false;
|
||||
bool m_runWithoutYul = true;
|
||||
bool m_runWithABIEncoderV1Only = false;
|
||||
bool m_allowNonExistingFunctions = false;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -37,20 +37,7 @@ namespace fs = boost::filesystem;
|
||||
|
||||
SyntaxTest::SyntaxTest(string const& _filename, langutil::EVMVersion _evmVersion, bool _parserErrorRecovery): CommonSyntaxTest(_filename, _evmVersion)
|
||||
{
|
||||
if (m_settings.count("optimize-yul"))
|
||||
{
|
||||
if (m_settings["optimize-yul"] == "true")
|
||||
{
|
||||
m_validatedSettings["optimize-yul"] = "true";
|
||||
m_settings.erase("optimize-yul");
|
||||
}
|
||||
else if (m_settings["optimize-yul"] == "false")
|
||||
{
|
||||
m_validatedSettings["optimize-yul"] = "false";
|
||||
m_settings.erase("optimize-yul");
|
||||
m_optimiseYul = false;
|
||||
}
|
||||
}
|
||||
m_optimiseYul = m_reader.boolSetting("optimize-yul", true);
|
||||
m_parserErrorRecovery = _parserErrorRecovery;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user