test(process): cover pipes timeouts and process state
This commit is contained in:
@@ -25,5 +25,57 @@ int main() {
|
||||
result = izo::LaunchProcess({"/bin/true", {}, directory / "missing", false});
|
||||
CHECK(!result);
|
||||
CHECK(!result.errorMessage.empty());
|
||||
|
||||
izo::ProcessOptions run_options;
|
||||
run_options.executable = "/bin/sh";
|
||||
run_options.arguments = {"-c", "printf stdout; printf stderr >&2; exit 7"};
|
||||
run_options.captureOutput = true;
|
||||
run_options.timeoutMs = 5000;
|
||||
const auto run = izo::RunProcess(run_options);
|
||||
CHECK(run.started);
|
||||
CHECK(!run.timedOut);
|
||||
CHECK(run.exitCode == 7);
|
||||
CHECK(run.stdoutText == "stdout");
|
||||
CHECK(run.stderrText == "stderr");
|
||||
|
||||
izo::ProcessOptions pipe_options;
|
||||
pipe_options.executable = "/bin/cat";
|
||||
pipe_options.captureOutput = true;
|
||||
pipe_options.pipeStdin = true;
|
||||
auto process = izo::StartProcess(pipe_options);
|
||||
CHECK(process);
|
||||
CHECK(process.Id() > 0);
|
||||
CHECK(process.IsRunning());
|
||||
CHECK(izo::IsProcessRunning(process.Id()));
|
||||
CHECK(process.WriteStdin("input through pipe"));
|
||||
CHECK(process.CloseStdin());
|
||||
CHECK(process.Wait(5000));
|
||||
CHECK(process.ExitCode() == 0);
|
||||
CHECK(process.Stdout() == "input through pipe");
|
||||
CHECK(process.Stderr().empty());
|
||||
CHECK(!process.IsRunning());
|
||||
|
||||
izo::ProcessOptions timeout_options;
|
||||
timeout_options.executable = "/bin/sh";
|
||||
timeout_options.arguments = {"-c", "sleep 10"};
|
||||
timeout_options.timeoutMs = 20;
|
||||
const auto timeout = izo::RunProcess(timeout_options);
|
||||
CHECK(timeout.started);
|
||||
CHECK(timeout.timedOut);
|
||||
CHECK(timeout.exitCode != 0);
|
||||
|
||||
izo::ProcessOptions output_options;
|
||||
output_options.executable = "/bin/sh";
|
||||
output_options.arguments = {"-c", "yes x | head -c 200000"};
|
||||
output_options.captureOutput = true;
|
||||
output_options.timeoutMs = 5000;
|
||||
const auto output = izo::RunProcess(output_options);
|
||||
CHECK(output);
|
||||
CHECK(output.stdoutText.size() == 200000);
|
||||
|
||||
CHECK(izo::GetCurrentProcessId() > 0);
|
||||
CHECK(izo::GetParentProcessId() > 0);
|
||||
CHECK(izo::IsProcessRunning(izo::GetCurrentProcessId()));
|
||||
CHECK(!izo::IsProcessRunning(0));
|
||||
std::filesystem::remove_all(directory);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user