MCPcopy Create free account
hub / github.com/3rdparty/libprocess / await_subprocess

Function await_subprocess

src/tests/ssl_tests.cpp:78–116  ·  view source on GitHub ↗

Wait for a subprocess and test the status code for the following conditions of 'expected_status': 1. 'None' = Anything but '0'. 2. 'Some' = the value of 'expected_status'. Returns Nothing if the resulting status code matches the expectation otherwise a Failure with the output of the subprocess. TODO(jmlvanre): Turn this into a generally useful abstraction for gtest where we can have a more straigt

Source from the content-addressed store, hash-verified

76// TODO(jmlvanre): Turn this into a generally useful abstraction for
77// gtest where we can have a more straigtforward 'expected_status'.
78Future<Nothing> await_subprocess(
79 const Subprocess& subprocess,
80 const Option<int>& expected_status = None())
81{
82 // Dup the pipe fd of the subprocess so we can read the output if
83 // needed.
84 Try<int_fd> dup = os::dup(subprocess.out().get());
85 if (dup.isError()) {
86 return Failure(dup.error());
87 }
88
89 int_fd out = dup.get();
90
91 // Once we get the status of the process.
92 return subprocess.status()
93 .then([=](const Option<int>& status) -> Future<Nothing> {
94 // If the status is not set, fail out.
95 if (status.isNone()) {
96 return Failure("Subprocess status is none");
97 }
98
99 // If the status is not what we expect then fail out with the
100 // output of the subprocess. The failure message will include
101 // the assertion failures of the subprocess.
102 if ((expected_status.isSome() && status.get() != expected_status.get()) ||
103 (expected_status.isNone() && status.get() == 0)) {
104 return io::read(out)
105 .then([](const string& output) -> Future<Nothing> {
106 return Failure("\n[++++++++++] Subprocess output.\n" + output +
107 "[++++++++++]\n");
108 });
109 }
110
111 // If the subprocess ran successfully then return nothing.
112 return Nothing();
113 }).onAny([=]() {
114 os::close(out);
115 });
116}
117
118
119// The SSL protocols that we support through configuration flags.

Callers 3

TEST_FFunction · 0.85
TEST_PFunction · 0.85
foreachFunction · 0.85

Calls 7

FailureClass · 0.85
closeFunction · 0.85
outMethod · 0.80
statusMethod · 0.80
readFunction · 0.50
getMethod · 0.45
thenMethod · 0.45

Tested by

no test coverage detected