2018-06-08 12:17:50 +00:00
|
|
|
/*
|
|
|
|
This file is part of solidity.
|
|
|
|
|
|
|
|
solidity is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
solidity is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-11-25 00:02:32 +00:00
|
|
|
#include <test/TestCase.h>
|
2018-06-08 12:17:50 +00:00
|
|
|
|
2019-03-18 13:08:56 +00:00
|
|
|
#include <boost/algorithm/cxx11/none_of.hpp>
|
2018-06-08 12:17:50 +00:00
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
#include <boost/algorithm/string/predicate.hpp>
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
using namespace dev;
|
|
|
|
using namespace solidity;
|
|
|
|
using namespace dev::solidity::test;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
bool TestCase::isTestFilename(boost::filesystem::path const& _filename)
|
|
|
|
{
|
2018-10-09 13:43:55 +00:00
|
|
|
string extension = _filename.extension().string();
|
|
|
|
return (extension == ".sol" || extension == ".yul") &&
|
2018-06-08 12:17:50 +00:00
|
|
|
!boost::starts_with(_filename.string(), "~") &&
|
|
|
|
!boost::starts_with(_filename.string(), ".");
|
|
|
|
}
|
|
|
|
|
2019-03-15 16:22:04 +00:00
|
|
|
bool TestCase::supportedForEVMVersion(langutil::EVMVersion _evmVersion) const
|
|
|
|
{
|
2019-03-18 13:08:56 +00:00
|
|
|
return boost::algorithm::none_of(m_evmVersionRules, [&](auto const& rule) { return !rule(_evmVersion); });
|
2019-03-15 16:22:04 +00:00
|
|
|
}
|
|
|
|
|
2018-06-08 12:17:50 +00:00
|
|
|
string TestCase::parseSource(istream& _stream)
|
|
|
|
{
|
|
|
|
string source;
|
|
|
|
string line;
|
2019-03-18 13:08:56 +00:00
|
|
|
static string const delimiter("// ----");
|
|
|
|
static string const evmVersion("// EVMVersion: ");
|
2019-03-15 16:22:04 +00:00
|
|
|
bool isTop = true;
|
2018-06-08 12:17:50 +00:00
|
|
|
while (getline(_stream, line))
|
|
|
|
if (boost::algorithm::starts_with(line, delimiter))
|
|
|
|
break;
|
|
|
|
else
|
2019-03-15 16:22:04 +00:00
|
|
|
{
|
|
|
|
if (isTop && boost::algorithm::starts_with(line, evmVersion))
|
|
|
|
{
|
|
|
|
string versionString = line.substr(evmVersion.size() + 1);
|
|
|
|
auto version = langutil::EVMVersion::fromString(versionString);
|
|
|
|
if (!version)
|
|
|
|
throw runtime_error("Invalid EVM version: \"" + versionString + "\"");
|
|
|
|
switch (line.at(evmVersion.size()))
|
|
|
|
{
|
|
|
|
case '>':
|
|
|
|
m_evmVersionRules.emplace_back([version](langutil::EVMVersion _version) {
|
|
|
|
return version < _version;
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case '<':
|
|
|
|
m_evmVersionRules.emplace_back([version](langutil::EVMVersion _version) {
|
|
|
|
return _version < version;
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case '=':
|
|
|
|
m_evmVersionRules.emplace_back([version](langutil::EVMVersion _version) {
|
|
|
|
return _version == version;
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case '!':
|
|
|
|
m_evmVersionRules.emplace_back([version](langutil::EVMVersion _version) {
|
|
|
|
return !(_version == version);
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
isTop = false;
|
2018-06-08 12:17:50 +00:00
|
|
|
source += line + "\n";
|
2019-03-15 16:22:04 +00:00
|
|
|
}
|
2018-06-08 12:17:50 +00:00
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestCase::expect(string::iterator& _it, string::iterator _end, string::value_type _c)
|
|
|
|
{
|
|
|
|
if (_it == _end || *_it != _c)
|
|
|
|
throw runtime_error(string("Invalid test expectation. Expected: \"") + _c + "\".");
|
|
|
|
++_it;
|
|
|
|
}
|