feat(System): harden OwnedFd/Child process spawn, full-duplex bounds, durable replace_file, safe TempFile/TempDir, and SystemOnly consumer (M-SYSTEM-01, M-SYSTEM-02, M-SYSTEM-05)
This commit is contained in:
1 parent
3f67b1ecb7
commit
fcdbc063b2
14 files changed
+3538
-890
No files matched your search
@@ -7,60 +7,59 @@
|
||||
|
||||
namespace
|
||||
{
|
||||
using Void::Testing::Test;
|
||||
|
||||
struct ProcessStream : Void::Testing::Suite<ProcessStream> {
|
||||
// stdout lines are delivered to the callback as they arrive, and
|
||||
// the full output is still captured.
|
||||
Test streams_stdout_lines()
|
||||
{
|
||||
std::vector<std::string> lines;
|
||||
Void::Process::StreamCallbacks cb;
|
||||
cb.on_stdout = [&](std::string_view l) {
|
||||
lines.emplace_back(l);
|
||||
};
|
||||
using Void::Testing::Test;
|
||||
|
||||
auto r = Void::Process::run_streaming(
|
||||
"/bin/sh", {"-c", "printf 'a\\nb\\nc\\n'"}, cb);
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(r->exit_code, 0);
|
||||
struct ProcessStream : Void::Testing::Suite<ProcessStream> {
|
||||
Test streams_stdout_lines()
|
||||
{
|
||||
std::vector<std::string> lines;
|
||||
Void::Process::StreamCallbacks cb;
|
||||
cb.on_stdout = [&](std::string_view l) {
|
||||
lines.emplace_back(l);
|
||||
};
|
||||
|
||||
const std::vector<std::string> expected{"a", "b", "c"};
|
||||
Void::Testing::expect(lines == expected);
|
||||
Void::Testing::expect_eq(r->out, std::string{"a\nb\nc\n"});
|
||||
}
|
||||
auto r = Void::Process::run_streaming(
|
||||
VOID_PROCESS_HELPER_PATH, {"lines", "a", "b", "c"}, cb);
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(r->exit_code, 0);
|
||||
|
||||
// A trailing partial line (no newline) is flushed at EOF.
|
||||
Test flushes_trailing_partial_line()
|
||||
{
|
||||
std::vector<std::string> lines;
|
||||
Void::Process::StreamCallbacks cb;
|
||||
cb.on_stdout = [&](std::string_view l) {
|
||||
lines.emplace_back(l);
|
||||
};
|
||||
const std::vector<std::string> expected{"a", "b", "c"};
|
||||
Void::Testing::expect(lines == expected);
|
||||
Void::Testing::expect_eq(r->out, std::string{"a\nb\nc\n"});
|
||||
}
|
||||
|
||||
auto r = Void::Process::run_streaming(
|
||||
"/bin/sh", {"-c", "printf 'no-newline'"}, cb);
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(lines.size(), std::size_t{1});
|
||||
Void::Testing::expect_eq(lines.at(0),
|
||||
std::string{"no-newline"});
|
||||
}
|
||||
Test flushes_trailing_partial_line()
|
||||
{
|
||||
std::vector<std::string> lines;
|
||||
Void::Process::StreamCallbacks cb;
|
||||
cb.on_stdout = [&](std::string_view l) {
|
||||
lines.emplace_back(l);
|
||||
};
|
||||
|
||||
// stderr is routed to its own callback.
|
||||
Test streams_stderr_separately()
|
||||
{
|
||||
std::vector<std::string> errs;
|
||||
Void::Process::StreamCallbacks cb;
|
||||
cb.on_stderr = [&](std::string_view l) {
|
||||
errs.emplace_back(l);
|
||||
};
|
||||
auto r = Void::Process::run_streaming(
|
||||
VOID_PROCESS_HELPER_PATH,
|
||||
{"lines", "--no-newline", "no-newline"},
|
||||
cb);
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(lines.size(), std::size_t{1});
|
||||
Void::Testing::expect_eq(lines.at(0), std::string{"no-newline"});
|
||||
}
|
||||
|
||||
Test streams_stderr_separately()
|
||||
{
|
||||
std::vector<std::string> errs;
|
||||
Void::Process::StreamCallbacks cb;
|
||||
cb.on_stderr = [&](std::string_view l) {
|
||||
errs.emplace_back(l);
|
||||
};
|
||||
|
||||
auto r = Void::Process::run_streaming(
|
||||
VOID_PROCESS_HELPER_PATH, {"lines", "--stderr", "oops"}, cb);
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(errs.size(), std::size_t{1});
|
||||
Void::Testing::expect_eq(errs.at(0), std::string{"oops"});
|
||||
}
|
||||
};
|
||||
|
||||
auto r = Void::Process::run_streaming(
|
||||
"/bin/sh", {"-c", "printf 'oops\\n' 1>&2"}, cb);
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(errs.size(), std::size_t{1});
|
||||
Void::Testing::expect_eq(errs.at(0), std::string{"oops"});
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
Reference in new issue
Block a user