From a7a8ba73f9d75f18b6ca22f92aaeb3bcf0f8c811 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Sun, 21 Jul 2019 15:46:03 +0200 Subject: [PATCH] [isoltest] Moves error types to dedicated file. --- test/TestCase.h | 8 -- test/libsolidity/util/SoltestErrors.h | 128 +++++++++++++++++++++++ test/libsolidity/util/TestFunctionCall.h | 91 +--------------- test/libyul/YulOptimizerTest.cpp | 1 + 4 files changed, 130 insertions(+), 98 deletions(-) create mode 100644 test/libsolidity/util/SoltestErrors.h diff --git a/test/TestCase.h b/test/TestCase.h index 4a9c728ca..7b3ab5fa6 100644 --- a/test/TestCase.h +++ b/test/TestCase.h @@ -35,14 +35,6 @@ namespace solidity namespace test { -#define soltestAssert(CONDITION, DESCRIPTION) \ - do \ - { \ - if (!(CONDITION)) \ - BOOST_THROW_EXCEPTION(runtime_error(DESCRIPTION)); \ - } \ - while (false) - /** * Common superclass of anything that can be run via isoltest. */ diff --git a/test/libsolidity/util/SoltestErrors.h b/test/libsolidity/util/SoltestErrors.h new file mode 100644 index 000000000..23b5afc42 --- /dev/null +++ b/test/libsolidity/util/SoltestErrors.h @@ -0,0 +1,128 @@ +/* + 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 . +*/ + +#pragma once + +#include +#include +#include + +namespace dev +{ +namespace solidity +{ +namespace test +{ + +#define soltestAssert(CONDITION, DESCRIPTION) \ + do \ + { \ + if (!(CONDITION)) \ + BOOST_THROW_EXCEPTION(runtime_error(DESCRIPTION)); \ + } \ + while (false) + + +/** + * Representation of a notice, warning or error that can occur while + * formatting and therefore updating an interactive function call test. + */ +struct FormatError +{ + enum Type + { + Notice, + Warning, + Error + }; + + explicit FormatError(Type _type, std::string _message): + type(_type), + message(std::move(_message)) + {} + + Type type; + std::string message; +}; +using FormatErrors = std::vector; + +/** + * Utility class that collects notices, warnings and errors and is able + * to format them for ANSI colorized output during the interactive update + * process in isoltest. + * Its purpose is to help users of isoltest to automatically + * update test files and always keep track of what is happening. + */ +class ErrorReporter +{ +public: + explicit ErrorReporter() {} + + /// Adds a new FormatError of type Notice with the given message. + void notice(std::string _notice) + { + m_errors.push_back(FormatError{FormatError::Notice, std::move(_notice)}); + } + + /// Adds a new FormatError of type Warning with the given message. + void warning(std::string _warning) + { + m_errors.push_back(FormatError{FormatError::Warning, std::move(_warning)}); + } + + /// Adds a new FormatError of type Error with the given message. + void error(std::string _error) + { + m_errors.push_back(FormatError{FormatError::Error, std::move(_error)}); + } + + /// Prints all errors depending on their type using ANSI colorized output. + /// It will be used to print notices, warnings and errors during the + /// interactive update process. + std::string format(std::string const& _linePrefix, bool _formatted) + { + std::stringstream os; + for (auto const& error: m_errors) + { + switch (error.type) + { + case FormatError::Notice: + + break; + case FormatError::Warning: + AnsiColorized( + os, + _formatted, + {formatting::YELLOW} + ) << _linePrefix << "Warning: " << error.message << std::endl; + break; + case FormatError::Error: + AnsiColorized( + os, + _formatted, + {formatting::RED} + ) << _linePrefix << "Error: " << error.message << std::endl; + break; + } + } + return os.str(); + } + +private: + FormatErrors m_errors; +}; + +} +} +} diff --git a/test/libsolidity/util/TestFunctionCall.h b/test/libsolidity/util/TestFunctionCall.h index 1d8bc9e98..9a49777fd 100644 --- a/test/libsolidity/util/TestFunctionCall.h +++ b/test/libsolidity/util/TestFunctionCall.h @@ -15,7 +15,7 @@ #pragma once #include -#include +#include #include #include @@ -37,95 +37,6 @@ namespace solidity namespace test { -/** - * Representation of a notice, warning or error that can occur while - * formatting and therefore updating an interactive function call test. - */ -struct FormatError -{ - enum Type - { - Notice, - Warning, - Error - }; - - explicit FormatError(Type _type, std::string _message): - type(_type), - message(std::move(_message)) - {} - - Type type; - std::string message; -}; -using FormatErrors = std::vector; - -/** - * Utility class that collects notices, warnings and errors and is able - * to format them for ANSI colorized output during the interactive update - * process in isoltest. - * Its purpose is to help users of isoltest to automatically - * update test files and always keep track of what is happening. - */ -class ErrorReporter -{ -public: - explicit ErrorReporter() {} - - /// Adds a new FormatError of type Notice with the given message. - void notice(std::string _notice) - { - m_errors.push_back(FormatError{FormatError::Notice, std::move(_notice)}); - } - - /// Adds a new FormatError of type Warning with the given message. - void warning(std::string _warning) - { - m_errors.push_back(FormatError{FormatError::Warning, std::move(_warning)}); - } - - /// Adds a new FormatError of type Error with the given message. - void error(std::string _error) - { - m_errors.push_back(FormatError{FormatError::Error, std::move(_error)}); - } - - /// Prints all errors depending on their type using ANSI colorized output. - /// It will be used to print notices, warnings and errors during the - /// interactive update process. - std::string format(std::string const& _linePrefix, bool _formatted) - { - std::stringstream os; - for (auto const& error: m_errors) - { - switch (error.type) - { - case FormatError::Notice: - - break; - case FormatError::Warning: - AnsiColorized( - os, - _formatted, - {formatting::YELLOW} - ) << _linePrefix << "Warning: " << error.message << std::endl; - break; - case FormatError::Error: - AnsiColorized( - os, - _formatted, - {formatting::RED} - ) << _linePrefix << "Error: " << error.message << std::endl; - break; - } - } - return os.str(); - } - -private: - FormatErrors m_errors; -}; - /** * Represents a function call and the result it returned. It stores the call * representation itself, the actual byte result (if any) and a string representation diff --git a/test/libyul/YulOptimizerTest.cpp b/test/libyul/YulOptimizerTest.cpp index 074b9b02a..019536b9d 100644 --- a/test/libyul/YulOptimizerTest.cpp +++ b/test/libyul/YulOptimizerTest.cpp @@ -17,6 +17,7 @@ #include +#include #include #include