[isoltest] Moves error types to dedicated file.

This commit is contained in:
Erik Kundt 2019-07-21 15:46:03 +02:00
parent 9b375edfe3
commit a7a8ba73f9
4 changed files with 130 additions and 98 deletions

View File

@ -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.
*/

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <libdevcore/AnsiColorized.h>
#include <libdevcore/CommonData.h>
#include <libdevcore/Exceptions.h>
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<FormatError>;
/**
* 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;
};
}
}
}

View File

@ -15,7 +15,7 @@
#pragma once
#include <test/libsolidity/util/TestFileParser.h>
#include <test/TestCase.h>
#include <test/libsolidity/util/SoltestErrors.h>
#include <libsolidity/ast/Types.h>
#include <liblangutil/Exceptions.h>
@ -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<FormatError>;
/**
* 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

View File

@ -17,6 +17,7 @@
#include <test/libyul/YulOptimizerTest.h>
#include <test/libsolidity/util/SoltestErrors.h>
#include <test/Options.h>
#include <libyul/optimiser/BlockFlattener.h>