66 lines
1.9 KiB
C++
66 lines
1.9 KiB
C++
#include <Void/System/Process.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Suite.hpp>
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace
|
|
{
|
|
|
|
using Void::Testing::Test;
|
|
|
|
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);
|
|
};
|
|
|
|
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<std::string> 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<std::string> 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<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"});
|
|
}
|
|
};
|
|
|
|
} // namespace
|