Merge pull request #6924 from ethereum/testRefactoring

Some test case refactoring.
This commit is contained in:
Daniel Kirchner 2019-06-11 15:13:45 +02:00 committed by GitHub
commit 644f5c00f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 37 additions and 36 deletions

View File

@ -95,6 +95,20 @@ string TestCase::parseSourceAndSettings(istream& _stream)
return source;
}
string TestCase::parseSimpleExpectations(std::istream& _file)
{
string result;
string line;
while (getline(_file, line))
if (boost::algorithm::starts_with(line, "// "))
result += line.substr(3) + "\n";
else if (line == "//")
result += "\n";
else
BOOST_THROW_EXCEPTION(runtime_error("Test expectations must start with \"// \"."));
return result;
}
void TestCase::expect(string::iterator& _it, string::iterator _end, string::value_type _c)
{
if (_it == _end || *_it != _c)

View File

@ -92,6 +92,8 @@ protected:
std::string parseSourceAndSettings(std::istream& _file);
static void expect(std::string::iterator& _it, std::string::iterator _end, std::string::value_type _c);
static std::string parseSimpleExpectations(std::istream& _file);
template<typename IteratorType>
static void skipWhitespace(IteratorType& _it, IteratorType _end)
{

View File

@ -46,20 +46,14 @@ ObjectCompilerTest::ObjectCompilerTest(string const& _filename)
BOOST_THROW_EXCEPTION(runtime_error("Cannot open test case: \"" + _filename + "\"."));
file.exceptions(ios::badbit);
string line;
while (getline(file, line))
m_source = parseSourceAndSettings(file);
if (m_settings.count("optimize"))
{
if (boost::algorithm::starts_with(line, "// ----"))
break;
if (m_source.empty() && boost::algorithm::starts_with(line, "// optimize"))
m_optimize = true;
m_source += line + "\n";
m_optimize = true;
m_validatedSettings["optimize"] = "true";
m_settings.erase("optimize");
}
while (getline(file, line))
if (boost::algorithm::starts_with(line, "//"))
m_expectation += line.substr((line.size() >= 3 && line[2] == ' ') ? 3 : 2) + "\n";
else
m_expectation += line + "\n";
m_expectation = parseSimpleExpectations(file);
}
TestCase::TestResult ObjectCompilerTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted)

View File

@ -54,13 +54,7 @@ YulInterpreterTest::YulInterpreterTest(string const& _filename)
file.exceptions(ios::badbit);
m_source = parseSourceAndSettings(file);
string line;
while (getline(file, line))
if (boost::algorithm::starts_with(line, "// "))
m_expectation += line.substr(3) + "\n";
else
m_expectation += line + "\n";
m_expectation = parseSimpleExpectations(file);
}
TestCase::TestResult YulInterpreterTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted)

View File

@ -99,12 +99,7 @@ YulOptimizerTest::YulOptimizerTest(string const& _filename)
m_settings.erase("step");
}
string line;
while (getline(file, line))
if (boost::algorithm::starts_with(line, "// "))
m_expectation += line.substr(3) + "\n";
else
m_expectation += line + "\n";
m_expectation = parseSimpleExpectations(file);
}
TestCase::TestResult YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted)

View File

@ -1,4 +1,3 @@
// optimize
object "a" {
code {
let x := calldataload(0)
@ -15,24 +14,26 @@ object "a" {
}
}
}
// ====
// optimize: true
// ----
// Assembly:
// /* "source":60:61 */
// /* "source":48:49 */
// 0x00
// 0x00
// /* "source":47:62 */
// /* "source":35:50 */
// calldataload
// /* "source":119:139 */
// /* "source":107:127 */
// sstore
// stop
//
// sub_0: assembly {
// /* "source":200:201 */
// /* "source":188:189 */
// 0x00
// 0x00
// /* "source":187:202 */
// /* "source":175:190 */
// calldataload
// /* "source":265:285 */
// /* "source":253:273 */
// sstore
// }
// Bytecode: 600060003555fe

View File

@ -1,18 +1,19 @@
// optimize
{
let x := calldataload(0)
let y := calldataload(0)
let z := sub(y, x)
sstore(add(x, 0), z)
}
// ====
// optimize: true
// ----
// Assembly:
// /* "source":38:39 */
// /* "source":26:27 */
// 0x00
// 0x00
// /* "source":25:40 */
// /* "source":13:28 */
// calldataload
// /* "source":91:111 */
// /* "source":79:99 */
// sstore
// Bytecode: 600060003555
// Opcodes: PUSH1 0x0 PUSH1 0x0 CALLDATALOAD SSTORE