/*
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 .
*/
#include
#include
#include
#include
#include
using namespace std;
using namespace solidity::frontend::test;
TestCaseReader::TestCaseReader(string const& _filename):
m_file(_filename)
{
if (!m_file)
BOOST_THROW_EXCEPTION(runtime_error("Cannot open file: \"" + _filename + "\"."));
m_file.exceptions(ios::badbit);
tie(m_sources, m_lineNumber) = parseSourcesAndSettingsWithLineNumber(m_file);
m_unreadSettings = m_settings;
}
string const& TestCaseReader::source()
{
if (m_sources.size() != 1)
BOOST_THROW_EXCEPTION(runtime_error("Expected single source definition, but got multiple sources."));
return m_sources.begin()->second;
}
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))
return _defaultValue;
m_unreadSettings.erase(_name);
string value = m_settings.at(_name);
if (value == "false")
return false;
if (value == "true")
return true;
BOOST_THROW_EXCEPTION(runtime_error("Invalid Boolean value: " + value + "."));
}
size_t TestCaseReader::sizetSetting(std::string const& _name, size_t _defaultValue)
{
if (!hasSetting(_name))
return _defaultValue;
m_unreadSettings.erase(_name);
static_assert(sizeof(unsigned long) <= sizeof(size_t));
return stoul(m_settings.at(_name));
}
string TestCaseReader::stringSetting(string const& _name, string const& _defaultValue)
{
if (!hasSetting(_name))
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())
throw runtime_error(
"Unknown setting(s): " +
util::joinHumanReadable(m_unreadSettings | boost::adaptors::map_keys)
);
}
pair