From 8b342cbe6a9aa2e32391e6e7fcc1e80a03fa931f Mon Sep 17 00:00:00 2001 From: Mathias Baumann Date: Tue, 19 Feb 2019 13:24:24 +0100 Subject: [PATCH] Use Boost::Program_Options in soltest --- test/CMakeLists.txt | 2 +- test/Options.cpp | 67 ++++++++++++++++++++++++--------------------- 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e231a6f97..59603442d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -30,7 +30,7 @@ add_executable(soltest ${sources} ${headers} ${libsolidity_sources} ${libsolidity_headers} ${libsolidity_util_sources} ${libsolidity_util_headers} ) -target_link_libraries(soltest PRIVATE libsolc yul solidity evmasm devcore ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES}) +target_link_libraries(soltest PRIVATE libsolc yul solidity evmasm devcore ${Boost_PROGRAM_OPTIONS_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES}) if (LLL) target_link_libraries(soltest PRIVATE lll) diff --git a/test/Options.cpp b/test/Options.cpp index 23de9cc55..1c46f8cf8 100644 --- a/test/Options.cpp +++ b/test/Options.cpp @@ -28,10 +28,12 @@ #include #include +#include using namespace std; using namespace dev::test; namespace fs = boost::filesystem; +namespace po = boost::program_options; Options const& Options::get() { @@ -42,39 +44,42 @@ Options const& Options::get() Options::Options() { auto const& suite = boost::unit_test::framework::master_test_suite(); - for (auto i = 0; i < suite.argc; i++) - if (string(suite.argv[i]) == "--ipcpath" && i + 1 < suite.argc) - { - ipcPath = suite.argv[i + 1]; - i++; - } - else if (string(suite.argv[i]) == "--testpath" && i + 1 < suite.argc) - { - testPath = suite.argv[i + 1]; - i++; - } - else if (string(suite.argv[i]) == "--optimize") - optimize = true; - else if (string(suite.argv[i]) == "--abiencoderv2") - useABIEncoderV2 = true; - else if (string(suite.argv[i]) == "--evm-version") - { - evmVersionString = i + 1 < suite.argc ? suite.argv[i + 1] : "INVALID"; - ++i; - } - else if (string(suite.argv[i]) == "--show-messages") - showMessages = true; - else if (string(suite.argv[i]) == "--no-ipc") - disableIPC = true; - else if (string(suite.argv[i]) == "--no-smt") - disableSMT = true; - if (!disableIPC && ipcPath.empty()) - if (auto path = getenv("ETH_TEST_IPC")) - ipcPath = path; + if (suite.argc == 0) + return; - if (testPath.empty()) - testPath = getTestPath(); + po::options_description options("", + po::options_description::m_default_line_length, + po::options_description::m_default_line_length - 23); + + options.add_options() + ("testpath", po::value(&testPath)->default_value(getTestPath()), "path to test files") + ("ipcpath", po::value(&ipcPath)->default_value(getenv("ETH_TEST_IPC")), "path to ipc socket") + ("no-ipc", po::bool_switch(&disableIPC), "disable semantic tests") + ("no-smt", po::bool_switch(&disableSMT), "disable SMT checker") + ("optimize", po::bool_switch(&optimize), "enables optimization") + ("abiencoderv2", po::bool_switch(&useABIEncoderV2), "enables abi encoder v2") + ("evm-version", po::value(&evmVersionString), "which evm version to use") + ("show-messages", po::bool_switch(&showMessages), "enables message output"); + + po::variables_map arguments; + + po::command_line_parser cmdLineParser(suite.argc, suite.argv); + cmdLineParser.options(options); + po::store(cmdLineParser.run(), arguments); + po::notify(arguments); + + if (!disableIPC) + { + solAssert( + !ipcPath.empty(), + "No ipc path specified. The --ipcpath argument is required, unless --no-ipc is used." + ); + solAssert( + fs::exists(ipcPath), + "Invalid ipc path specified." + ); + } } void Options::validate() const