From 56d5dd46687026d2fab80f1b38e8314b080267ab Mon Sep 17 00:00:00 2001 From: Lazaridis Date: Sun, 25 Nov 2018 02:02:32 +0200 Subject: decouple TestCase class from test/libsolidity --- test/TestCase.cpp | 56 +++++++++++++++++++++++++++++ test/TestCase.h | 80 ++++++++++++++++++++++++++++++++++++++++++ test/libsolidity/ASTJSONTest.h | 2 +- test/libsolidity/SyntaxTest.h | 2 +- test/libsolidity/TestCase.cpp | 56 ----------------------------- test/libsolidity/TestCase.h | 80 ------------------------------------------ test/libyul/YulOptimizerTest.h | 2 +- test/tools/CMakeLists.txt | 2 +- 8 files changed, 140 insertions(+), 140 deletions(-) create mode 100644 test/TestCase.cpp create mode 100644 test/TestCase.h delete mode 100644 test/libsolidity/TestCase.cpp delete mode 100644 test/libsolidity/TestCase.h diff --git a/test/TestCase.cpp b/test/TestCase.cpp new file mode 100644 index 00000000..e9e2c9f2 --- /dev/null +++ b/test/TestCase.cpp @@ -0,0 +1,56 @@ +/* + 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 . +*/ + +#include + +#include +#include + +#include + +using namespace dev; +using namespace solidity; +using namespace dev::solidity::test; +using namespace std; + +bool TestCase::isTestFilename(boost::filesystem::path const& _filename) +{ + string extension = _filename.extension().string(); + return (extension == ".sol" || extension == ".yul") && + !boost::starts_with(_filename.string(), "~") && + !boost::starts_with(_filename.string(), "."); +} + +string TestCase::parseSource(istream& _stream) +{ + string source; + string line; + string const delimiter("// ----"); + while (getline(_stream, line)) + if (boost::algorithm::starts_with(line, delimiter)) + break; + else + source += line + "\n"; + return source; +} + +void TestCase::expect(string::iterator& _it, string::iterator _end, string::value_type _c) +{ + if (_it == _end || *_it != _c) + throw runtime_error(string("Invalid test expectation. Expected: \"") + _c + "\"."); + ++_it; +} diff --git a/test/TestCase.h b/test/TestCase.h new file mode 100644 index 00000000..3c05ae4e --- /dev/null +++ b/test/TestCase.h @@ -0,0 +1,80 @@ +/* + 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 . +*/ + +#pragma once + +#include + +#include +#include +#include + +namespace dev +{ +namespace solidity +{ +namespace test +{ + +/** Common superclass of SyntaxTest and SemanticsTest. */ +class TestCase +{ +public: + using TestCaseCreator = std::unique_ptr(*)(std::string const&); + + virtual ~TestCase() {} + + /// 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 + virtual bool run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) = 0; + + /// 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. + virtual void printSource(std::ostream &_stream, std::string const &_linePrefix = "", bool const _formatted = false) const = 0; + /// 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); + +protected: + static std::string parseSource(std::istream& _file); + static void expect(std::string::iterator& _it, std::string::iterator _end, std::string::value_type _c); + + template + static void skipWhitespace(IteratorType& _it, IteratorType _end) + { + while (_it != _end && isspace(*_it)) + ++_it; + } + + template + static void skipSlashes(IteratorType& _it, IteratorType _end) + { + while (_it != _end && *_it == '/') + ++_it; + } + +}; + +} +} +} diff --git a/test/libsolidity/ASTJSONTest.h b/test/libsolidity/ASTJSONTest.h index 9760ef66..dcdaf221 100644 --- a/test/libsolidity/ASTJSONTest.h +++ b/test/libsolidity/ASTJSONTest.h @@ -18,7 +18,7 @@ #pragma once #include -#include +#include #include #include diff --git a/test/libsolidity/SyntaxTest.h b/test/libsolidity/SyntaxTest.h index d286f934..12c14087 100644 --- a/test/libsolidity/SyntaxTest.h +++ b/test/libsolidity/SyntaxTest.h @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include diff --git a/test/libsolidity/TestCase.cpp b/test/libsolidity/TestCase.cpp deleted file mode 100644 index 17972269..00000000 --- a/test/libsolidity/TestCase.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - 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 . -*/ - -#include - -#include -#include - -#include - -using namespace dev; -using namespace solidity; -using namespace dev::solidity::test; -using namespace std; - -bool TestCase::isTestFilename(boost::filesystem::path const& _filename) -{ - string extension = _filename.extension().string(); - return (extension == ".sol" || extension == ".yul") && - !boost::starts_with(_filename.string(), "~") && - !boost::starts_with(_filename.string(), "."); -} - -string TestCase::parseSource(istream& _stream) -{ - string source; - string line; - string const delimiter("// ----"); - while (getline(_stream, line)) - if (boost::algorithm::starts_with(line, delimiter)) - break; - else - source += line + "\n"; - return source; -} - -void TestCase::expect(string::iterator& _it, string::iterator _end, string::value_type _c) -{ - if (_it == _end || *_it != _c) - throw runtime_error(string("Invalid test expectation. Expected: \"") + _c + "\"."); - ++_it; -} diff --git a/test/libsolidity/TestCase.h b/test/libsolidity/TestCase.h deleted file mode 100644 index 3c05ae4e..00000000 --- a/test/libsolidity/TestCase.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - 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 . -*/ - -#pragma once - -#include - -#include -#include -#include - -namespace dev -{ -namespace solidity -{ -namespace test -{ - -/** Common superclass of SyntaxTest and SemanticsTest. */ -class TestCase -{ -public: - using TestCaseCreator = std::unique_ptr(*)(std::string const&); - - virtual ~TestCase() {} - - /// 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 - virtual bool run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) = 0; - - /// 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. - virtual void printSource(std::ostream &_stream, std::string const &_linePrefix = "", bool const _formatted = false) const = 0; - /// 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); - -protected: - static std::string parseSource(std::istream& _file); - static void expect(std::string::iterator& _it, std::string::iterator _end, std::string::value_type _c); - - template - static void skipWhitespace(IteratorType& _it, IteratorType _end) - { - while (_it != _end && isspace(*_it)) - ++_it; - } - - template - static void skipSlashes(IteratorType& _it, IteratorType _end) - { - while (_it != _end && *_it == '/') - ++_it; - } - -}; - -} -} -} diff --git a/test/libyul/YulOptimizerTest.h b/test/libyul/YulOptimizerTest.h index 72c4299f..90026e24 100644 --- a/test/libyul/YulOptimizerTest.h +++ b/test/libyul/YulOptimizerTest.h @@ -17,7 +17,7 @@ #pragma once -#include +#include namespace langutil { diff --git a/test/tools/CMakeLists.txt b/test/tools/CMakeLists.txt index a0fbe140..736212fc 100644 --- a/test/tools/CMakeLists.txt +++ b/test/tools/CMakeLists.txt @@ -4,7 +4,7 @@ target_link_libraries(solfuzzer PRIVATE libsolc evmasm ${Boost_PROGRAM_OPTIONS_L add_executable(yulopti yulopti.cpp) target_link_libraries(yulopti PRIVATE solidity ${Boost_PROGRAM_OPTIONS_LIBRARIES} ${Boost_SYSTEM_LIBRARIES}) -add_executable(isoltest isoltest.cpp ../Options.cpp ../Common.cpp ../libsolidity/TestCase.cpp ../libsolidity/SyntaxTest.cpp +add_executable(isoltest isoltest.cpp ../Options.cpp ../Common.cpp ../TestCase.cpp ../libsolidity/SyntaxTest.cpp ../libsolidity/AnalysisFramework.cpp ../libsolidity/SolidityExecutionFramework.cpp ../ExecutionFramework.cpp ../RPCSession.cpp ../libsolidity/ASTJSONTest.cpp ../libsolidity/SMTCheckerJSONTest.cpp ../libyul/YulOptimizerTest.cpp) target_link_libraries(isoltest PRIVATE libsolc solidity evmasm ${Boost_PROGRAM_OPTIONS_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES}) -- cgit