From 9c6f8c011fabc2d1c341db5c019dfcc62c0fffdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Mon, 26 Apr 2021 22:13:41 +0200 Subject: [PATCH] TestCaseReader: Add enumSetting() --- test/TestCaseReader.cpp | 8 +------- test/TestCaseReader.h | 31 +++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/test/TestCaseReader.cpp b/test/TestCaseReader.cpp index 26b625734..decfa3cbc 100644 --- a/test/TestCaseReader.cpp +++ b/test/TestCaseReader.cpp @@ -18,18 +18,12 @@ #include -#include -#include #include #include -#include #include -#include - using namespace std; -using namespace solidity::langutil; using namespace solidity::frontend::test; namespace fs = boost::filesystem; @@ -162,7 +156,7 @@ pair TestCaseReader::parseSourcesAndSettingsWithLineNumber(is else externalSourceName = externalSourceString; - solAssert(!externalSourceName.empty(), ""); + soltestAssert(!externalSourceName.empty(), ""); fs::path externalSourceTarget(externalSourceString); fs::path testCaseParentDir = m_fileName.parent_path(); if (!externalSourceTarget.is_relative()) diff --git a/test/TestCaseReader.h b/test/TestCaseReader.h index 2d0ffe3b0..d1ef95be3 100644 --- a/test/TestCaseReader.h +++ b/test/TestCaseReader.h @@ -16,13 +16,21 @@ */ // SPDX-License-Identifier: GPL-3.0 +#pragma once + +#include + +#include + +#include + #include +#include + #include #include #include -#pragma once - namespace solidity::frontend::test { @@ -58,6 +66,9 @@ public: size_t sizetSetting(std::string const& _name, size_t _defaultValue); std::string stringSetting(std::string const& _name, std::string const& _defaultValue); + template + E enumSetting(std::string const& _name, std::map const& _choices, std::string const& _defaultChoice); + void ensureAllSettingsRead() const; private: @@ -71,4 +82,20 @@ private: std::map m_settings; std::map m_unreadSettings; ///< tracks which settings are left unread }; + +template +E TestCaseReader::enumSetting(std::string const& _name, std::map 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); +} + }