Files
Library/tests/standalone/System/ProcessStream.cpp
T
faumarayandClaude Opus 4.8 80293ee56f Add async/resilience/reflection primitives + FSM v2 rewrite
A round of new universal capabilities (all generic — templated/reflection
based, no app coupling), verified by the test suite (1103 passing):

Data reflection:
- Reflect.hpp now (de)serializes chrono::duration, chrono::time_point,
  std::variant (tagged), std::array, and non-string-keyed std::map;
  Meta.hpp gains is_time_point_v et al.

Async:
- EventBus gains Mode::Async (worker-thread dispatch + flush()).
- ThreadPool gains a bounded queue, try_submit(), and rejection stats.

New modules / containers:
- Resilience: TokenBucket, KeyedRateLimiter<Key>, CircuitBreaker,
  ResourceMonitor.
- Containers: BufferPool<T> (size-class buffer reuse) and Cache<K,V>
  (per-entry TTL, LRU/LFU/FIFO eviction, hit/miss stats).
- System: process/CPU/memory metrics (Metrics.hpp) and a streaming
  Process API.

Plus FSM v2 (typed Success/Failure, sub-machines, parallel regions,
history states, deferred events), Configuration/Logging reflection
helpers, and the accompanying test suites.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-22 15:45:16 +03:00

67 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> {
// 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);
};
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);
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"});
}
// 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);
};
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"});
}
// 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(
"/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