diff --git a/test/Common.cpp b/test/Common.cpp index 9b2cfbb96..2a663aa1b 100644 --- a/test/Common.cpp +++ b/test/Common.cpp @@ -91,22 +91,27 @@ CommonOptions::CommonOptions(std::string _caption): po::options_description::m_default_line_length, po::options_description::m_default_line_length - 23 ) +{ + +} + +void CommonOptions::addOptions() { options.add_options() ("evm-version", po::value(&evmVersionString), "which evm version to use") ("testpath", po::value(&this->testPath)->default_value(solidity::test::testPath()), "path to test files") ("vm", po::value>(&vmPaths), "path to evmc library, can be supplied multiple times.") - ("ewasm", po::bool_switch(&ewasm), "tries to automatically find an ewasm vm and enable ewasm test-execution.") - ("no-semantic-tests", po::bool_switch(&disableSemanticTests), "disable semantic tests") - ("no-smt", po::bool_switch(&disableSMT), "disable SMT checker") - ("optimize", po::bool_switch(&optimize), "enables optimization") - ("enforce-via-yul", po::bool_switch(&enforceViaYul), "Enforce compiling all tests via yul to see if additional tests can be activated.") - ("enforce-compile-to-ewasm", po::bool_switch(&enforceCompileToEwasm), "Enforce compiling all tests to Ewasm to see if additional tests can be activated.") - ("enforce-gas-cost", po::bool_switch(&enforceGasTest), "Enforce checking gas cost in semantic tests.") - ("enforce-gas-cost-min-value", po::value(&enforceGasTestMinValue), "Threshold value to enforce adding gas checks to a test.") - ("abiencoderv1", po::bool_switch(&useABIEncoderV1), "enables abi encoder v1") - ("show-messages", po::bool_switch(&showMessages), "enables message output") - ("show-metadata", po::bool_switch(&showMetadata), "enables metadata output"); + ("ewasm", po::bool_switch(&ewasm)->default_value(ewasm), "tries to automatically find an ewasm vm and enable ewasm test-execution.") + ("no-semantic-tests", po::bool_switch(&disableSemanticTests)->default_value(disableSemanticTests), "disable semantic tests") + ("no-smt", po::bool_switch(&disableSMT)->default_value(disableSMT), "disable SMT checker") + ("optimize", po::bool_switch(&optimize)->default_value(optimize), "enables optimization") + ("enforce-via-yul", po::value(&enforceViaYul)->default_value(enforceViaYul)->implicit_value(true), "Enforce compiling all tests via yul to see if additional tests can be activated.") + ("enforce-compile-to-ewasm", po::bool_switch(&enforceCompileToEwasm)->default_value(enforceCompileToEwasm), "Enforce compiling all tests to Ewasm to see if additional tests can be activated.") + ("enforce-gas-cost", po::value(&enforceGasTest)->default_value(enforceGasTest)->implicit_value(true), "Enforce checking gas cost in semantic tests.") + ("enforce-gas-cost-min-value", po::value(&enforceGasTestMinValue)->default_value(enforceGasTestMinValue), "Threshold value to enforce adding gas checks to a test.") + ("abiencoderv1", po::bool_switch(&useABIEncoderV1)->default_value(useABIEncoderV1), "enables abi encoder v1") + ("show-messages", po::bool_switch(&showMessages)->default_value(showMessages), "enables message output") + ("show-metadata", po::bool_switch(&showMetadata)->default_value(showMetadata), "enables metadata output"); } void CommonOptions::validate() const @@ -139,6 +144,7 @@ void CommonOptions::validate() const bool CommonOptions::parse(int argc, char const* const* argv) { po::variables_map arguments; + addOptions(); po::command_line_parser cmdLineParser(argc, argv); cmdLineParser.options(options); diff --git a/test/Common.h b/test/Common.h index c8a863d8c..f7c8fa733 100644 --- a/test/Common.h +++ b/test/Common.h @@ -70,6 +70,7 @@ struct CommonOptions langutil::EVMVersion evmVersion() const; + virtual void addOptions(); virtual bool parse(int argc, char const* const* argv); // Throws a ConfigException on error virtual void validate() const; diff --git a/test/tools/IsolTestOptions.cpp b/test/tools/IsolTestOptions.cpp index aaa087e47..7f00e88f6 100644 --- a/test/tools/IsolTestOptions.cpp +++ b/test/tools/IsolTestOptions.cpp @@ -56,14 +56,21 @@ std::string editorPath() } -IsolTestOptions::IsolTestOptions(std::string* _editor): +IsolTestOptions::IsolTestOptions(): CommonOptions(description) { + enforceViaYul = true; + enforceGasTest = (evmVersion() == langutil::EVMVersion{}); +} + +void IsolTestOptions::addOptions() +{ + CommonOptions::addOptions(); options.add_options() - ("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.") + ("editor", po::value(&editor)->default_value(editorPath()), "Path to editor for opening test files.") + ("help", po::bool_switch(&showHelp)->default_value(showHelp), "Show this help screen.") + ("no-color", po::bool_switch(&noColor)->default_value(noColor), "Don't use colors.") + ("accept-updates", po::bool_switch(&acceptUpdates)->default_value(acceptUpdates), "Automatically accept expectation updates.") ("test,t", po::value(&testFilter)->default_value("*/*"), "Filters which test units to include."); } @@ -76,15 +83,13 @@ bool IsolTestOptions::parse(int _argc, char const* const* _argv) std::cout << options << std::endl; return false; } - enforceViaYul = true; - enforceGasTest = (evmVersion() == langutil::EVMVersion{}); - enforceGasTestMinValue = 100000; return res; } void IsolTestOptions::validate() const { + CommonOptions::validate(); static std::string filterString{"[a-zA-Z0-9_/*]*"}; static std::regex filterExpression{filterString}; assertThrow( diff --git a/test/tools/IsolTestOptions.h b/test/tools/IsolTestOptions.h index aa9eb2564..5bb02c2bc 100644 --- a/test/tools/IsolTestOptions.h +++ b/test/tools/IsolTestOptions.h @@ -33,8 +33,10 @@ struct IsolTestOptions: CommonOptions bool noColor = false; bool acceptUpdates = false; std::string testFilter = std::string{}; + std::string editor = std::string{}; - IsolTestOptions(std::string* _editor); + explicit IsolTestOptions(); + void addOptions() override; bool parse(int _argc, char const* const* _argv) override; void validate() const override; }; diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index fa7b914aa..73adbc62b 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -121,8 +121,6 @@ public: fs::path const& _basepath, fs::path const& _path ); - - static string editor; private: enum class Request { @@ -145,7 +143,6 @@ private: static bool m_exitRequested; }; -string TestTool::editor; bool TestTool::m_exitRequested = false; TestTool::Result TestTool::process() @@ -258,7 +255,7 @@ TestTool::Request TestTool::handleResponse(bool _exception) } case 'e': cout << endl << endl; - if (system((TestTool::editor + " \"" + m_path.string() + "\"").c_str())) + if (system((m_options.editor + " \"" + m_path.string() + "\"").c_str())) cerr << "Error running editor command." << endl << endl; return Request::Rerun; case 'q': @@ -425,7 +422,7 @@ int main(int argc, char const *argv[]) setupTerminal(); { - auto options = std::make_unique(&TestTool::editor); + auto options = std::make_unique(); if (!options->parse(argc, argv)) return -1;