2018-06-08 12:17:50 +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/>.
|
|
|
|
*/
|
2020-07-17 14:54:12 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
2018-06-08 12:17:50 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-03-06 00:22:51 +00:00
|
|
|
#include <test/TestCaseReader.h>
|
|
|
|
|
2019-03-15 16:22:04 +00:00
|
|
|
#include <liblangutil/EVMVersion.h>
|
|
|
|
|
2018-06-08 12:17:50 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2019-12-23 15:50:30 +00:00
|
|
|
namespace solidity::frontend::test
|
2018-06-08 12:17:50 +00:00
|
|
|
{
|
|
|
|
|
2019-04-01 13:31:48 +00:00
|
|
|
/**
|
|
|
|
* Common superclass of anything that can be run via isoltest.
|
|
|
|
*/
|
2018-06-08 12:17:50 +00:00
|
|
|
class TestCase
|
|
|
|
{
|
|
|
|
public:
|
2019-02-06 11:10:05 +00:00
|
|
|
struct Config
|
|
|
|
{
|
|
|
|
std::string filename;
|
2019-03-15 16:22:04 +00:00
|
|
|
langutil::EVMVersion evmVersion;
|
2022-11-22 12:05:20 +00:00
|
|
|
std::optional<uint8_t> eofVersion;
|
2020-06-05 23:10:48 +00:00
|
|
|
std::vector<boost::filesystem::path> vmPaths;
|
2021-01-29 13:07:22 +00:00
|
|
|
bool enforceGasCost = false;
|
|
|
|
u256 enforceGasCostMinValue;
|
2019-02-06 11:10:05 +00:00
|
|
|
};
|
|
|
|
|
2019-05-07 13:33:22 +00:00
|
|
|
enum class TestResult { Success, Failure, FatalError };
|
|
|
|
|
2019-02-06 11:10:05 +00:00
|
|
|
using TestCaseCreator = std::unique_ptr<TestCase>(*)(Config const&);
|
2018-06-08 12:17:50 +00:00
|
|
|
|
2018-12-12 13:51:22 +00:00
|
|
|
virtual ~TestCase() = default;
|
2018-06-08 12:17:50 +00:00
|
|
|
|
|
|
|
/// Runs the test case.
|
|
|
|
/// Outputs error messages to @arg _stream. Each line of output is prefixed with @arg _linePrefix.
|
|
|
|
/// Optionally, color-coding can be enabled (if @arg _formatted is set to true).
|
|
|
|
/// @returns true, if the test case succeeds, false otherwise
|
2019-05-07 13:33:22 +00:00
|
|
|
virtual TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) = 0;
|
2018-06-08 12:17:50 +00:00
|
|
|
|
|
|
|
/// Outputs the test contract to @arg _stream.
|
|
|
|
/// Each line of output is prefixed with @arg _linePrefix.
|
|
|
|
/// If @arg _formatted is true, color-coding may be used to indicate
|
|
|
|
/// error locations in the contract, if applicable.
|
2020-05-25 13:31:24 +00:00
|
|
|
virtual void printSource(std::ostream &_stream, std::string const &_linePrefix = "", bool const _formatted = false) const;
|
2020-03-19 01:48:42 +00:00
|
|
|
/// Outputs settings.
|
|
|
|
virtual void printSettings(std::ostream &_stream, std::string const &_linePrefix = "", bool const _formatted = false);
|
2020-04-17 20:24:33 +00:00
|
|
|
/// Outputs updated settings
|
|
|
|
virtual void printUpdatedSettings(std::ostream& _stream, std::string const& _linePrefix = "");
|
2018-06-08 12:17:50 +00:00
|
|
|
/// Outputs test expectations to @arg _stream that match the actual results of the test.
|
|
|
|
/// Each line of output is prefixed with @arg _linePrefix.
|
2020-05-25 13:31:24 +00:00
|
|
|
virtual void printUpdatedExpectations(std::ostream& _stream, std::string const& _linePrefix) const;
|
2018-06-08 12:17:50 +00:00
|
|
|
|
|
|
|
static bool isTestFilename(boost::filesystem::path const& _filename);
|
|
|
|
|
2019-04-01 13:31:48 +00:00
|
|
|
/// Returns true, if the test case is supported in the current environment and false
|
|
|
|
/// otherwise which causes this test to be skipped.
|
|
|
|
/// This might check e.g. for restrictions on the EVM version.
|
2020-03-06 00:22:51 +00:00
|
|
|
/// The function throws an exception if there are unread settings.
|
2020-02-18 16:13:13 +00:00
|
|
|
bool shouldRun();
|
2019-03-15 16:22:04 +00:00
|
|
|
|
2018-06-08 12:17:50 +00:00
|
|
|
protected:
|
2020-03-06 00:22:51 +00:00
|
|
|
// Used by ASTJSONTest, the only TestCase class with a custom parser of the test files.
|
|
|
|
TestCase() = default;
|
|
|
|
|
|
|
|
TestCase(std::string const& _filename): m_reader(_filename) {}
|
2018-06-08 12:17:50 +00:00
|
|
|
|
2020-03-06 00:22:51 +00:00
|
|
|
static void expect(std::string::iterator& _it, std::string::iterator _end, std::string::value_type _c);
|
2019-06-11 12:05:45 +00:00
|
|
|
|
2018-06-08 12:17:50 +00:00
|
|
|
template<typename IteratorType>
|
|
|
|
static void skipWhitespace(IteratorType& _it, IteratorType _end)
|
|
|
|
{
|
2022-03-04 09:15:57 +00:00
|
|
|
while (_it != _end && std::isspace<char>(*_it, std::locale::classic()))
|
2018-06-08 12:17:50 +00:00
|
|
|
++_it;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename IteratorType>
|
|
|
|
static void skipSlashes(IteratorType& _it, IteratorType _end)
|
|
|
|
{
|
|
|
|
while (_it != _end && *_it == '/')
|
|
|
|
++_it;
|
|
|
|
}
|
2019-04-01 13:31:48 +00:00
|
|
|
|
2020-04-23 11:16:10 +00:00
|
|
|
void printIndented(std::ostream& _stream, std::string const& _output, std::string const& _linePrefix = "") const;
|
2020-05-25 13:31:24 +00:00
|
|
|
TestCase::TestResult checkResult(std::ostream& _stream, const std::string& _linePrefix, bool const _formatted);
|
|
|
|
|
|
|
|
std::string m_source;
|
|
|
|
std::string m_obtainedResult;
|
|
|
|
std::string m_expectation;
|
2020-04-23 11:16:10 +00:00
|
|
|
|
2020-03-06 00:22:51 +00:00
|
|
|
TestCaseReader m_reader;
|
2020-02-18 16:13:13 +00:00
|
|
|
bool m_shouldRun = true;
|
2018-06-08 12:17:50 +00:00
|
|
|
};
|
|
|
|
|
2019-04-01 13:31:48 +00:00
|
|
|
class EVMVersionRestrictedTestCase: public TestCase
|
|
|
|
{
|
2020-03-06 00:22:51 +00:00
|
|
|
protected:
|
|
|
|
EVMVersionRestrictedTestCase(std::string const& _filename);
|
2019-04-01 13:31:48 +00:00
|
|
|
};
|
2019-12-23 15:50:30 +00:00
|
|
|
|
2018-06-08 12:17:50 +00:00
|
|
|
}
|