diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index 908e0b795..1e92b6bac 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -46,6 +46,9 @@ using namespace std; namespace po = boost::program_options; namespace fs = boost::filesystem; +using TestCreator = TestCase::TestCaseCreator; +using TestOptions = dev::test::IsolTestOptions; + struct TestStats { int successCount = 0; @@ -88,21 +91,16 @@ class TestTool { public: TestTool( - TestCase::TestCaseCreator _testCaseCreator, - string const& _filter, - string const& _name, + TestCreator _testCaseCreator, + TestOptions const& _options, fs::path const& _path, - string const& _ipcPath, - bool _formatted, - langutil::EVMVersion _evmVersion + string const& _name ): m_testCaseCreator(_testCaseCreator), - m_filter(TestFilter{_filter}), - m_name(_name), + m_options(_options), + m_filter(TestFilter{_options.test}), m_path(_path), - m_ipcPath(_ipcPath), - m_formatted(_formatted), - m_evmVersion(_evmVersion) + m_name(_name) {} enum class Result @@ -116,13 +114,10 @@ public: Result process(); static TestStats processPath( - TestCase::TestCaseCreator _testCaseCreator, + TestCreator _testCaseCreator, + TestOptions const& _options, fs::path const& _basepath, - fs::path const& _path, - string const& _filter, - string const& _ipcPath, - bool _formatted, - langutil::EVMVersion _evmVersion + fs::path const& _path ); static string editor; @@ -136,14 +131,11 @@ private: Request handleResponse(bool _exception); - TestCase::TestCaseCreator m_testCaseCreator; + TestCreator m_testCaseCreator; + TestOptions const& m_options; TestFilter m_filter; - - string const m_name; fs::path const m_path; - string const m_ipcPath; - bool const m_formatted = false; - langutil::EVMVersion const m_evmVersion; + string const m_name; unique_ptr m_test; @@ -156,20 +148,21 @@ bool TestTool::m_exitRequested = false; TestTool::Result TestTool::process() { bool success; + bool formatted{!m_options.noColor}; std::stringstream outputMessages; try { if (m_filter.matches(m_name)) { - (AnsiColorized(cout, m_formatted, {BOLD}) << m_name << ": ").flush(); + (AnsiColorized(cout, formatted, {BOLD}) << m_name << ": ").flush(); - m_test = m_testCaseCreator(TestCase::Config{m_path.string(), m_ipcPath, m_evmVersion}); - if (m_test->validateSettings(m_evmVersion)) - success = m_test->run(outputMessages, " ", m_formatted); + m_test = m_testCaseCreator(TestCase::Config{m_path.string(), m_options.ipcPath.string(), m_options.evmVersion()}); + if (m_test->validateSettings(m_options.evmVersion())) + success = m_test->run(outputMessages, " ", formatted); else { - AnsiColorized(cout, m_formatted, {BOLD, YELLOW}) << "NOT RUN" << endl; + AnsiColorized(cout, formatted, {BOLD, YELLOW}) << "NOT RUN" << endl; return Result::Skipped; } } @@ -178,35 +171,35 @@ TestTool::Result TestTool::process() } catch(boost::exception const& _e) { - AnsiColorized(cout, m_formatted, {BOLD, RED}) << + AnsiColorized(cout, formatted, {BOLD, RED}) << "Exception during test: " << boost::diagnostic_information(_e) << endl; return Result::Exception; } catch (std::exception const& _e) { - AnsiColorized(cout, m_formatted, {BOLD, RED}) << + AnsiColorized(cout, formatted, {BOLD, RED}) << "Exception during test: " << _e.what() << endl; return Result::Exception; } catch (...) { - AnsiColorized(cout, m_formatted, {BOLD, RED}) << + AnsiColorized(cout, formatted, {BOLD, RED}) << "Unknown exception during test." << endl; return Result::Exception; } if (success) { - AnsiColorized(cout, m_formatted, {BOLD, GREEN}) << "OK" << endl; + AnsiColorized(cout, formatted, {BOLD, GREEN}) << "OK" << endl; return Result::Success; } else { - AnsiColorized(cout, m_formatted, {BOLD, RED}) << "FAIL" << endl; + AnsiColorized(cout, formatted, {BOLD, RED}) << "FAIL" << endl; - AnsiColorized(cout, m_formatted, {BOLD, CYAN}) << " Contract:" << endl; - m_test->printSource(cout, " ", m_formatted); - m_test->printUpdatedSettings(cout, " ", m_formatted); + AnsiColorized(cout, formatted, {BOLD, CYAN}) << " Contract:" << endl; + m_test->printSource(cout, " ", formatted); + m_test->printUpdatedSettings(cout, " ", formatted); cout << endl << outputMessages.str() << endl; return Result::Failure; @@ -256,13 +249,10 @@ TestTool::Request TestTool::handleResponse(bool _exception) } TestStats TestTool::processPath( - TestCase::TestCaseCreator _testCaseCreator, + TestCreator _testCaseCreator, + TestOptions const& _options, fs::path const& _basepath, - fs::path const& _path, - string const& _filter, - string const& _ipcPath, - bool _formatted, - langutil::EVMVersion _evmVersion + fs::path const& _path ) { std::queue paths; @@ -296,12 +286,9 @@ TestStats TestTool::processPath( ++testCount; TestTool testTool( _testCaseCreator, - _filter, - currentPath.generic_string(), + _options, fullpath, - _ipcPath, - _formatted, - _evmVersion + currentPath.string() ); auto result = testTool.process(); @@ -365,17 +352,15 @@ void setupTerminal() } boost::optional runTestSuite( - string const& _name, + TestCreator _testCaseCreator, + TestOptions const& _options, fs::path const& _basePath, fs::path const& _subdirectory, - string const& _filter, - string const& _ipcPath, - TestCase::TestCaseCreator _testCaseCreator, - bool _formatted, - langutil::EVMVersion _evmVersion + string const& _name ) { - fs::path testPath = _basePath / _subdirectory; + fs::path testPath{_basePath / _subdirectory}; + bool formatted{!_options.noColor}; if (!fs::exists(testPath) || !fs::is_directory(testPath)) { @@ -385,18 +370,15 @@ boost::optional runTestSuite( TestStats stats = TestTool::processPath( _testCaseCreator, + _options, _basePath, - _subdirectory, - _filter, - _ipcPath, - _formatted, - _evmVersion + _subdirectory ); if (stats.skippedCount != stats.testCount) { cout << endl << _name << " Test Summary: "; - AnsiColorized(cout, _formatted, {BOLD, stats ? GREEN : RED}) << + AnsiColorized(cout, formatted, {BOLD, stats ? GREEN : RED}) << stats.successCount << "/" << stats.testCount; @@ -404,7 +386,7 @@ boost::optional runTestSuite( if (stats.skippedCount > 0) { cout << " ("; - AnsiColorized(cout, _formatted, {BOLD, YELLOW}) << stats.skippedCount; + AnsiColorized(cout, formatted, {BOLD, YELLOW}) << stats.skippedCount; cout<< " tests skipped)"; } cout << "." << endl << endl; @@ -447,14 +429,11 @@ int main(int argc, char const *argv[]) continue; auto stats = runTestSuite( - ts.title, + ts.testCaseCreator, + options, options.testPath / ts.path, ts.subpath, - options.test, - options.ipcPath.string(), - ts.testCaseCreator, - !options.noColor, - options.evmVersion() + ts.title ); if (stats) global_stats += *stats;