Skip to content
Bitcoin Roots

v29.4-roots.2 · Commit 2: [PATCH 02/21] runtime: preserve shared operator controls

src/test/system_tests.cpp

Before: src/test/system_tests.cpp · After: src/test/system_tests.cpp

File metadata
index a5d9be07d526864d075cb80b7081645f4f7d3b74..dec4d4182904012c3ff319866ce846254a72340b 100644

Download original patch · Release notes

Diff rows 1–66 of 66. Line numbers refer to the original before/after files.

+ Added− RemovedUnmarked lines are context.

Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.

src/test/system_tests.cpp CHANGED
@@ -25,7 +25,11 @@ BOOST_AUTO_TEST_CASE(run_command)
25
25
  BOOST_CHECK(result.isNull());
26
26
  }
27
27
  {
28
+ #ifdef WIN32
29
+ const UniValue result = RunCommandParseJSON("cmd.exe /c echo {\"success\": true}");
30
+ #else
28
31
  const UniValue result = RunCommandParseJSON("echo {\"success\": true}");
32
+ #endif
29
33
  BOOST_CHECK(result.isObject());
30
34
  const UniValue& success = result.find_value("success");
31
35
  BOOST_CHECK(!success.isNull());
@@ -33,12 +37,20 @@ BOOST_AUTO_TEST_CASE(run_command)
33
37
  }
34
38
  {
35
39
  // An invalid command is handled by cpp-subprocess
40
+ #ifdef WIN32
41
+ const std::string expected{"CreateProcess failed: "};
42
+ #else
36
43
  const std::string expected{"execve failed: "};
44
+ #endif
37
45
  BOOST_CHECK_EXCEPTION(RunCommandParseJSON("invalid_command"), subprocess::CalledProcessError, HasReason(expected));
38
46
  }
39
47
  {
40
48
  // Return non-zero exit code, no output to stderr
49
+ #ifdef WIN32
50
+ const std::string command{"cmd.exe /c exit 1"};
51
+ #else
41
52
  const std::string command{"false"};
53
+ #endif
42
54
  BOOST_CHECK_EXCEPTION(RunCommandParseJSON(command), std::runtime_error, [&](const std::runtime_error& e) {
43
55
  const std::string what{e.what()};
44
56
  BOOST_CHECK(what.find(strprintf("RunCommandParseJSON error: process(%s) returned 1: \n", command)) != std::string::npos);
@@ -47,7 +59,11 @@ BOOST_AUTO_TEST_CASE(run_command)
47
59
  }
48
60
  {
49
61
  // Return non-zero exit code, with error message for stderr
62
+ #ifdef WIN32
63
+ const std::string command{"cmd.exe /c \"echo err 1>&2 && exit 1\""};
64
+ #else
50
65
  const std::string command{"sh -c 'echo err 1>&2 && false'"};
66
+ #endif
51
67
  const std::string expected{"err"};
52
68
  BOOST_CHECK_EXCEPTION(RunCommandParseJSON(command), std::runtime_error, [&](const std::runtime_error& e) {
53
69
  const std::string what(e.what());
@@ -58,17 +74,23 @@ BOOST_AUTO_TEST_CASE(run_command)
58
74
  }
59
75
  {
60
76
  // Unable to parse JSON
77
+ #ifdef WIN32
78
+ const std::string command{"cmd.exe /c echo {"};
79
+ #else
61
80
  const std::string command{"echo {"};
81
+ #endif
62
82
  BOOST_CHECK_EXCEPTION(RunCommandParseJSON(command), std::runtime_error, HasReason("Unable to parse JSON: {"));
63
83
  }
64
- // Test std::in
84
+ #ifndef WIN32
65
85
  {
86
+ // Test stdin
66
87
  const UniValue result = RunCommandParseJSON("cat", "{\"success\": true}");
67
88
  BOOST_CHECK(result.isObject());
68
89
  const UniValue& success = result.find_value("success");
69
90
  BOOST_CHECK(!success.isNull());
70
91
  BOOST_CHECK_EQUAL(success.get_bool(), true);
71
92
  }
93
+ #endif
72
94
  }
73
95
  #endif // ENABLE_EXTERNAL_SIGNER
74
96