mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Adapts tests/ to use AnsiColorized (the generalized/moved version of FormattedScope, which in turn is removed in this PR)
This commit is contained in:
parent
49cd55d3a0
commit
53f9be8a23
@ -17,6 +17,7 @@
|
||||
|
||||
#include <test/libsolidity/ASTJSONTest.h>
|
||||
#include <test/Options.h>
|
||||
#include <libdevcore/AnsiColorized.h>
|
||||
#include <libsolidity/ast/ASTJsonConverter.h>
|
||||
#include <libsolidity/interface/CompilerStack.h>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
@ -26,10 +27,10 @@
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace dev;
|
||||
using namespace solidity;
|
||||
using namespace dev::solidity;
|
||||
using namespace dev::solidity::test;
|
||||
using namespace dev::solidity::test::formatting;
|
||||
using namespace dev::formatting;
|
||||
using namespace dev;
|
||||
using namespace std;
|
||||
namespace fs = boost::filesystem;
|
||||
using namespace boost::unit_test;
|
||||
@ -116,7 +117,7 @@ bool ASTJSONTest::run(ostream& _stream, string const& _linePrefix, bool const _f
|
||||
if (m_expectation != m_result)
|
||||
{
|
||||
string nextIndentLevel = _linePrefix + " ";
|
||||
FormattedScope(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Expected result:" << endl;
|
||||
AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Expected result:" << endl;
|
||||
{
|
||||
istringstream stream(m_expectation);
|
||||
string line;
|
||||
@ -124,7 +125,7 @@ bool ASTJSONTest::run(ostream& _stream, string const& _linePrefix, bool const _f
|
||||
_stream << nextIndentLevel << line << endl;
|
||||
}
|
||||
_stream << endl;
|
||||
FormattedScope(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Obtained result:" << endl;
|
||||
AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Obtained result:" << endl;
|
||||
{
|
||||
istringstream stream(m_result);
|
||||
string line;
|
||||
@ -148,7 +149,7 @@ bool ASTJSONTest::run(ostream& _stream, string const& _linePrefix, bool const _f
|
||||
if (m_expectationLegacy != m_resultLegacy)
|
||||
{
|
||||
string nextIndentLevel = _linePrefix + " ";
|
||||
FormattedScope(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Expected result (legacy):" << endl;
|
||||
AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Expected result (legacy):" << endl;
|
||||
{
|
||||
istringstream stream(m_expectationLegacy);
|
||||
string line;
|
||||
@ -156,7 +157,7 @@ bool ASTJSONTest::run(ostream& _stream, string const& _linePrefix, bool const _f
|
||||
_stream << nextIndentLevel << line << endl;
|
||||
}
|
||||
_stream << endl;
|
||||
FormattedScope(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Obtained result (legacy):" << endl;
|
||||
AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Obtained result (legacy):" << endl;
|
||||
{
|
||||
istringstream stream(m_resultLegacy);
|
||||
string line;
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <test/libsolidity/FormattedScope.h>
|
||||
#include <libdevcore/AnsiColorized.h>
|
||||
#include <test/TestCase.h>
|
||||
|
||||
#include <iosfwd>
|
||||
|
@ -1,68 +0,0 @@
|
||||
/*
|
||||
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 <boost/noncopyable.hpp>
|
||||
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
|
||||
namespace dev
|
||||
{
|
||||
namespace solidity
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
namespace formatting
|
||||
{
|
||||
|
||||
static constexpr char const* RESET = "\033[0m";
|
||||
static constexpr char const* RED = "\033[1;31m";
|
||||
static constexpr char const* GREEN = "\033[1;32m";
|
||||
static constexpr char const* YELLOW = "\033[1;33m";
|
||||
static constexpr char const* CYAN = "\033[1;36m";
|
||||
static constexpr char const* BOLD = "\033[1m";
|
||||
static constexpr char const* RED_BACKGROUND = "\033[48;5;160m";
|
||||
static constexpr char const* ORANGE_BACKGROUND = "\033[48;5;166m";
|
||||
static constexpr char const* INVERSE = "\033[7m";
|
||||
|
||||
}
|
||||
|
||||
class FormattedScope: boost::noncopyable
|
||||
{
|
||||
public:
|
||||
/// @arg _formatting List of formatting strings (e.g. colors) defined in the formatting namespace.
|
||||
FormattedScope(std::ostream& _stream, bool const _enabled, std::vector<char const*> const& _formatting):
|
||||
m_stream(_stream), m_enabled(_enabled)
|
||||
{
|
||||
if (m_enabled)
|
||||
for (auto const& format: _formatting)
|
||||
m_stream << format;
|
||||
}
|
||||
~FormattedScope() { if (m_enabled) m_stream << formatting::RESET; }
|
||||
template<typename T>
|
||||
std::ostream& operator<<(T&& _t) { return m_stream << std::forward<T>(_t); }
|
||||
private:
|
||||
std::ostream& m_stream;
|
||||
bool m_enabled;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -28,10 +28,10 @@
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
|
||||
using namespace dev;
|
||||
using namespace solidity;
|
||||
using namespace dev::solidity::test;
|
||||
using namespace dev::solidity::test::formatting;
|
||||
using namespace dev::solidity;
|
||||
using namespace dev::formatting;
|
||||
using namespace dev;
|
||||
using namespace std;
|
||||
using namespace boost::unit_test;
|
||||
|
||||
|
@ -24,11 +24,11 @@
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace dev;
|
||||
using namespace langutil;
|
||||
using namespace solidity;
|
||||
using namespace dev::solidity;
|
||||
using namespace dev::solidity::test;
|
||||
using namespace dev::solidity::test::formatting;
|
||||
using namespace dev::formatting;
|
||||
using namespace dev;
|
||||
using namespace std;
|
||||
namespace fs = boost::filesystem;
|
||||
using namespace boost::unit_test;
|
||||
@ -100,9 +100,9 @@ bool SyntaxTest::printExpectationAndError(ostream& _stream, string const& _lineP
|
||||
if (m_expectations != m_errorList)
|
||||
{
|
||||
string nextIndentLevel = _linePrefix + " ";
|
||||
FormattedScope(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Expected result:" << endl;
|
||||
AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Expected result:" << endl;
|
||||
printErrorList(_stream, m_expectations, nextIndentLevel, _formatted);
|
||||
FormattedScope(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Obtained result:" << endl;
|
||||
AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Obtained result:" << endl;
|
||||
printErrorList(_stream, m_errorList, nextIndentLevel, _formatted);
|
||||
return false;
|
||||
}
|
||||
@ -127,7 +127,7 @@ void SyntaxTest::printSource(ostream& _stream, string const& _linePrefix, bool c
|
||||
if (isWarning)
|
||||
{
|
||||
if (sourceFormatting[i] == formatting::RESET)
|
||||
sourceFormatting[i] = formatting::ORANGE_BACKGROUND;
|
||||
sourceFormatting[i] = formatting::ORANGE_BACKGROUND_256;
|
||||
}
|
||||
else
|
||||
sourceFormatting[i] = formatting::RED_BACKGROUND;
|
||||
@ -166,12 +166,12 @@ void SyntaxTest::printErrorList(
|
||||
)
|
||||
{
|
||||
if (_errorList.empty())
|
||||
FormattedScope(_stream, _formatted, {BOLD, GREEN}) << _linePrefix << "Success" << endl;
|
||||
AnsiColorized(_stream, _formatted, {BOLD, GREEN}) << _linePrefix << "Success" << endl;
|
||||
else
|
||||
for (auto const& error: _errorList)
|
||||
{
|
||||
{
|
||||
FormattedScope scope(_stream, _formatted, {BOLD, (error.type == "Warning") ? YELLOW : RED});
|
||||
AnsiColorized scope(_stream, _formatted, {BOLD, (error.type == "Warning") ? YELLOW : RED});
|
||||
_stream << _linePrefix;
|
||||
_stream << error.type << ": ";
|
||||
}
|
||||
|
@ -18,9 +18,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <test/libsolidity/AnalysisFramework.h>
|
||||
#include <test/libsolidity/FormattedScope.h>
|
||||
#include <test/TestCase.h>
|
||||
#include <liblangutil/Exceptions.h>
|
||||
#include <libdevcore/AnsiColorized.h>
|
||||
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
#include <test/libyul/ObjectCompilerTest.h>
|
||||
|
||||
#include <test/libsolidity/FormattedScope.h>
|
||||
#include <libdevcore/AnsiColorized.h>
|
||||
|
||||
#include <libsolidity/interface/AssemblyStack.h>
|
||||
|
||||
@ -67,7 +67,7 @@ bool ObjectCompilerTest::run(ostream& _stream, string const& _linePrefix, bool c
|
||||
AssemblyStack stack(EVMVersion(), AssemblyStack::Language::StrictAssembly);
|
||||
if (!stack.parseAndAnalyze("source", m_source))
|
||||
{
|
||||
FormattedScope(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Error parsing source." << endl;
|
||||
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Error parsing source." << endl;
|
||||
printErrors(_stream, stack.errors());
|
||||
return false;
|
||||
}
|
||||
@ -91,9 +91,9 @@ bool ObjectCompilerTest::run(ostream& _stream, string const& _linePrefix, bool c
|
||||
if (m_expectation != m_obtainedResult)
|
||||
{
|
||||
string nextIndentLevel = _linePrefix + " ";
|
||||
FormattedScope(_stream, _formatted, {formatting::BOLD, formatting::CYAN}) << _linePrefix << "Expected result:" << endl;
|
||||
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::CYAN}) << _linePrefix << "Expected result:" << endl;
|
||||
printIndented(_stream, m_expectation, nextIndentLevel);
|
||||
FormattedScope(_stream, _formatted, {formatting::BOLD, formatting::CYAN}) << _linePrefix << "Obtained result:" << endl;
|
||||
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::CYAN}) << _linePrefix << "Obtained result:" << endl;
|
||||
printIndented(_stream, m_obtainedResult, nextIndentLevel);
|
||||
return false;
|
||||
}
|
||||
|
@ -17,8 +17,6 @@
|
||||
|
||||
#include <test/libyul/YulOptimizerTest.h>
|
||||
|
||||
#include <test/libsolidity/FormattedScope.h>
|
||||
|
||||
#include <test/Options.h>
|
||||
|
||||
#include <libyul/optimiser/BlockFlattener.h>
|
||||
@ -52,6 +50,8 @@
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
#include <liblangutil/Scanner.h>
|
||||
|
||||
#include <libdevcore/AnsiColorized.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
@ -245,7 +245,7 @@ bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool con
|
||||
OptimiserSuite::run(*m_dialect, *m_ast, *m_analysisInfo);
|
||||
else
|
||||
{
|
||||
FormattedScope(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Invalid optimizer step: " << m_optimizerStep << endl;
|
||||
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Invalid optimizer step: " << m_optimizerStep << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -254,10 +254,10 @@ bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool con
|
||||
if (m_expectation != m_obtainedResult)
|
||||
{
|
||||
string nextIndentLevel = _linePrefix + " ";
|
||||
FormattedScope(_stream, _formatted, {formatting::BOLD, formatting::CYAN}) << _linePrefix << "Expected result:" << endl;
|
||||
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::CYAN}) << _linePrefix << "Expected result:" << endl;
|
||||
// TODO could compute a simple diff with highlighted lines
|
||||
printIndented(_stream, m_expectation, nextIndentLevel);
|
||||
FormattedScope(_stream, _formatted, {formatting::BOLD, formatting::CYAN}) << _linePrefix << "Obtained result:" << endl;
|
||||
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::CYAN}) << _linePrefix << "Obtained result:" << endl;
|
||||
printIndented(_stream, m_obtainedResult, nextIndentLevel);
|
||||
return false;
|
||||
}
|
||||
@ -291,7 +291,7 @@ bool YulOptimizerTest::parse(ostream& _stream, string const& _linePrefix, bool c
|
||||
m_ast = yul::Parser(errorReporter, m_dialect).parse(scanner, false);
|
||||
if (!m_ast || !errorReporter.errors().empty())
|
||||
{
|
||||
FormattedScope(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Error parsing source." << endl;
|
||||
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Error parsing source." << endl;
|
||||
printErrors(_stream, errorReporter.errors());
|
||||
return false;
|
||||
}
|
||||
@ -305,7 +305,7 @@ bool YulOptimizerTest::parse(ostream& _stream, string const& _linePrefix, bool c
|
||||
);
|
||||
if (!analyzer.analyze(*m_ast) || !errorReporter.errors().empty())
|
||||
{
|
||||
FormattedScope(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Error analyzing source." << endl;
|
||||
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Error analyzing source." << endl;
|
||||
printErrors(_stream, errorReporter.errors());
|
||||
return false;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
*/
|
||||
|
||||
#include <libdevcore/CommonIO.h>
|
||||
#include <libdevcore/AnsiColorized.h>
|
||||
|
||||
#include <test/Common.h>
|
||||
#include <test/libsolidity/AnalysisFramework.h>
|
||||
@ -38,7 +39,7 @@
|
||||
using namespace dev;
|
||||
using namespace dev::solidity;
|
||||
using namespace dev::solidity::test;
|
||||
using namespace dev::solidity::test::formatting;
|
||||
using namespace dev::formatting;
|
||||
using namespace std;
|
||||
namespace po = boost::program_options;
|
||||
namespace fs = boost::filesystem;
|
||||
@ -110,7 +111,7 @@ TestTool::Result TestTool::process()
|
||||
bool success;
|
||||
std::stringstream outputMessages;
|
||||
|
||||
(FormattedScope(cout, m_formatted, {BOLD}) << m_name << ": ").flush();
|
||||
(AnsiColorized(cout, m_formatted, {BOLD}) << m_name << ": ").flush();
|
||||
|
||||
try
|
||||
{
|
||||
@ -119,33 +120,33 @@ TestTool::Result TestTool::process()
|
||||
}
|
||||
catch(boost::exception const& _e)
|
||||
{
|
||||
FormattedScope(cout, m_formatted, {BOLD, RED}) <<
|
||||
AnsiColorized(cout, m_formatted, {BOLD, RED}) <<
|
||||
"Exception during syntax test: " << boost::diagnostic_information(_e) << endl;
|
||||
return Result::Exception;
|
||||
}
|
||||
catch (std::exception const& _e)
|
||||
{
|
||||
FormattedScope(cout, m_formatted, {BOLD, RED}) <<
|
||||
AnsiColorized(cout, m_formatted, {BOLD, RED}) <<
|
||||
"Exception during syntax test: " << _e.what() << endl;
|
||||
return Result::Exception;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
FormattedScope(cout, m_formatted, {BOLD, RED}) <<
|
||||
AnsiColorized(cout, m_formatted, {BOLD, RED}) <<
|
||||
"Unknown exception during syntax test." << endl;
|
||||
return Result::Exception;
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
FormattedScope(cout, m_formatted, {BOLD, GREEN}) << "OK" << endl;
|
||||
AnsiColorized(cout, m_formatted, {BOLD, GREEN}) << "OK" << endl;
|
||||
return Result::Success;
|
||||
}
|
||||
else
|
||||
{
|
||||
FormattedScope(cout, m_formatted, {BOLD, RED}) << "FAIL" << endl;
|
||||
AnsiColorized(cout, m_formatted, {BOLD, RED}) << "FAIL" << endl;
|
||||
|
||||
FormattedScope(cout, m_formatted, {BOLD, CYAN}) << " Contract:" << endl;
|
||||
AnsiColorized(cout, m_formatted, {BOLD, CYAN}) << " Contract:" << endl;
|
||||
m_test->printSource(cout, " ", m_formatted);
|
||||
|
||||
cout << endl << outputMessages.str() << endl;
|
||||
@ -305,7 +306,7 @@ boost::optional<TestStats> runTestSuite(
|
||||
TestStats stats = TestTool::processPath(_testCaseCreator, _basePath, _subdirectory, _formatted);
|
||||
|
||||
cout << endl << _name << " Test Summary: ";
|
||||
FormattedScope(cout, _formatted, {BOLD, stats ? GREEN : RED}) <<
|
||||
AnsiColorized(cout, _formatted, {BOLD, stats ? GREEN : RED}) <<
|
||||
stats.successCount <<
|
||||
"/" <<
|
||||
stats.testCount;
|
||||
@ -389,7 +390,7 @@ Allowed options)",
|
||||
}
|
||||
|
||||
cout << endl << "Summary: ";
|
||||
FormattedScope(cout, formatted, {BOLD, global_stats ? GREEN : RED}) <<
|
||||
AnsiColorized(cout, formatted, {BOLD, global_stats ? GREEN : RED}) <<
|
||||
global_stats.successCount << "/" << global_stats.testCount;
|
||||
cout << " tests successful." << endl;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user