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-03-12 12:57:48 +00:00
|
|
|
#include <test/libsolidity/FormattedScope.h>
|
2018-06-08 12:17:50 +00:00
|
|
|
#include <test/libsolidity/TestCase.h>
|
2018-11-14 13:59:30 +00:00
|
|
|
#include <liblangutil/Exceptions.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
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-06-08 12:17:50 +00:00
|
|
|
class SyntaxTest: AnalysisFramework, public TestCase
|
2018-03-06 19:45:34 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-06-08 12:17:50 +00:00
|
|
|
static std::unique_ptr<TestCase> create(std::string const& _filename)
|
|
|
|
{ return std::unique_ptr<TestCase>(new SyntaxTest(_filename)); }
|
2018-03-12 12:33:37 +00:00
|
|
|
SyntaxTest(std::string const& _filename);
|
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
bool run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) override;
|
2018-03-12 12:57:48 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
void printSource(std::ostream &_stream, std::string const &_linePrefix = "", bool const _formatted = false) const override;
|
|
|
|
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);
|
|
|
|
private:
|
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,
|
|
|
|
bool const _formatted = false
|
2018-04-03 10:05:26 +00:00
|
|
|
);
|
2018-03-12 12:33:37 +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;
|
2018-03-06 19:45:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|