2018-03-06 19:45:34 +00:00
|
|
|
/*
|
|
|
|
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 <test/libsolidity/AnalysisFramework.h>
|
2018-11-25 00:02:32 +00:00
|
|
|
#include <test/TestCase.h>
|
2018-11-14 13:59:30 +00:00
|
|
|
#include <liblangutil/Exceptions.h>
|
2019-02-11 15:00:24 +00:00
|
|
|
#include <libdevcore/AnsiColorized.h>
|
2018-03-12 12:33:37 +00:00
|
|
|
|
|
|
|
#include <iosfwd>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <utility>
|
|
|
|
|
2018-03-06 19:45:34 +00:00
|
|
|
namespace dev
|
|
|
|
{
|
|
|
|
namespace solidity
|
|
|
|
{
|
|
|
|
namespace test
|
|
|
|
{
|
|
|
|
|
2018-04-03 10:05:26 +00:00
|
|
|
struct SyntaxTestError
|
2018-03-12 12:33:37 +00:00
|
|
|
{
|
|
|
|
std::string type;
|
|
|
|
std::string message;
|
2018-04-06 16:37:01 +00:00
|
|
|
int locationStart;
|
|
|
|
int locationEnd;
|
2018-04-03 10:05:26 +00:00
|
|
|
bool operator==(SyntaxTestError const& _rhs) const
|
|
|
|
{
|
2018-04-06 16:37:01 +00:00
|
|
|
return type == _rhs.type &&
|
|
|
|
message == _rhs.message &&
|
|
|
|
locationStart == _rhs.locationStart &&
|
|
|
|
locationEnd == _rhs.locationEnd;
|
2018-04-03 10:05:26 +00:00
|
|
|
}
|
2018-03-12 12:33:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-04-01 13:31:48 +00:00
|
|
|
class SyntaxTest: AnalysisFramework, public EVMVersionRestrictedTestCase
|
2018-03-06 19:45:34 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-02-06 11:10:05 +00:00
|
|
|
static std::unique_ptr<TestCase> create(Config const& _config)
|
2019-03-18 13:08:56 +00:00
|
|
|
{ return std::make_unique<SyntaxTest>(_config.filename, _config.evmVersion); }
|
|
|
|
SyntaxTest(std::string const& _filename, langutil::EVMVersion _evmVersion);
|
2018-03-12 12:33:37 +00:00
|
|
|
|
2019-03-18 13:08:56 +00:00
|
|
|
bool run(std::ostream& _stream, std::string const& _linePrefix = "", bool _formatted = false) override;
|
2018-03-12 12:57:48 +00:00
|
|
|
|
2019-03-18 13:08:56 +00:00
|
|
|
void printSource(std::ostream &_stream, std::string const &_linePrefix = "", bool _formatted = false) const override;
|
2018-11-16 01:09:04 +00:00
|
|
|
void printUpdatedExpectations(std::ostream& _stream, std::string const& _linePrefix) const override
|
2018-06-08 12:17:50 +00:00
|
|
|
{
|
|
|
|
if (!m_errorList.empty())
|
|
|
|
printErrorList(_stream, m_errorList, _linePrefix, false);
|
|
|
|
}
|
2018-03-12 12:57:48 +00:00
|
|
|
|
2018-06-08 12:17:50 +00:00
|
|
|
static std::string errorMessage(Exception const& _e);
|
2018-11-15 15:47:52 +00:00
|
|
|
protected:
|
2018-04-03 10:05:26 +00:00
|
|
|
static void printErrorList(
|
2018-03-12 12:33:37 +00:00
|
|
|
std::ostream& _stream,
|
2018-04-03 10:05:26 +00:00
|
|
|
std::vector<SyntaxTestError> const& _errors,
|
2018-03-12 12:57:48 +00:00
|
|
|
std::string const& _linePrefix,
|
2019-03-18 13:08:56 +00:00
|
|
|
bool _formatted = false
|
2018-04-03 10:05:26 +00:00
|
|
|
);
|
2018-03-12 12:33:37 +00:00
|
|
|
|
2019-03-18 13:08:56 +00:00
|
|
|
virtual bool printExpectationAndError(std::ostream& _stream, std::string const& _linePrefix = "", bool _formatted = false);
|
2018-11-15 15:47:52 +00:00
|
|
|
|
2018-04-03 10:05:26 +00:00
|
|
|
static std::vector<SyntaxTestError> parseExpectations(std::istream& _stream);
|
2018-03-12 12:33:37 +00:00
|
|
|
|
|
|
|
std::string m_source;
|
2018-04-03 10:05:26 +00:00
|
|
|
std::vector<SyntaxTestError> m_expectations;
|
|
|
|
std::vector<SyntaxTestError> m_errorList;
|
2019-03-15 16:22:04 +00:00
|
|
|
langutil::EVMVersion const m_evmVersion;
|
2018-03-06 19:45:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|