Merge pull request #11098 from ethereum/isoltest-yes

isoltest: add --accept-updates option
This commit is contained in:
Alex Beregszaszi 2021-03-15 19:10:02 +00:00 committed by GitHub
commit 7fd1a3132d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 5 deletions

View File

@ -63,6 +63,7 @@ IsolTestOptions::IsolTestOptions(std::string* _editor):
("editor", po::value<std::string>(_editor)->default_value(editorPath()), "Path to editor for opening test files.") ("editor", po::value<std::string>(_editor)->default_value(editorPath()), "Path to editor for opening test files.")
("help", po::bool_switch(&showHelp), "Show this help screen.") ("help", po::bool_switch(&showHelp), "Show this help screen.")
("no-color", po::bool_switch(&noColor), "Don't use colors.") ("no-color", po::bool_switch(&noColor), "Don't use colors.")
("accept-updates", po::bool_switch(&acceptUpdates), "Automatically accept expectation updates.")
("test,t", po::value<std::string>(&testFilter)->default_value("*/*"), "Filters which test units to include."); ("test,t", po::value<std::string>(&testFilter)->default_value("*/*"), "Filters which test units to include.");
} }

View File

@ -31,6 +31,7 @@ struct IsolTestOptions: CommonOptions
{ {
bool showHelp = false; bool showHelp = false;
bool noColor = false; bool noColor = false;
bool acceptUpdates = false;
std::string testFilter = std::string{}; std::string testFilter = std::string{};
IsolTestOptions(std::string* _editor); IsolTestOptions(std::string* _editor);

View File

@ -131,6 +131,7 @@ private:
Quit Quit
}; };
void updateTestCase();
Request handleResponse(bool _exception); Request handleResponse(bool _exception);
TestCreator m_testCaseCreator; TestCreator m_testCaseCreator;
@ -213,8 +214,23 @@ TestTool::Result TestTool::process()
} }
} }
void TestTool::updateTestCase()
{
ofstream file(m_path.string(), ios::trunc);
m_test->printSource(file);
m_test->printUpdatedSettings(file);
file << "// ----" << endl;
m_test->printUpdatedExpectations(file, "// ");
}
TestTool::Request TestTool::handleResponse(bool _exception) TestTool::Request TestTool::handleResponse(bool _exception)
{ {
if (!_exception && m_options.acceptUpdates)
{
updateTestCase();
return Request::Rerun;
}
if (_exception) if (_exception)
cout << "(e)dit/(s)kip/(q)uit? "; cout << "(e)dit/(s)kip/(q)uit? ";
else else
@ -234,11 +250,7 @@ TestTool::Request TestTool::handleResponse(bool _exception)
else else
{ {
cout << endl; cout << endl;
ofstream file(m_path.string(), ios::trunc); updateTestCase();
m_test->printSource(file);
m_test->printUpdatedSettings(file);
file << "// ----" << endl;
m_test->printUpdatedExpectations(file, "// ");
return Request::Rerun; return Request::Rerun;
} }
case 'e': case 'e':