diff --git a/test/tools/IsolTestOptions.cpp b/test/tools/IsolTestOptions.cpp index 785179132..aaa087e47 100644 --- a/test/tools/IsolTestOptions.cpp +++ b/test/tools/IsolTestOptions.cpp @@ -63,6 +63,7 @@ IsolTestOptions::IsolTestOptions(std::string* _editor): ("editor", po::value(_editor)->default_value(editorPath()), "Path to editor for opening test files.") ("help", po::bool_switch(&showHelp), "Show this help screen.") ("no-color", po::bool_switch(&noColor), "Don't use colors.") + ("accept-updates", po::bool_switch(&acceptUpdates), "Automatically accept expectation updates.") ("test,t", po::value(&testFilter)->default_value("*/*"), "Filters which test units to include."); } diff --git a/test/tools/IsolTestOptions.h b/test/tools/IsolTestOptions.h index 118ac95d3..aa9eb2564 100644 --- a/test/tools/IsolTestOptions.h +++ b/test/tools/IsolTestOptions.h @@ -31,6 +31,7 @@ struct IsolTestOptions: CommonOptions { bool showHelp = false; bool noColor = false; + bool acceptUpdates = false; std::string testFilter = std::string{}; IsolTestOptions(std::string* _editor); diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index bd5f48a4a..91efedadb 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -131,6 +131,7 @@ private: Quit }; + void updateTestCase(); Request handleResponse(bool _exception); 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) { + if (!_exception && m_options.acceptUpdates) + { + updateTestCase(); + return Request::Rerun; + } + if (_exception) cout << "(e)dit/(s)kip/(q)uit? "; else @@ -234,11 +250,7 @@ TestTool::Request TestTool::handleResponse(bool _exception) else { cout << endl; - ofstream file(m_path.string(), ios::trunc); - m_test->printSource(file); - m_test->printUpdatedSettings(file); - file << "// ----" << endl; - m_test->printUpdatedExpectations(file, "// "); + updateTestCase(); return Request::Rerun; } case 'e':