Unified use of settings. Removed a couple of unused functions.

This commit is contained in:
a3d4 2020-03-19 02:48:42 +01:00
parent 3b9e926559
commit f4d9f6772f
10 changed files with 30 additions and 40 deletions

View File

@ -28,7 +28,7 @@ using namespace solidity;
using namespace solidity::frontend;
using namespace solidity::frontend::test;
void TestCase::printUpdatedSettings(ostream& _stream, const string& _linePrefix, const bool)
void TestCase::printSettings(ostream& _stream, const string& _linePrefix, const bool)
{
auto& settings = m_reader.settings();
if (settings.empty())
@ -63,11 +63,10 @@ void TestCase::expect(string::iterator& _it, string::iterator _end, string::valu
EVMVersionRestrictedTestCase::EVMVersionRestrictedTestCase(string const& _filename):
TestCase(_filename)
{
if (!m_reader.hasSetting("EVMVersion"))
string versionString = m_reader.stringSetting("EVMVersion", "any");
if (versionString == "any")
return;
string versionString = m_reader.stringSetting("EVMVersion", "");
string comparator;
size_t versionBegin = 0;
for (auto character: versionString)

View File

@ -57,8 +57,8 @@ public:
/// If @arg _formatted is true, color-coding may be used to indicate
/// error locations in the contract, if applicable.
virtual void printSource(std::ostream &_stream, std::string const &_linePrefix = "", bool const _formatted = false) const = 0;
/// Outputs the updated settings.
virtual void printUpdatedSettings(std::ostream &_stream, std::string const &_linePrefix = "", bool const _formatted = false);
/// Outputs settings.
virtual void printSettings(std::ostream &_stream, std::string const &_linePrefix = "", bool const _formatted = false);
/// Outputs test expectations to @arg _stream that match the actual results of the test.
/// Each line of output is prefixed with @arg _linePrefix.
virtual void printUpdatedExpectations(std::ostream& _stream, std::string const& _linePrefix) const = 0;

View File

@ -49,14 +49,9 @@ string TestCaseReader::simpleExpectations()
return parseSimpleExpectations(m_file);
}
bool TestCaseReader::hasSetting(std::string const& _name) const
{
return m_settings.count(_name) != 0;
}
bool TestCaseReader::boolSetting(std::string const& _name, bool _defaultValue)
{
if (!hasSetting(_name))
if (m_settings.count(_name) == 0)
return _defaultValue;
m_unreadSettings.erase(_name);
@ -71,7 +66,7 @@ bool TestCaseReader::boolSetting(std::string const& _name, bool _defaultValue)
size_t TestCaseReader::sizetSetting(std::string const& _name, size_t _defaultValue)
{
if (!hasSetting(_name))
if (m_settings.count(_name) == 0)
return _defaultValue;
m_unreadSettings.erase(_name);
@ -82,18 +77,13 @@ size_t TestCaseReader::sizetSetting(std::string const& _name, size_t _defaultVal
string TestCaseReader::stringSetting(string const& _name, string const& _defaultValue)
{
if (!hasSetting(_name))
if (m_settings.count(_name) == 0)
return _defaultValue;
m_unreadSettings.erase(_name);
return m_settings.at(_name);
}
void TestCaseReader::setSetting(std::string const& _name, std::string const& _value)
{
m_settings[_name] = _value;
}
void TestCaseReader::ensureAllSettingsRead() const
{
if (!m_unreadSettings.empty())

View File

@ -40,11 +40,9 @@ public:
std::string simpleExpectations();
bool hasSetting(std::string const& _name) const;
bool boolSetting(std::string const& _name, bool _defaultValue);
size_t sizetSetting(std::string const& _name, size_t _defaultValue);
std::string stringSetting(std::string const& _name, std::string const& _defaultValue);
void setSetting(std::string const& _name, std::string const& _value);
void ensureAllSettingsRead() const;

View File

@ -43,21 +43,24 @@ SemanticTest::SemanticTest(string const& _filename, langutil::EVMVersion _evmVer
m_source = m_reader.source();
m_lineOffset = m_reader.lineNumber();
if (m_reader.hasSetting("compileViaYul"))
string choice = m_reader.stringSetting("compileViaYul", "false");
if (choice == "also")
{
string choice = m_reader.stringSetting("compileViaYul", "");
if (choice == "also")
{
m_runWithYul = true;
m_runWithoutYul = true;
}
else
{
m_reader.setSetting("compileViaYul", "only");
m_runWithYul = true;
m_runWithoutYul = false;
}
m_runWithYul = true;
m_runWithoutYul = true;
}
else if (choice == "true")
{
m_runWithYul = true;
m_runWithoutYul = false;
}
else if (choice == "false")
{
m_runWithYul = false;
m_runWithoutYul = true;
}
else
BOOST_THROW_EXCEPTION(runtime_error("Invalid compileViaYul value: " + choice + "."));
m_runWithABIEncoderV1Only = m_reader.boolSetting("ABIEncoderV1Only", false);
if (m_runWithABIEncoderV1Only && solidity::test::CommonOptions::get().useABIEncoderV2)

View File

@ -7,7 +7,7 @@ contract C {
}
}
// ====
// compileViaYul: only
// compileViaYul: true
// ----
// f(uint256,uint256): 10, 3 -> 1
// f(uint256,uint256): 10, 2 -> 0

View File

@ -7,7 +7,7 @@ contract C {
}
}
// ====
// compileViaYul: only
// compileViaYul: true
// ----
// f(int256,int256): 10, 3 -> 1
// f(int256,int256): 10, 2 -> 0

View File

@ -8,7 +8,7 @@ contract C {
}
}
// ====
// compileViaYul: only
// compileViaYul: true
// ----
// keccak1() -> 0x64e604787cbf194841e7b68d7cd28786f6c9a0a3ab9f8b0a0e87cb4387ab0107
// keccak2() -> 0x64e604787cbf194841e7b68d7cd28786f6c9a0a3ab9f8b0a0e87cb4387ab0107

View File

@ -5,7 +5,7 @@ contract C {
function h() external pure returns (bytes4) { return 0xcafecafe; }
}
// ====
// compileViaYul: only
// compileViaYul: true
// ----
// f1() -> 0x20, 6, left(0x616263616263)
// f2() -> 32, 47, 44048183223289766195424279195050628400112610419087780792899004030957505095210, 18165586057823232067963737336409268114628061002662705707816940456850361417728

View File

@ -172,7 +172,7 @@ TestTool::Result TestTool::process()
AnsiColorized(cout, formatted, {BOLD, CYAN}) << " Contract:" << endl;
m_test->printSource(cout, " ", formatted);
m_test->printUpdatedSettings(cout, " ", formatted);
m_test->printSettings(cout, " ", formatted);
cout << endl << outputMessages.str() << endl;
return result == TestCase::TestResult::FatalError ? Result::Exception : Result::Failure;
@ -231,7 +231,7 @@ TestTool::Request TestTool::handleResponse(bool _exception)
cout << endl;
ofstream file(m_path.string(), ios::trunc);
m_test->printSource(file);
m_test->printUpdatedSettings(file);
m_test->printSettings(file);
file << "// ----" << endl;
m_test->printUpdatedExpectations(file, "// ");
return Request::Rerun;