diff --git a/src/test/test_bitcoin_main.cpp b/src/test/test_bitcoin_main.cpp index 0aab23f11..cd5763ea5 100644 --- a/src/test/test_bitcoin_main.cpp +++ b/src/test/test_bitcoin_main.cpp @@ -1,49 +1,57 @@ // Copyright (c) 2011-2016 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #define BOOST_TEST_MODULE Bitcoin Test Suite -#define BOOST_TEST_NO_MAIN #include #include #include #include #include std::unique_ptr g_connman; std::unique_ptr g_banman; [[noreturn]] void Shutdown(void *parg) { std::exit(EXIT_SUCCESS); } [[noreturn]] void StartShutdown() { std::exit(EXIT_SUCCESS); } bool ShutdownRequested() { return false; } -int main(int argc, char *argv[]) { - // Additional CLI params supported by test_bitcoin: - std::set testArgs = { - "-phononactivationtime", - }; - - // Note: gArgs.ParseParameters() cannot be called here or it will fail to - // parse BOOST runtime params. - for (int i = 1; i < argc; i++) { - std::string key(argv[i]); - std::string value; - if (ParseKeyValue(key, value)) { - if (testArgs.count(key) > 0) { - gArgs.ForceSetArg(key, value); - } +namespace utf = boost::unit_test::framework; + +/* + * Global fixture for passing custom arguments, and clearing them all after each + * test case. + */ +struct CustomArgumentsFixture { + std::string error; + + CustomArgumentsFixture() { + std::set testArgs = { + "-phononactivationtime", + }; + + for (const auto &arg : testArgs) { + gArgs.AddArg(arg, "", false, OptionsCategory::HIDDEN); + } + + if (!gArgs.ParseParameters(utf::master_test_suite().argc, + utf::master_test_suite().argv, error)) { + throw utf::setup_error(error); } } - return boost::unit_test::unit_test_main(&init_unit_test, argc, argv); -} + + ~CustomArgumentsFixture(){}; +}; + +BOOST_GLOBAL_FIXTURE(CustomArgumentsFixture);