mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Unify parsing of simple test expectations and require lines to start with `//
`.
This commit is contained in:
parent
bd1f65d609
commit
547173533c
@ -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)
|
||||||
{
|
{
|
||||||
|
@ -55,11 +55,7 @@ ObjectCompilerTest::ObjectCompilerTest(string const& _filename)
|
|||||||
m_optimize = true;
|
m_optimize = true;
|
||||||
m_source += line + "\n";
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user