mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #6924 from ethereum/testRefactoring
Some test case refactoring.
This commit is contained in:
commit
644f5c00f5
@ -95,6 +95,20 @@ string TestCase::parseSourceAndSettings(istream& _stream)
|
|||||||
return source;
|
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)
|
void TestCase::expect(string::iterator& _it, string::iterator _end, string::value_type _c)
|
||||||
{
|
{
|
||||||
if (_it == _end || *_it != _c)
|
if (_it == _end || *_it != _c)
|
||||||
|
@ -92,6 +92,8 @@ protected:
|
|||||||
std::string parseSourceAndSettings(std::istream& _file);
|
std::string parseSourceAndSettings(std::istream& _file);
|
||||||
static void expect(std::string::iterator& _it, std::string::iterator _end, std::string::value_type _c);
|
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>
|
template<typename IteratorType>
|
||||||
static void skipWhitespace(IteratorType& _it, IteratorType _end)
|
static void skipWhitespace(IteratorType& _it, IteratorType _end)
|
||||||
{
|
{
|
||||||
|
@ -46,20 +46,14 @@ ObjectCompilerTest::ObjectCompilerTest(string const& _filename)
|
|||||||
BOOST_THROW_EXCEPTION(runtime_error("Cannot open test case: \"" + _filename + "\"."));
|
BOOST_THROW_EXCEPTION(runtime_error("Cannot open test case: \"" + _filename + "\"."));
|
||||||
file.exceptions(ios::badbit);
|
file.exceptions(ios::badbit);
|
||||||
|
|
||||||
string line;
|
m_source = parseSourceAndSettings(file);
|
||||||
while (getline(file, line))
|
if (m_settings.count("optimize"))
|
||||||
{
|
{
|
||||||
if (boost::algorithm::starts_with(line, "// ----"))
|
m_optimize = true;
|
||||||
break;
|
m_validatedSettings["optimize"] = "true";
|
||||||
if (m_source.empty() && boost::algorithm::starts_with(line, "// optimize"))
|
m_settings.erase("optimize");
|
||||||
m_optimize = true;
|
|
||||||
m_source += line + "\n";
|
|
||||||
}
|
}
|
||||||
while (getline(file, line))
|
m_expectation = parseSimpleExpectations(file);
|
||||||
if (boost::algorithm::starts_with(line, "//"))
|
|
||||||
m_expectation += line.substr((line.size() >= 3 && line[2] == ' ') ? 3 : 2) + "\n";
|
|
||||||
else
|
|
||||||
m_expectation += line + "\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TestCase::TestResult ObjectCompilerTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted)
|
TestCase::TestResult ObjectCompilerTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted)
|
||||||
|
@ -54,13 +54,7 @@ YulInterpreterTest::YulInterpreterTest(string const& _filename)
|
|||||||
file.exceptions(ios::badbit);
|
file.exceptions(ios::badbit);
|
||||||
|
|
||||||
m_source = parseSourceAndSettings(file);
|
m_source = parseSourceAndSettings(file);
|
||||||
|
m_expectation = parseSimpleExpectations(file);
|
||||||
string line;
|
|
||||||
while (getline(file, line))
|
|
||||||
if (boost::algorithm::starts_with(line, "// "))
|
|
||||||
m_expectation += line.substr(3) + "\n";
|
|
||||||
else
|
|
||||||
m_expectation += line + "\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TestCase::TestResult YulInterpreterTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted)
|
TestCase::TestResult YulInterpreterTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted)
|
||||||
|
@ -99,12 +99,7 @@ YulOptimizerTest::YulOptimizerTest(string const& _filename)
|
|||||||
m_settings.erase("step");
|
m_settings.erase("step");
|
||||||
}
|
}
|
||||||
|
|
||||||
string line;
|
m_expectation = parseSimpleExpectations(file);
|
||||||
while (getline(file, line))
|
|
||||||
if (boost::algorithm::starts_with(line, "// "))
|
|
||||||
m_expectation += line.substr(3) + "\n";
|
|
||||||
else
|
|
||||||
m_expectation += line + "\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TestCase::TestResult YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted)
|
TestCase::TestResult YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted)
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
// optimize
|
|
||||||
object "a" {
|
object "a" {
|
||||||
code {
|
code {
|
||||||
let x := calldataload(0)
|
let x := calldataload(0)
|
||||||
@ -15,24 +14,26 @@ object "a" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ====
|
||||||
|
// optimize: true
|
||||||
// ----
|
// ----
|
||||||
// Assembly:
|
// Assembly:
|
||||||
// /* "source":60:61 */
|
// /* "source":48:49 */
|
||||||
// 0x00
|
// 0x00
|
||||||
// 0x00
|
// 0x00
|
||||||
// /* "source":47:62 */
|
// /* "source":35:50 */
|
||||||
// calldataload
|
// calldataload
|
||||||
// /* "source":119:139 */
|
// /* "source":107:127 */
|
||||||
// sstore
|
// sstore
|
||||||
// stop
|
// stop
|
||||||
//
|
//
|
||||||
// sub_0: assembly {
|
// sub_0: assembly {
|
||||||
// /* "source":200:201 */
|
// /* "source":188:189 */
|
||||||
// 0x00
|
// 0x00
|
||||||
// 0x00
|
// 0x00
|
||||||
// /* "source":187:202 */
|
// /* "source":175:190 */
|
||||||
// calldataload
|
// calldataload
|
||||||
// /* "source":265:285 */
|
// /* "source":253:273 */
|
||||||
// sstore
|
// sstore
|
||||||
// }
|
// }
|
||||||
// Bytecode: 600060003555fe
|
// Bytecode: 600060003555fe
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
// optimize
|
|
||||||
{
|
{
|
||||||
let x := calldataload(0)
|
let x := calldataload(0)
|
||||||
let y := calldataload(0)
|
let y := calldataload(0)
|
||||||
let z := sub(y, x)
|
let z := sub(y, x)
|
||||||
sstore(add(x, 0), z)
|
sstore(add(x, 0), z)
|
||||||
}
|
}
|
||||||
|
// ====
|
||||||
|
// optimize: true
|
||||||
// ----
|
// ----
|
||||||
// Assembly:
|
// Assembly:
|
||||||
// /* "source":38:39 */
|
// /* "source":26:27 */
|
||||||
// 0x00
|
// 0x00
|
||||||
// 0x00
|
// 0x00
|
||||||
// /* "source":25:40 */
|
// /* "source":13:28 */
|
||||||
// calldataload
|
// calldataload
|
||||||
// /* "source":91:111 */
|
// /* "source":79:99 */
|
||||||
// sstore
|
// sstore
|
||||||
// Bytecode: 600060003555
|
// Bytecode: 600060003555
|
||||||
// Opcodes: PUSH1 0x0 PUSH1 0x0 CALLDATALOAD SSTORE
|
// Opcodes: PUSH1 0x0 PUSH1 0x0 CALLDATALOAD SSTORE
|
||||||
|
Loading…
Reference in New Issue
Block a user