#include #include #include #include #include namespace { using Void::Testing::Test; struct ProcessStream : Void::Testing::Suite { Test streams_stdout_lines() { std::vector lines; Void::Process::StreamCallbacks cb; cb.on_stdout = [&](std::string_view l) { lines.emplace_back(l); }; 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); const std::vector expected{"a", "b", "c"}; Void::Testing::expect(lines == expected); Void::Testing::expect_eq(r->out, std::string{"a\nb\nc\n"}); } Test flushes_trailing_partial_line() { std::vector lines; Void::Process::StreamCallbacks cb; cb.on_stdout = [&](std::string_view l) { lines.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 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"}); } }; } // namespace