Add settings framework for interactive tests.

This commit is contained in:
chriseth
2019-04-03 14:58:20 +02:00
parent 8942c5acfb
commit aeb260cde1
10 changed files with 118 additions and 53 deletions
+24 -6
View File
@@ -26,6 +26,7 @@
#include <memory>
#include <string>
#include <vector>
#include <map>
namespace dev
{
@@ -42,7 +43,9 @@ namespace test
} \
while (false)
/** Common superclass of SyntaxTest and SemanticsTest. */
/**
* Common superclass of anything that can be run via isoltest.
*/
class TestCase
{
public:
@@ -68,17 +71,23 @@ public:
/// If @arg _formatted is true, color-coding may be used to indicate
/// error locations in the contract, if applicable.
virtual void printSource(std::ostream &_stream, std::string const &_linePrefix = "", bool const _formatted = false) const = 0;
/// Outputs the updated settings.
virtual void printUpdatedSettings(std::ostream &_stream, std::string const &_linePrefix = "", bool const _formatted = false) const;
/// Outputs test expectations to @arg _stream that match the actual results of the test.
/// Each line of output is prefixed with @arg _linePrefix.
virtual void printUpdatedExpectations(std::ostream& _stream, std::string const& _linePrefix) const = 0;
static bool isTestFilename(boost::filesystem::path const& _filename);
/// Returns true, if the test case is supported for EVM version @arg _evmVersion, false otherwise.
bool supportedForEVMVersion(langutil::EVMVersion _evmVersion) const;
/// Validates the settings, i.e. moves them from m_settings to m_validatedSettings.
/// Throws a runtime exception if any setting is left at this class (i.e. unknown setting).
/// 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.
virtual bool validateSettings(langutil::EVMVersion /*_evmVersion*/);
protected:
std::string parseSource(std::istream& _file);
std::string parseSourceAndSettings(std::istream& _file);
static void expect(std::string::iterator& _it, std::string::iterator _end, std::string::value_type _c);
template<typename IteratorType>
@@ -94,10 +103,19 @@ protected:
while (_it != _end && *_it == '/')
++_it;
}
private:
std::vector<std::function<bool(langutil::EVMVersion)>> m_evmVersionRules;
/// Parsed settings.
std::map<std::string, std::string> m_settings;
/// Updated settings after validation.
std::map<std::string, std::string> m_validatedSettings;
};
class EVMVersionRestrictedTestCase: public TestCase
{
public:
/// Returns true, if the test case is supported for EVM version @arg _evmVersion, false otherwise.
bool validateSettings(langutil::EVMVersion _evmVersion) override;
};
}
}
}