From 50247dc8d1f1b3f4408670ab0538da8f0e113cf6 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 9 Oct 2018 15:36:40 +0200 Subject: Extract test suite runs. --- test/tools/isoltest.cpp | 75 +++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 36 deletions(-) (limited to 'test') diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index cc7e706d..5cf1d9c0 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -47,6 +47,12 @@ struct TestStats int successCount; int testCount; operator bool() const { return successCount == testCount; } + TestStats& operator+=(TestStats const& _other) + { + successCount += _other.successCount; + testCount += _other.testCount; + return *this; + } }; class TestTool @@ -298,6 +304,34 @@ fs::path discoverTestPath() return {}; } +boost::optional 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[]) @@ -352,53 +386,22 @@ Allowed options)", if (testPath.empty()) testPath = discoverTestPath(); - TestStats global_stats { 0, 0 }; - - fs::path syntaxTestPath = testPath / "libsolidity" / "syntaxTests"; + TestStats global_stats{0, 0}; - 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; } -- cgit v1.2.3