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