mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
TestCaseReader: Add enumSetting()
This commit is contained in:
parent
5023cef382
commit
9c6f8c011f
@ -18,18 +18,12 @@
|
|||||||
|
|
||||||
#include <test/TestCaseReader.h>
|
#include <test/TestCaseReader.h>
|
||||||
|
|
||||||
#include <libsolidity/parsing/Parser.h>
|
|
||||||
#include <libsolutil/StringUtils.h>
|
|
||||||
#include <libsolutil/CommonIO.h>
|
#include <libsolutil/CommonIO.h>
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <boost/throw_exception.hpp>
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
#include <range/v3/view/map.hpp>
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace solidity::langutil;
|
|
||||||
using namespace solidity::frontend::test;
|
using namespace solidity::frontend::test;
|
||||||
|
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
@ -162,7 +156,7 @@ pair<SourceMap, size_t> TestCaseReader::parseSourcesAndSettingsWithLineNumber(is
|
|||||||
else
|
else
|
||||||
externalSourceName = externalSourceString;
|
externalSourceName = externalSourceString;
|
||||||
|
|
||||||
solAssert(!externalSourceName.empty(), "");
|
soltestAssert(!externalSourceName.empty(), "");
|
||||||
fs::path externalSourceTarget(externalSourceString);
|
fs::path externalSourceTarget(externalSourceString);
|
||||||
fs::path testCaseParentDir = m_fileName.parent_path();
|
fs::path testCaseParentDir = m_fileName.parent_path();
|
||||||
if (!externalSourceTarget.is_relative())
|
if (!externalSourceTarget.is_relative())
|
||||||
|
@ -16,13 +16,21 @@
|
|||||||
*/
|
*/
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <test/libsolidity/util/SoltestErrors.h>
|
||||||
|
|
||||||
|
#include <libsolutil/StringUtils.h>
|
||||||
|
|
||||||
|
#include <range/v3/view/map.hpp>
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
#include <boost/throw_exception.hpp>
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
namespace solidity::frontend::test
|
namespace solidity::frontend::test
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -58,6 +66,9 @@ public:
|
|||||||
size_t sizetSetting(std::string const& _name, size_t _defaultValue);
|
size_t sizetSetting(std::string const& _name, size_t _defaultValue);
|
||||||
std::string stringSetting(std::string const& _name, std::string const& _defaultValue);
|
std::string stringSetting(std::string const& _name, std::string const& _defaultValue);
|
||||||
|
|
||||||
|
template <typename E>
|
||||||
|
E enumSetting(std::string const& _name, std::map<std::string, E> const& _choices, std::string const& _defaultChoice);
|
||||||
|
|
||||||
void ensureAllSettingsRead() const;
|
void ensureAllSettingsRead() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -71,4 +82,20 @@ private:
|
|||||||
std::map<std::string, std::string> m_settings;
|
std::map<std::string, std::string> m_settings;
|
||||||
std::map<std::string, std::string> m_unreadSettings; ///< tracks which settings are left unread
|
std::map<std::string, std::string> m_unreadSettings; ///< tracks which settings are left unread
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename E>
|
||||||
|
E TestCaseReader::enumSetting(std::string const& _name, std::map<std::string, E> const& _choices, std::string const& _defaultChoice)
|
||||||
|
{
|
||||||
|
soltestAssert(_choices.count(_defaultChoice) > 0, "");
|
||||||
|
|
||||||
|
std::string value = stringSetting(_name, _defaultChoice);
|
||||||
|
|
||||||
|
if (_choices.count(value) == 0)
|
||||||
|
BOOST_THROW_EXCEPTION(std::runtime_error(
|
||||||
|
"Invalid Enum value: " + value + ". Available choices: " + util::joinHumanReadable(_choices | ranges::views::keys) + "."
|
||||||
|
));
|
||||||
|
|
||||||
|
return _choices.at(value);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user