From 29b770c43439addcb29fd79ddbf6bc37dfed0f5e Mon Sep 17 00:00:00 2001 From: a3d4 Date: Tue, 18 Feb 2020 17:13:13 +0100 Subject: [PATCH] Introduced TestCase::shouldRun(). --- test/TestCase.cpp | 35 ++++++++++++++++++----------- test/TestCase.h | 9 +++++--- test/boostTest.cpp | 3 ++- test/libsolidity/SMTCheckerTest.cpp | 23 ++++++++----------- test/libsolidity/SMTCheckerTest.h | 2 -- test/libsolidity/SemanticTest.cpp | 10 +++------ test/libsolidity/SemanticTest.h | 2 -- test/libyul/SyntaxTest.cpp | 9 +++----- test/libyul/SyntaxTest.h | 5 +---- test/tools/isoltest.cpp | 3 ++- 10 files changed, 48 insertions(+), 53 deletions(-) diff --git a/test/TestCase.cpp b/test/TestCase.cpp index 01dc51e7c..6b0a16e27 100644 --- a/test/TestCase.cpp +++ b/test/TestCase.cpp @@ -15,6 +15,7 @@ along with solidity. If not, see . */ +#include #include #include @@ -52,14 +53,18 @@ bool TestCase::isTestFilename(boost::filesystem::path const& _filename) !boost::starts_with(_filename.string(), "."); } -bool TestCase::validateSettings(langutil::EVMVersion) +void TestCase::validateSettings() { if (!m_settings.empty()) throw runtime_error( "Unknown setting(s): " + util::joinHumanReadable(m_settings | boost::adaptors::map_keys) ); - return true; +} + +bool TestCase::shouldRun() +{ + return m_shouldRun; } pair, size_t> TestCase::parseSourcesAndSettingsWithLineNumbers(istream& _stream) @@ -157,20 +162,19 @@ void TestCase::expect(string::iterator& _it, string::iterator _end, string::valu ++_it; } -bool EVMVersionRestrictedTestCase::validateSettings(langutil::EVMVersion _evmVersion) +void EVMVersionRestrictedTestCase::validateSettings() { if (!m_settings.count("EVMVersion")) - return true; + return; string versionString = m_settings["EVMVersion"]; m_validatedSettings["EVMVersion"] = versionString; m_settings.erase("EVMVersion"); - if (!TestCase::validateSettings(_evmVersion)) - return false; + TestCase::validateSettings(); if (versionString.empty()) - return true; + return; string comparator; size_t versionBegin = 0; @@ -188,18 +192,23 @@ bool EVMVersionRestrictedTestCase::validateSettings(langutil::EVMVersion _evmVer if (!version) BOOST_THROW_EXCEPTION(runtime_error{"Invalid EVM version: \"" + versionString + "\""}); + langutil::EVMVersion evmVersion = solidity::test::CommonOptions::get().evmVersion(); + bool comparisonResult; if (comparator == ">") - return _evmVersion > version; + comparisonResult = evmVersion > version; else if (comparator == ">=") - return _evmVersion >= version; + comparisonResult = evmVersion >= version; else if (comparator == "<") - return _evmVersion < version; + comparisonResult = evmVersion < version; else if (comparator == "<=") - return _evmVersion <= version; + comparisonResult = evmVersion <= version; else if (comparator == "=") - return _evmVersion == version; + comparisonResult = evmVersion == version; else if (comparator == "!") - return !(_evmVersion == version); + comparisonResult = !(evmVersion == version); else BOOST_THROW_EXCEPTION(runtime_error{"Invalid EVM comparator: \"" + comparator + "\""}); + + if (!comparisonResult) + m_shouldRun = false; } diff --git a/test/TestCase.h b/test/TestCase.h index 927490537..d6afff8b8 100644 --- a/test/TestCase.h +++ b/test/TestCase.h @@ -70,10 +70,12 @@ public: /// 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). + virtual void validateSettings(); + /// 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*/); + bool shouldRun(); protected: std::pair, std::size_t> parseSourcesAndSettingsWithLineNumbers(std::istream& _file); @@ -102,13 +104,14 @@ protected: std::map m_settings; /// Updated settings after validation. std::map m_validatedSettings; + + bool m_shouldRun = true; }; 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; + void validateSettings() override; }; } diff --git a/test/boostTest.cpp b/test/boostTest.cpp index 2b5606546..3137a5085 100644 --- a/test/boostTest.cpp +++ b/test/boostTest.cpp @@ -94,7 +94,8 @@ int registerTests( { stringstream errorStream; auto testCase = _testCaseCreator(config); - if (testCase->validateSettings(solidity::test::CommonOptions::get().evmVersion())) + testCase->validateSettings(); + if (testCase->shouldRun()) switch (testCase->run(errorStream)) { case TestCase::TestResult::Success: diff --git a/test/libsolidity/SMTCheckerTest.cpp b/test/libsolidity/SMTCheckerTest.cpp index 7db668a2d..912349182 100644 --- a/test/libsolidity/SMTCheckerTest.cpp +++ b/test/libsolidity/SMTCheckerTest.cpp @@ -44,6 +44,15 @@ SMTCheckerTest::SMTCheckerTest(string const& _filename, langutil::EVMVersion _ev } else m_enabledSolvers = smt::SMTSolverChoice::All(); + + auto available = ModelChecker::availableSolvers(); + if (!available.z3) + m_enabledSolvers.z3 = false; + if (!available.cvc4) + m_enabledSolvers.cvc4 = false; + + if (m_enabledSolvers.none()) + m_shouldRun = false; } TestCase::TestResult SMTCheckerTest::run(ostream& _stream, string const& _linePrefix, bool _formatted) @@ -55,17 +64,3 @@ TestCase::TestResult SMTCheckerTest::run(ostream& _stream, string const& _linePr return printExpectationAndError(_stream, _linePrefix, _formatted) ? TestResult::Success : TestResult::Failure; } - -bool SMTCheckerTest::validateSettings(langutil::EVMVersion _evmVersion) -{ - auto available = ModelChecker::availableSolvers(); - if (!available.z3) - m_enabledSolvers.z3 = false; - if (!available.cvc4) - m_enabledSolvers.cvc4 = false; - - if (m_enabledSolvers.none()) - return false; - - return SyntaxTest::validateSettings(_evmVersion); -} diff --git a/test/libsolidity/SMTCheckerTest.h b/test/libsolidity/SMTCheckerTest.h index ce28409e6..ad38af25c 100644 --- a/test/libsolidity/SMTCheckerTest.h +++ b/test/libsolidity/SMTCheckerTest.h @@ -37,8 +37,6 @@ public: TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool _formatted = false) override; - bool validateSettings(langutil::EVMVersion _evmVersion) override; - protected: /// This is set via option SMTSolvers in the test. /// The possible options are `all`, `z3`, `cvc4`, `none`, diff --git a/test/libsolidity/SemanticTest.cpp b/test/libsolidity/SemanticTest.cpp index b2c4628da..97c83a3e5 100644 --- a/test/libsolidity/SemanticTest.cpp +++ b/test/libsolidity/SemanticTest.cpp @@ -71,6 +71,9 @@ SemanticTest::SemanticTest(string const& _filename, langutil::EVMVersion _evmVer m_settings.erase("ABIEncoderV1Only"); } + if (m_runWithABIEncoderV1Only && solidity::test::CommonOptions::get().useABIEncoderV2) + m_shouldRun = false; + if (m_settings.count("revertStrings")) { auto revertStrings = revertStringsFromString(m_settings["revertStrings"]); @@ -90,13 +93,6 @@ SemanticTest::SemanticTest(string const& _filename, langutil::EVMVersion _evmVer soltestAssert(!m_tests.empty(), "No tests specified in " + _filename); } -bool SemanticTest::validateSettings(langutil::EVMVersion _evmVersion) -{ - if (m_runWithABIEncoderV1Only && solidity::test::CommonOptions::get().useABIEncoderV2) - return false; - return EVMVersionRestrictedTestCase::validateSettings(_evmVersion); -} - TestCase::TestResult SemanticTest::run(ostream& _stream, string const& _linePrefix, bool _formatted) { for(bool compileViaYul: set{!m_runWithoutYul, m_runWithYul}) diff --git a/test/libsolidity/SemanticTest.h b/test/libsolidity/SemanticTest.h index 5cd8e5cc7..0ea486cad 100644 --- a/test/libsolidity/SemanticTest.h +++ b/test/libsolidity/SemanticTest.h @@ -44,8 +44,6 @@ public: explicit SemanticTest(std::string const& _filename, langutil::EVMVersion _evmVersion); - bool validateSettings(langutil::EVMVersion _evmVersion) override; - TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool _formatted = false) override; void printSource(std::ostream &_stream, std::string const& _linePrefix = "", bool _formatted = false) const override; void printUpdatedExpectations(std::ostream& _stream, std::string const& _linePrefix = "") const override; diff --git a/test/libyul/SyntaxTest.cpp b/test/libyul/SyntaxTest.cpp index be1b9990b..75e38c844 100644 --- a/test/libyul/SyntaxTest.cpp +++ b/test/libyul/SyntaxTest.cpp @@ -114,13 +114,12 @@ void SyntaxTest::parseAndAnalyze() } -bool SyntaxTest::validateSettings(langutil::EVMVersion _evmVersion) +void SyntaxTest::validateSettings() { - if (!CommonSyntaxTest::validateSettings(_evmVersion)) - return false; + CommonSyntaxTest::validateSettings(); if (!m_settings.count("dialect")) - return true; + return; string const dialect = m_settings["dialect"]; m_validatedSettings["dialect"] = dialect; @@ -134,6 +133,4 @@ bool SyntaxTest::validateSettings(langutil::EVMVersion _evmVersion) joinHumanReadable(validDialectNames(), ", ", " and ") + "." }); - - return true; } diff --git a/test/libyul/SyntaxTest.h b/test/libyul/SyntaxTest.h index e355a5932..087a6326c 100644 --- a/test/libyul/SyntaxTest.h +++ b/test/libyul/SyntaxTest.h @@ -42,10 +42,7 @@ public: /// 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. - bool validateSettings(langutil::EVMVersion _evmVersion) override; + void validateSettings() override; protected: void parseAndAnalyze() override; }; diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index a8c8748fb..e439aba64 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -161,7 +161,8 @@ TestTool::Result TestTool::process() (AnsiColorized(cout, formatted, {BOLD}) << m_name << ": ").flush(); m_test = m_testCaseCreator(TestCase::Config{m_path.string(), m_options.evmVersion()}); - if (m_test->validateSettings(m_options.evmVersion())) + m_test->validateSettings(); + if (m_test->shouldRun()) switch (TestCase::TestResult result = m_test->run(outputMessages, " ", formatted)) { case TestCase::TestResult::Success: