Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests to verify capturing output from ChildProcess
Summary: as above. Reviewed By: sid0 Differential Revision: D4424911 fbshipit-source-id: 595457173c4b21d512a18fd17c360d529e72299b
- Loading branch information
1 parent
3aec455
commit ec480f1
Showing
7 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -375,4 +375,9 @@ void ChildProcess::kill( | |
} | ||
#endif | ||
} | ||
|
||
Pipe& ChildProcess::pipe(int fd) { | ||
return *pipes_.at(fd); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,6 +144,8 @@ class ChildProcess { | |
#endif | ||
); | ||
|
||
Pipe& pipe(int fd); | ||
|
||
private: | ||
pid_t pid_; | ||
bool waited_{false}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* Copyright 2017-present Facebook, Inc. | ||
* Licensed under the Apache License, Version 2.0. */ | ||
#include "watchman_system.h" | ||
#include "ChildProcess.h" | ||
#include "thirdparty/tap.h" | ||
|
||
using watchman::ChildProcess; | ||
using Environment = ChildProcess::Environment; | ||
using Options = ChildProcess::Options; | ||
|
||
void test_pipe() { | ||
Options opts; | ||
opts.pipeStdout(); | ||
ChildProcess echo( | ||
{ | ||
#ifndef _WIN32 | ||
"/bin/echo", | ||
#else | ||
"cmd", | ||
"/c", | ||
"echo", | ||
#endif | ||
"hello"}, | ||
std::move(opts)); | ||
|
||
echo.pipe(STDOUT_FILENO).read.clearNonBlock(); | ||
echo.wait(); | ||
|
||
char buf[128]; | ||
auto len = read(echo.pipe(STDOUT_FILENO).read.fd(), buf, sizeof(buf)); | ||
|
||
ok(len >= 0, | ||
"read from pipe was successful: len=%d err=%s", | ||
len, | ||
strerror(errno)); | ||
w_string_piece line(buf, len); | ||
ok(line.startsWith("hello"), "starts with hello"); | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
(void)argc; | ||
(void)argv; | ||
|
||
plan_tests(2); | ||
test_pipe(); | ||
|
||
return exit_status(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters