- Allowlist Configuration, Crypto and System for the Windows target. - System: link winmm for the Win32 audio backend; include windows.h before mmsystem.h. - Tests: add a whole-file // @requires-posix gate (CMake path and the VBS build.cpp) and mark the POSIX-only System suites; skip helper-based cases on Windows; make setenv/unsetenv and getpid portable. - The POSIX process helper is no longer built on Windows. Cross-built with x86_64-w64-mingw32 GCC 16.2: all modules and VoidTests.exe link. Linux System+Testing suite still passes (477 tests, 474 passed). Refs #65
120 lines
4.0 KiB
C++
120 lines
4.0 KiB
C++
#include <Void/System/Process.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <string>
|
|
|
|
Void::Testing::Test shell_echo_captures_stdout()
|
|
{
|
|
auto r = Void::Process::shell("echo hello");
|
|
Void::Testing::expect(r.has_value());
|
|
Void::Testing::expect_eq(r->exit_code, 0);
|
|
Void::Testing::expect(r->out.find("hello") != std::string::npos);
|
|
}
|
|
|
|
Void::Testing::Test shell_exit_code_propagates()
|
|
{
|
|
auto r = Void::Process::shell("exit 42");
|
|
Void::Testing::expect(r.has_value());
|
|
Void::Testing::expect_eq(r->exit_code, 42);
|
|
}
|
|
|
|
Void::Testing::Test shell_captures_stderr_separately()
|
|
{
|
|
auto r = Void::Process::shell("echo err_output >&2");
|
|
Void::Testing::expect(r.has_value());
|
|
Void::Testing::expect(r->err.find("err_output") != std::string::npos);
|
|
Void::Testing::expect(r->out.find("err_output") == std::string::npos);
|
|
}
|
|
|
|
// The process helper is POSIX-only; these cases are skipped on Windows.
|
|
|
|
Void::Testing::Test run_with_args_builds_correct_argv()
|
|
{
|
|
#ifdef VOID_PROCESS_HELPER_PATH
|
|
auto r = Void::Process::run(VOID_PROCESS_HELPER_PATH,
|
|
{"echo", "hello", "world"});
|
|
Void::Testing::expect(r.has_value());
|
|
Void::Testing::expect_eq(r->exit_code, 0);
|
|
Void::Testing::expect(r->out.find("hello world") != std::string::npos);
|
|
#else
|
|
Void::Testing::skip("POSIX process helper is not available");
|
|
#endif
|
|
}
|
|
|
|
Void::Testing::Test run_stdin_forwarded_to_cat()
|
|
{
|
|
#ifdef VOID_PROCESS_HELPER_PATH
|
|
auto r = Void::Process::run(VOID_PROCESS_HELPER_PATH, {"cat"}, "piped_input");
|
|
Void::Testing::expect(r.has_value());
|
|
Void::Testing::expect_eq(r->exit_code, 0);
|
|
Void::Testing::expect(r->out.find("piped_input") != std::string::npos);
|
|
#else
|
|
Void::Testing::skip("POSIX process helper is not available");
|
|
#endif
|
|
}
|
|
|
|
Void::Testing::Test run_direct_exit_code_propagates()
|
|
{
|
|
#ifdef VOID_PROCESS_HELPER_PATH
|
|
auto r = Void::Process::run(VOID_PROCESS_HELPER_PATH, {"exit", "42"});
|
|
Void::Testing::expect(r.has_value());
|
|
Void::Testing::expect_eq(r->exit_code, 42);
|
|
#else
|
|
Void::Testing::skip("POSIX process helper is not available");
|
|
#endif
|
|
}
|
|
|
|
Void::Testing::Test run_direct_stdout_and_stderr_independent()
|
|
{
|
|
#ifdef VOID_PROCESS_HELPER_PATH
|
|
auto r = Void::Process::run(VOID_PROCESS_HELPER_PATH, {"streams"});
|
|
Void::Testing::expect(r.has_value());
|
|
Void::Testing::expect_eq(r->exit_code, 0);
|
|
Void::Testing::expect(r->out.find("to_stdout") != std::string::npos);
|
|
Void::Testing::expect(r->err.find("to_stderr") != std::string::npos);
|
|
Void::Testing::expect(r->out.find("to_stderr") == std::string::npos);
|
|
Void::Testing::expect(r->err.find("to_stdout") == std::string::npos);
|
|
#else
|
|
Void::Testing::skip("POSIX process helper is not available");
|
|
#endif
|
|
}
|
|
|
|
Void::Testing::Test run_missing_executable_returns_code_127()
|
|
{
|
|
#ifdef _WIN32
|
|
Void::Testing::skip("exit-code convention differs on Windows");
|
|
#else
|
|
auto r = Void::Process::run("/this/binary/does/not/exist");
|
|
// fork succeeds, execvp fails, child _exits(127)
|
|
Void::Testing::expect(r.has_value());
|
|
Void::Testing::expect_eq(r->exit_code, 127);
|
|
#endif
|
|
}
|
|
|
|
Void::Testing::Test run_stdout_and_stderr_independent()
|
|
{
|
|
auto r = Void::Process::shell(
|
|
"echo to_stdout; echo to_stderr >&2");
|
|
Void::Testing::expect(r.has_value());
|
|
Void::Testing::expect(r->out.find("to_stdout") != std::string::npos);
|
|
Void::Testing::expect(r->err.find("to_stderr") != std::string::npos);
|
|
Void::Testing::expect(r->out.find("to_stderr") == std::string::npos);
|
|
Void::Testing::expect(r->err.find("to_stdout") == std::string::npos);
|
|
}
|
|
|
|
Void::Testing::Test run_large_output_is_captured_fully()
|
|
{
|
|
#ifdef VOID_PROCESS_HELPER_PATH
|
|
// Generate 10 000 lines; poll-based reader must accumulate them all.
|
|
auto r = Void::Process::run(VOID_PROCESS_HELPER_PATH, {"seq", "1", "10000"});
|
|
Void::Testing::expect(r.has_value());
|
|
Void::Testing::expect_eq(r->exit_code, 0);
|
|
// "10000\n" must be present, and total output must be substantial
|
|
Void::Testing::expect(r->out.find("10000") != std::string::npos);
|
|
Void::Testing::expect(r->out.size() > 40000);
|
|
#else
|
|
Void::Testing::skip("POSIX process helper is not available");
|
|
#endif
|
|
}
|