diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1ecc40b367fb..f5feb9959341 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -101,7 +101,6 @@ add_library(bitcoin_common STATIC EXCLUDE_FROM_ALL common/messages.cpp common/netif.cpp common/pcp.cpp - common/run_command.cpp common/settings.cpp common/signmessage.cpp common/system.cpp diff --git a/src/common/run_command.cpp b/src/common/run_command.cpp deleted file mode 100644 index d79b78187929..000000000000 --- a/src/common/run_command.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2022-present The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include - -#include -#include -#include -#include - -UniValue RunCommandParseJSON(const std::vector& cmd_args, const std::string& str_std_in) -{ - namespace sp = subprocess; - - UniValue result_json; - std::istringstream stdout_stream; - std::istringstream stderr_stream; - - if (cmd_args.empty()) return UniValue::VNULL; - - auto c = sp::Popen(cmd_args, sp::input{sp::PIPE}, sp::output{sp::PIPE}, sp::error{sp::PIPE}); - if (!str_std_in.empty()) { - c.send(str_std_in); - } - auto [out_res, err_res] = c.communicate(); - stdout_stream.str(std::string{out_res.buf.begin(), out_res.buf.end()}); - stderr_stream.str(std::string{err_res.buf.begin(), err_res.buf.end()}); - - std::string result; - std::string error; - std::getline(stdout_stream, result); - std::getline(stderr_stream, error); - - const int n_error = c.retcode(); - if (n_error) throw std::runtime_error(strprintf("RunCommandParseJSON error: process(%s) returned %d: %s\n", util::Join(cmd_args, " "), n_error, error)); - if (!result_json.read(result)) throw std::runtime_error("Unable to parse JSON: " + result); - - return result_json; -} diff --git a/src/common/run_command.h b/src/common/run_command.h deleted file mode 100644 index 9162c704561b..000000000000 --- a/src/common/run_command.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2022-present The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef BITCOIN_COMMON_RUN_COMMAND_H -#define BITCOIN_COMMON_RUN_COMMAND_H - -#include -#include - -class UniValue; - -/** - * Execute a command which returns JSON, and parse the result. - * - * @param cmd_args The command and arguments - * @param str_std_in string to pass to stdin - * @return parsed JSON - */ -UniValue RunCommandParseJSON(const std::vector& cmd_args, const std::string& str_std_in = ""); - -#endif // BITCOIN_COMMON_RUN_COMMAND_H diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index cbab383a9f82..666487b5fb3c 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -59,7 +59,6 @@ add_executable(test_bitcoin miniminer_tests.cpp miniscript_tests.cpp minisketch_tests.cpp - mock_process.cpp multisig_tests.cpp bip328_tests.cpp net_peer_connection_tests.cpp @@ -101,7 +100,6 @@ add_executable(test_bitcoin streams_tests.cpp sync_tests.cpp system_ram_tests.cpp - system_tests.cpp testnet4_miner_tests.cpp threadpool_tests.cpp timeoffsets_tests.cpp @@ -175,8 +173,6 @@ function(add_boost_test source_file) list(TRANSFORM test_suite_macro REPLACE "(BOOST_FIXTURE_TEST_SUITE|BOOST_AUTO_TEST_SUITE)\\(" "" ) - # The mock_process test suite does not contain unit tests. - list(REMOVE_ITEM test_suite_macro "mock_process") foreach(test_suite_name IN LISTS test_suite_macro) add_test(NAME ${test_suite_name} COMMAND test_bitcoin --run_test=${test_suite_name} --catch_system_error=no --log_level=test_suite -- -printtoconsole=1 diff --git a/src/test/mock_process.cpp b/src/test/mock_process.cpp deleted file mode 100644 index c9100c9fe0d8..000000000000 --- a/src/test/mock_process.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2025-present The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or https://opensource.org/license/mit/. - -#include - -#include -#include - -BOOST_AUTO_TEST_SUITE(mock_process, *boost::unit_test::disabled()) - -BOOST_AUTO_TEST_CASE(valid_json, *boost::unit_test::disabled()) -{ - std::cout << R"({"success": true})" << std::endl; -} - -BOOST_AUTO_TEST_CASE(nonzeroexit_nooutput, *boost::unit_test::disabled()) -{ - BOOST_FAIL("Test unconditionally fails."); -} - -BOOST_AUTO_TEST_CASE(nonzeroexit_stderroutput, *boost::unit_test::disabled()) -{ - std::cerr << "err\n"; - BOOST_FAIL("Test unconditionally fails."); -} - -BOOST_AUTO_TEST_CASE(invalid_json, *boost::unit_test::disabled()) -{ - std::cout << "{\n"; -} - -BOOST_AUTO_TEST_CASE(pass_stdin_to_stdout, *boost::unit_test::disabled()) -{ - std::string s; - std::getline(std::cin, s); - std::cout << s << std::endl; -} - -BOOST_AUTO_TEST_SUITE_END() diff --git a/src/test/system_tests.cpp b/src/test/system_tests.cpp deleted file mode 100644 index 90d741adc3a9..000000000000 --- a/src/test/system_tests.cpp +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright (c) 2019-present The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. -// - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -BOOST_FIXTURE_TEST_SUITE(system_tests, BasicTestingSetup) - -static std::vector mock_executable(std::string name) -{ - // Invoke the mock_process/* test case with all unsolicited output suppressed. - return { - boost::unit_test::framework::master_test_suite().argv[0], - // Disable false-positive memory leak dumps to stderr - // in debug builds when using the Windows UCRT. - "--detect_memory_leaks=0", - // Disable logging to stdout. - "--log_level=nothing", - // Disable the test report to stderr. - "--report_level=no", - "--run_test=mock_process/" + name, - }; -} - -BOOST_AUTO_TEST_CASE(run_command) -{ - { - const UniValue result = RunCommandParseJSON({}); - BOOST_CHECK(result.isNull()); - } - { - const UniValue result = RunCommandParseJSON(mock_executable("valid_json")); - BOOST_CHECK(result.isObject()); - const UniValue& success = result.find_value("success"); - BOOST_CHECK(!success.isNull()); - BOOST_CHECK_EQUAL(success.get_bool(), true); - } - { - // An invalid command is handled by cpp-subprocess -#ifdef WIN32 - const std::string expected{"CreateProcess failed: "}; -#else - const std::string expected{"execve failed: "}; -#endif - BOOST_CHECK_EXCEPTION(RunCommandParseJSON({"invalid_command"}), subprocess::CalledProcessError, HasReason(expected)); - } - { - // Return non-zero exit code, no output to stderr - const std::vector command = mock_executable("nonzeroexit_nooutput"); - BOOST_CHECK_EXCEPTION(RunCommandParseJSON(command), std::runtime_error, [&](const std::runtime_error& e) { - const std::string what{e.what()}; - BOOST_CHECK(what.find(strprintf("RunCommandParseJSON error: process(%s) returned %d: \n", util::Join(command, " "), boost::exit_test_failure)) != std::string::npos); - return true; - }); - } - { - // Return non-zero exit code, with error message for stderr - const std::vector command = mock_executable("nonzeroexit_stderroutput"); - const std::string expected{"err"}; - BOOST_CHECK_EXCEPTION(RunCommandParseJSON(command), std::runtime_error, [&](const std::runtime_error& e) { - const std::string what(e.what()); - BOOST_CHECK(what.find(strprintf("RunCommandParseJSON error: process(%s) returned %s: %s", util::Join(command, " "), boost::exit_test_failure, "err")) != std::string::npos); - BOOST_CHECK(what.find(expected) != std::string::npos); - return true; - }); - } - { - // Unable to parse JSON - BOOST_CHECK_EXCEPTION(RunCommandParseJSON(mock_executable("invalid_json")), std::runtime_error, HasReason("Unable to parse JSON: {")); - } - { - // Test stdin - const UniValue result = RunCommandParseJSON(mock_executable("pass_stdin_to_stdout"), "{\"success\": true}"); - BOOST_CHECK(result.isObject()); - const UniValue& success = result.find_value("success"); - BOOST_CHECK(!success.isNull()); - BOOST_CHECK_EQUAL(success.get_bool(), true); - } -} - -BOOST_AUTO_TEST_SUITE_END() diff --git a/test/lint/lint-includes.py b/test/lint/lint-includes.py index 18f47240f9dd..2e8417ea7341 100755 --- a/test/lint/lint-includes.py +++ b/test/lint/lint-includes.py @@ -21,7 +21,6 @@ ] + SHARED_EXCLUDED_SUBTREES EXPECTED_BOOST_INCLUDES = [ - "boost/cstdlib.hpp", "boost/multi_index/detail/hash_index_iterator.hpp", "boost/multi_index/hashed_index.hpp", "boost/multi_index/identity.hpp",