aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-10-11 21:23:21 +0800
committerGitHub <noreply@github.com>2018-10-11 21:23:21 +0800
commit6859ec043412ddb1da1929fec4064fbd288db71e (patch)
tree471f7111974f8d6eb5a85825fce2952e7e999128
parent51db4f5411d29f2c0569066ea792b752827f4aec (diff)
parent9da62384eeac37f1709fbb53c57386b5390e72a0 (diff)
downloaddexon-solidity-6859ec043412ddb1da1929fec4064fbd288db71e.tar
dexon-solidity-6859ec043412ddb1da1929fec4064fbd288db71e.tar.gz
dexon-solidity-6859ec043412ddb1da1929fec4064fbd288db71e.tar.bz2
dexon-solidity-6859ec043412ddb1da1929fec4064fbd288db71e.tar.lz
dexon-solidity-6859ec043412ddb1da1929fec4064fbd288db71e.tar.xz
dexon-solidity-6859ec043412ddb1da1929fec4064fbd288db71e.tar.zst
dexon-solidity-6859ec043412ddb1da1929fec4064fbd288db71e.zip
Merge pull request #5179 from ethereum/refactorIsoltest
Slight refactor of isoltest to add new automated yul optimizer tests
-rw-r--r--test/Common.cpp50
-rw-r--r--test/Common.h35
-rw-r--r--test/Options.cpp22
-rw-r--r--test/tools/CMakeLists.txt2
-rw-r--r--test/tools/isoltest.cpp102
5 files changed, 136 insertions, 75 deletions
diff --git a/test/Common.cpp b/test/Common.cpp
new file mode 100644
index 00000000..a80c55d4
--- /dev/null
+++ b/test/Common.cpp
@@ -0,0 +1,50 @@
+/*
+ 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/>.
+*/
+
+#include <test/Common.h>
+
+#include <boost/filesystem.hpp>
+
+namespace fs = boost::filesystem;
+
+namespace dev
+{
+namespace test
+{
+
+boost::filesystem::path discoverTestPath()
+{
+ auto const searchPath =
+ {
+ fs::current_path() / ".." / ".." / ".." / "test",
+ fs::current_path() / ".." / ".." / "test",
+ fs::current_path() / ".." / "test",
+ fs::current_path() / "test",
+ fs::current_path()
+ };
+ for (auto const& basePath: searchPath)
+ {
+ fs::path syntaxTestPath = basePath / "libsolidity" / "syntaxTests";
+ if (fs::exists(syntaxTestPath) && fs::is_directory(syntaxTestPath))
+ return basePath;
+ }
+ return {};
+}
+
+
+}
+}
diff --git a/test/Common.h b/test/Common.h
new file mode 100644
index 00000000..e87faa0e
--- /dev/null
+++ b/test/Common.h
@@ -0,0 +1,35 @@
+/*
+ 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 <boost/filesystem/path.hpp>
+
+namespace dev
+{
+namespace test
+{
+
+/// Tries to find a path that contains the directories "libsolidity/syntaxTests"
+/// and returns it if found.
+/// The routine searches in the current directory, and inside the "test" directory
+/// starting from the current directory and up to three levels up.
+/// @returns the path of the first match or an empty path if not found.
+boost::filesystem::path discoverTestPath();
+
+}
+}
diff --git a/test/Options.cpp b/test/Options.cpp
index 63588237..da08eb37 100644
--- a/test/Options.cpp
+++ b/test/Options.cpp
@@ -21,6 +21,8 @@
#include <test/Options.h>
+#include <test/Common.h>
+
#include <libsolidity/interface/EVMVersion.h>
#include <libsolidity/interface/Exceptions.h>
@@ -74,25 +76,7 @@ Options::Options()
testPath = path;
if (testPath.empty())
- {
- auto const searchPath =
- {
- fs::current_path() / ".." / ".." / ".." / "test",
- fs::current_path() / ".." / ".." / "test",
- fs::current_path() / ".." / "test",
- fs::current_path() / "test",
- fs::current_path()
- };
- for (auto const& basePath : searchPath)
- {
- fs::path syntaxTestPath = basePath / "libsolidity" / "syntaxTests";
- if (fs::exists(syntaxTestPath) && fs::is_directory(syntaxTestPath))
- {
- testPath = basePath;
- break;
- }
- }
- }
+ testPath = discoverTestPath();
}
void Options::validate() const
diff --git a/test/tools/CMakeLists.txt b/test/tools/CMakeLists.txt
index d6df0ac8..2f107d39 100644
--- a/test/tools/CMakeLists.txt
+++ b/test/tools/CMakeLists.txt
@@ -1,7 +1,7 @@
add_executable(solfuzzer fuzzer.cpp)
target_link_libraries(solfuzzer PRIVATE libsolc evmasm ${Boost_PROGRAM_OPTIONS_LIBRARIES} ${Boost_SYSTEM_LIBRARIES})
-add_executable(isoltest isoltest.cpp ../Options.cpp ../libsolidity/TestCase.cpp ../libsolidity/SyntaxTest.cpp
+add_executable(isoltest isoltest.cpp ../Options.cpp ../Common.cpp ../libsolidity/TestCase.cpp ../libsolidity/SyntaxTest.cpp
../libsolidity/AnalysisFramework.cpp ../libsolidity/SolidityExecutionFramework.cpp ../ExecutionFramework.cpp
../RPCSession.cpp ../libsolidity/ASTJSONTest.cpp)
target_link_libraries(isoltest PRIVATE libsolc solidity evmasm ${Boost_PROGRAM_OPTIONS_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES})
diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp
index ad6b456d..dac87d1c 100644
--- a/test/tools/isoltest.cpp
+++ b/test/tools/isoltest.cpp
@@ -16,6 +16,8 @@
*/
#include <libdevcore/CommonIO.h>
+
+#include <test/Common.h>
#include <test/libsolidity/AnalysisFramework.h>
#include <test/libsolidity/SyntaxTest.h>
#include <test/libsolidity/ASTJSONTest.h>
@@ -47,6 +49,12 @@ struct TestStats
int successCount;
int testCount;
operator bool() const { return successCount == testCount; }
+ TestStats& operator+=(TestStats const& _other) noexcept
+ {
+ successCount += _other.successCount;
+ testCount += _other.testCount;
+ return *this;
+ }
};
class TestTool
@@ -256,6 +264,9 @@ TestStats TestTool::processPath(
}
+namespace
+{
+
void setupTerminal()
{
#if defined(_WIN32) && defined(ENABLE_VIRTUAL_TERMINAL_PROCESSING)
@@ -276,6 +287,36 @@ void setupTerminal()
#endif
}
+boost::optional<TestStats> runTestSuite(
+ string const& _name,
+ fs::path const& _basePath,
+ fs::path const& _subdirectory,
+ TestCase::TestCaseCreator _testCaseCreator,
+ bool _formatted
+)
+{
+ fs::path testPath = _basePath / _subdirectory;
+
+ if (!fs::exists(testPath) || !fs::is_directory(testPath))
+ {
+ cerr << _name << " tests not found. Use the --testpath argument." << endl;
+ return {};
+ }
+
+ TestStats stats = TestTool::processPath(_testCaseCreator, _basePath, _subdirectory, _formatted);
+
+ cout << endl << _name << " Test Summary: ";
+ FormattedScope(cout, _formatted, {BOLD, stats ? GREEN : RED}) <<
+ stats.successCount <<
+ "/" <<
+ stats.testCount;
+ cout << " tests successful." << endl << endl;
+
+ return stats;
+}
+
+}
+
int main(int argc, char *argv[])
{
setupTerminal();
@@ -326,73 +367,24 @@ Allowed options)",
}
if (testPath.empty())
- {
- auto const searchPath =
- {
- fs::current_path() / ".." / ".." / ".." / "test",
- fs::current_path() / ".." / ".." / "test",
- fs::current_path() / ".." / "test",
- fs::current_path() / "test",
- fs::current_path()
- };
- for (auto const& basePath : searchPath)
- {
- fs::path syntaxTestPath = basePath / "libsolidity" / "syntaxTests";
- if (fs::exists(syntaxTestPath) && fs::is_directory(syntaxTestPath))
- {
- testPath = basePath;
- break;
- }
- }
- }
+ testPath = dev::test::discoverTestPath();
- TestStats global_stats { 0, 0 };
+ TestStats global_stats{0, 0};
- fs::path syntaxTestPath = testPath / "libsolidity" / "syntaxTests";
-
- if (fs::exists(syntaxTestPath) && fs::is_directory(syntaxTestPath))
- {
- auto stats = TestTool::processPath(SyntaxTest::create, testPath / "libsolidity", "syntaxTests", formatted);
-
- cout << endl << "Syntax Test Summary: ";
- FormattedScope(cout, formatted, {BOLD, stats ? GREEN : RED}) <<
- stats.successCount << "/" << stats.testCount;
- cout << " tests successful." << endl << endl;
-
- global_stats.testCount += stats.testCount;
- global_stats.successCount += stats.successCount;
- }
+ if (auto stats = runTestSuite("Syntax", testPath / "libsolidity", "syntaxTests", SyntaxTest::create, formatted))
+ global_stats += *stats;
else
- {
- cerr << "Syntax tests not found. Use the --testpath argument." << endl;
return 1;
- }
-
- fs::path astJsonTestPath = testPath / "libsolidity" / "ASTJSON";
-
- if (fs::exists(astJsonTestPath) && fs::is_directory(astJsonTestPath))
- {
- auto stats = TestTool::processPath(ASTJSONTest::create, testPath / "libsolidity", "ASTJSON", formatted);
- cout << endl << "JSON AST Test Summary: ";
- FormattedScope(cout, formatted, {BOLD, stats ? GREEN : RED}) <<
- stats.successCount << "/" << stats.testCount;
- cout << " tests successful." << endl << endl;
-
- global_stats.testCount += stats.testCount;
- global_stats.successCount += stats.successCount;
- }
+ if (auto stats = runTestSuite("JSON AST", testPath / "libsolidity", "ASTJSON", ASTJSONTest::create, formatted))
+ global_stats += *stats;
else
- {
- cerr << "JSON AST tests not found." << endl;
return 1;
- }
cout << endl << "Summary: ";
FormattedScope(cout, formatted, {BOLD, global_stats ? GREEN : RED}) <<
global_stats.successCount << "/" << global_stats.testCount;
cout << " tests successful." << endl;
-
return global_stats ? 0 : 1;
}