diff --git a/build.cpp b/build.cpp index b48e808..feadbef 100644 --- a/build.cpp +++ b/build.cpp @@ -881,11 +881,13 @@ void build(Void::Build::Project &project) if (!test_file_dependencies_selected(root / file, selected)) { continue; } - if (!compiler_has_reflection()) { + if (!compiler_has_reflection() || windows) { std::ifstream gate{root / file}; std::string content((std::istreambuf_iterator{gate}), std::istreambuf_iterator{}); - if (content.find("// @requires-reflection") != std::string::npos) { + if ((windows && content.find("// @requires-posix") != std::string::npos) || + (!compiler_has_reflection() && + content.find("// @requires-reflection") != std::string::npos)) { continue; } } diff --git a/cmake/Targets.cmake b/cmake/Targets.cmake index 65cfed8..85d5af1 100644 --- a/cmake/Targets.cmake +++ b/cmake/Targets.cmake @@ -47,8 +47,10 @@ set(VOID_WINDOWS_MODULES Algorithms Async Binary + Configuration Containers Core + Crypto Data Discovery Fsm @@ -63,6 +65,7 @@ set(VOID_WINDOWS_MODULES ObservabilityHooks Scheduler Service + System Testing TestingMock Text diff --git a/docs/targets.md b/docs/targets.md index 49e3fb1..d61f6d6 100644 --- a/docs/targets.md +++ b/docs/targets.md @@ -108,7 +108,7 @@ recognized and configured like Linux; musl-specific behaviour (subprocess | CMake / generator | CMake 4.5.0, Ninja 1.13.2 | | Language | C++26, reflection `yes` | | Runtime | Wine 11.0 (`wine64`), no native Windows runner available | -| Modules | `Algorithms Async Binary Containers Core Data Discovery Fsm Functional Log LogState Math Memory Messaging Observability ObservabilityHooks Scheduler Service Testing TestingMock Text Time Unicode` | +| Modules | `Algorithms Async Binary Configuration Containers Core Crypto Data Discovery Fsm Functional Log LogState Math Memory Messaging Observability ObservabilityHooks Scheduler Service System Testing TestingMock Text Time Unicode` | | Observed | configure, compile, `cmake --install`, consume (`TargetProfile.exe` linked); `VoidTests.exe` under Wine: **1364 tests, 1360 passed, 4 skipped, 0 failed** | Notes from the runtime run: @@ -117,6 +117,12 @@ Notes from the runtime run: is Linux-only (`EpollBackend`); on Windows `Driver::create` returns `IoErrorCode::unsupported` unless the mock backend is selected. A Windows IO backend (IOCP) is a separate task. +- `Configuration`, `Crypto` and `System` are allowlisted and cross-compile; + `System` links `winmm` for the Win32 audio backend. `Archive` is **not** + allowlisted yet: its staging implementation (`StagedArchive.cpp`) is + POSIX-only (see Void/Library#65). +- Tests that only exercise POSIX APIs carry `// @requires-posix` and are + skipped on Windows; the POSIX process helper is not built there. - `Observability` links after replacing the namespace-scope `inline thread_local` hook stack with a function-local `thread_local` accessor (MinGW emitted duplicate TLS init functions). diff --git a/include/Void/System/Audio.hpp b/include/Void/System/Audio.hpp index a57bbef..80a7c47 100644 --- a/include/Void/System/Audio.hpp +++ b/include/Void/System/Audio.hpp @@ -19,8 +19,9 @@ #ifndef NOMINMAX #define NOMINMAX #endif -#include +// windows.h must precede mmsystem.h: the latter relies on its base types. #include +#include #endif namespace Void::System diff --git a/src/System/module.cmake b/src/System/module.cmake index d94dd64..b0f5692 100644 --- a/src/System/module.cmake +++ b/src/System/module.cmake @@ -1,6 +1,7 @@ void_add_module(System INTERNAL_DEPS Functional Time LogState EXTERNAL_DEPS Threads::Threads + DEPS_WIN32 winmm EXCLUDE_HEADERS Void/System/AsyncProcess.hpp Void/System/AsyncWatcher.hpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 09100c5..3c8deda 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -26,6 +26,17 @@ function(_void_test_requires_satisfied src_file active_modules active_headers ou return() endif() endif() + # Whole-file POSIX gate: files that only exercise POSIX APIs (openat, + # fork/wait, process groups, /proc, ...) cannot be compiled for Windows. + if(WIN32) + string(FIND "${_src_content}" "// @requires-posix" _needs_posix) + if(NOT _needs_posix EQUAL -1) + message(STATUS + "[VoidTests] Skipping ${src_file} (requires POSIX)") + set(${out_var} FALSE PARENT_SCOPE) + return() + endif() + endif() string(REGEX MATCHALL "#[ \t]*include[ \t]*[<\"](Void/[^/\">]+/[^>\"]+)[>\"]" _matches "${_src_content}") set(_ok TRUE) @@ -209,7 +220,9 @@ endif() # ── Test-support executables & libraries ────────────────────────────────────── # These are NOT test files; they are helper executables/libs referenced by tests. -if(TARGET VoidTests AND (TARGET Void::System OR TARGET Void::IPC)) +# The process helper is POSIX-only (poll.h, fork/wait); Windows tests that +# need it are guarded or not built. +if(TARGET VoidTests AND (TARGET Void::System OR TARGET Void::IPC) AND NOT WIN32) add_executable(VoidProcessHelper "${CMAKE_CURRENT_SOURCE_DIR}/helpers/ProcessHelper.cpp") set_target_properties(VoidProcessHelper PROPERTIES diff --git a/tests/standalone/Configuration/Argparse.cpp b/tests/standalone/Configuration/Argparse.cpp index ea2b277..da41122 100644 --- a/tests/standalone/Configuration/Argparse.cpp +++ b/tests/standalone/Configuration/Argparse.cpp @@ -2,12 +2,35 @@ #include #include +#include #include #include #include using namespace Void::Argparse; +namespace +{ +// setenv/unsetenv are POSIX-only; _putenv_s is the Windows equivalent. +void set_env(const char* name, const char* value) +{ +#ifdef _WIN32 + _putenv_s(name, value); +#else + ::setenv(name, value, 1); +#endif +} + +void unset_env(const char* name) +{ +#ifdef _WIN32 + _putenv_s(name, ""); +#else + ::unsetenv(name); +#endif +} +} // namespace + // Helper: convert vector of strings to argc/argv style struct Args { std::vector strs; @@ -203,7 +226,7 @@ Void::Testing::Test argparse_unknown_option_is_error() Void::Testing::Test argparse_help_color_default_and_toggle() { - ::unsetenv("NO_COLOR"); + unset_env("NO_COLOR"); bool v = false; Parser p{"tool"}; p.flag("--verbose", "-v", "verbose mode", v); @@ -219,9 +242,9 @@ Void::Testing::Test argparse_help_color_default_and_toggle() // NO_COLOR disables styling even when the parser allows it. p.color(true); - ::setenv("NO_COLOR", "1", 1); + set_env("NO_COLOR", "1"); Void::Testing::expect(p.help().find("\033[") == std::string::npos); - ::unsetenv("NO_COLOR"); + unset_env("NO_COLOR"); } Void::Testing::Test argparse_help_contains_names() @@ -401,13 +424,13 @@ Void::Testing::Test argparse_rich_features() std::string::npos); // Environment fallback. - ::setenv("TOOL_REQUIRED", "from-env", 1); + set_env("TOOL_REQUIRED", "from-env"); required_opt.reset(); auto from_env = parser.parse_detailed(1, missing_argv); Void::Testing::expect(from_env.ok()); Void::Testing::require(required_opt.has_value()); Void::Testing::expect_eq(*required_opt, std::string{"from-env"}); - ::unsetenv("TOOL_REQUIRED"); + unset_env("TOOL_REQUIRED"); // Conflicting options. const char* conflict_argv[] = {"tool", "--verbose", "--mode", "slow", diff --git a/tests/standalone/Configuration/Config.cpp b/tests/standalone/Configuration/Config.cpp index 2b315e5..a866425 100644 --- a/tests/standalone/Configuration/Config.cpp +++ b/tests/standalone/Configuration/Config.cpp @@ -8,35 +8,57 @@ #include #include +namespace +{ +// setenv/unsetenv are POSIX-only; _putenv_s is the Windows equivalent. +void set_env(const char* name, const char* value) +{ +#ifdef _WIN32 + _putenv_s(name, value); +#else + ::setenv(name, value, 1); +#endif +} + +void unset_env(const char* name) +{ +#ifdef _WIN32 + _putenv_s(name, ""); +#else + ::unsetenv(name); +#endif +} +} // namespace + Void::Testing::Test get_env_finds_set_variable() { - ::setenv("VOID_TEST_VAR_A", "hello", 1); + set_env("VOID_TEST_VAR_A", "hello"); auto r = Void::Configuration::get_env("VOID_TEST_VAR_A"); Void::Testing::expect(r.has_value()); Void::Testing::expect_eq(*r, std::string{"hello"}); - ::unsetenv("VOID_TEST_VAR_A"); + unset_env("VOID_TEST_VAR_A"); } Void::Testing::Test get_env_returns_error_for_missing() { - ::unsetenv("VOID_TEST_VAR_MISSING_XYZ"); + unset_env("VOID_TEST_VAR_MISSING_XYZ"); auto r = Void::Configuration::get_env("VOID_TEST_VAR_MISSING_XYZ"); Void::Testing::expect(!r.has_value()); } Void::Testing::Test get_env_or_returns_fallback_when_absent() { - ::unsetenv("VOID_TEST_VAR_MISSING_XYZ"); + unset_env("VOID_TEST_VAR_MISSING_XYZ"); auto val = Void::Configuration::get_env_or("VOID_TEST_VAR_MISSING_XYZ", "default"); Void::Testing::expect_eq(val, std::string{"default"}); } Void::Testing::Test get_env_or_returns_value_when_present() { - ::setenv("VOID_TEST_VAR_B", "world", 1); + set_env("VOID_TEST_VAR_B", "world"); auto val = Void::Configuration::get_env_or("VOID_TEST_VAR_B", "fallback"); Void::Testing::expect_eq(val, std::string{"world"}); - ::unsetenv("VOID_TEST_VAR_B"); + unset_env("VOID_TEST_VAR_B"); } Void::Testing::Test config_set_and_get() @@ -64,13 +86,13 @@ Void::Testing::Test config_get_or_returns_fallback() Void::Testing::Test config_from_env_reads_listed_keys() { - ::setenv("VOID_TEST_CFG_X", "42", 1); - ::unsetenv("VOID_TEST_CFG_Y"); + set_env("VOID_TEST_CFG_X", "42"); + unset_env("VOID_TEST_CFG_Y"); auto cfg = Void::Configuration::Config::from_env({"VOID_TEST_CFG_X", "VOID_TEST_CFG_Y"}); Void::Testing::expect_eq(cfg.size(), std::size_t{1}); Void::Testing::expect_eq(std::string{cfg.get_or("VOID_TEST_CFG_X")}, std::string{"42"}); - ::unsetenv("VOID_TEST_CFG_X"); + unset_env("VOID_TEST_CFG_X"); } Void::Testing::Test config_from_file_parses_key_value() diff --git a/tests/standalone/Configuration/Sources.cpp b/tests/standalone/Configuration/Sources.cpp index 85f06d0..6c483b0 100644 --- a/tests/standalone/Configuration/Sources.cpp +++ b/tests/standalone/Configuration/Sources.cpp @@ -7,13 +7,35 @@ using Void::Configuration::Config; +namespace +{ +// setenv/unsetenv are POSIX-only; _putenv_s is the Windows equivalent. +void set_env(const char* name, const char* value) +{ +#ifdef _WIN32 + _putenv_s(name, value); +#else + ::setenv(name, value, 1); +#endif +} + +void unset_env(const char* name) +{ +#ifdef _WIN32 + _putenv_s(name, ""); +#else + ::unsetenv(name); +#endif +} +} // namespace + // ── from_env_prefix ─────────────────────────────────────────────────────────── Void::Testing::Test env_prefix_strips_and_normalizes() { - ::setenv("VOIDTEST_LOG__LEVEL", "debug", 1); - ::setenv("VOIDTEST_PORT", "9000", 1); - ::setenv("UNRELATED_KEY", "x", 1); + set_env("VOIDTEST_LOG__LEVEL", "debug"); + set_env("VOIDTEST_PORT", "9000"); + set_env("UNRELATED_KEY", "x"); const auto cfg = Config::from_env_prefix("VOIDTEST_"); Void::Testing::expect(cfg.get_or("log.level") == @@ -22,9 +44,9 @@ Void::Testing::Test env_prefix_strips_and_normalizes() "9000"); Void::Testing::expect(!cfg.contains("unrelated_key")); - ::unsetenv("VOIDTEST_LOG__LEVEL"); - ::unsetenv("VOIDTEST_PORT"); - ::unsetenv("UNRELATED_KEY"); + unset_env("VOIDTEST_LOG__LEVEL"); + unset_env("VOIDTEST_PORT"); + unset_env("UNRELATED_KEY"); } // ── from_ini_text ───────────────────────────────────────────────────────────── diff --git a/tests/standalone/Log/ConsoleLogger.cpp b/tests/standalone/Log/ConsoleLogger.cpp index d999f26..13ca93a 100644 --- a/tests/standalone/Log/ConsoleLogger.cpp +++ b/tests/standalone/Log/ConsoleLogger.cpp @@ -4,9 +4,32 @@ #include #include +#include #include #include +namespace +{ +// setenv/unsetenv are POSIX-only; _putenv_s is the Windows equivalent. +void set_env(const char* name, const char* value) +{ +#ifdef _WIN32 + _putenv_s(name, value); +#else + ::setenv(name, value, 1); +#endif +} + +void unset_env(const char* name) +{ +#ifdef _WIN32 + _putenv_s(name, ""); +#else + ::unsetenv(name); +#endif +} +} // namespace + class ConsoleLoggerTests : public Void::Testing::Fixture { public: @@ -26,14 +49,14 @@ class ConsoleLoggerTests : public Void::Testing::Fixture Void::Testing::Test colors_by_default_with_no_color_opt_out() { - ::unsetenv("NO_COLOR"); + unset_env("NO_COLOR"); { std::ostringstream out; Void::Logging::ConsoleLogger log{out, Void::Logging::Mode::Immediate}; log.error("colored"); Void::Testing::expect(out.str().find("\x1b[") != std::string::npos); } - ::setenv("NO_COLOR", "1", 1); + set_env("NO_COLOR", "1"); { std::ostringstream out; Void::Logging::ConsoleLogger log{out, Void::Logging::Mode::Immediate}; @@ -41,7 +64,7 @@ class ConsoleLoggerTests : public Void::Testing::Fixture Void::Testing::expect(out.str().find("\x1b[") == std::string::npos); Void::Testing::expect(out.str().find("plain") != std::string::npos); } - ::unsetenv("NO_COLOR"); + unset_env("NO_COLOR"); } Void::Testing::Test level_filtering() diff --git a/tests/standalone/System/BinarySession.cpp b/tests/standalone/System/BinarySession.cpp index f8e4e16..ebd1510 100644 --- a/tests/standalone/System/BinarySession.cpp +++ b/tests/standalone/System/BinarySession.cpp @@ -1,3 +1,5 @@ +// @requires-posix: binary sessions are driven through the POSIX process +// helper and descriptor/process-group APIs. #include #include #include diff --git a/tests/standalone/System/Path.cpp b/tests/standalone/System/Path.cpp index 5383e9a..12a62b1 100644 --- a/tests/standalone/System/Path.cpp +++ b/tests/standalone/System/Path.cpp @@ -108,6 +108,9 @@ Void::Testing::Test remove_path_handles_missing_and_recursive() Void::Testing::Test filesystem_file_lock_symlink_swap_reflink_and_timestamps() { +#ifdef _WIN32 + Void::Testing::skip("POSIX-only filesystem semantics"); +#else Void::FileSystem::TempDir tmp{"void_fs_vl010_"}; // 1. RAII advisory FileLock (shared & exclusive, blocking & try_lock) @@ -220,6 +223,7 @@ Void::Testing::Test filesystem_file_lock_symlink_swap_reflink_and_timestamps() Void::Testing::expect_eq(static_cast(st_link.st_mtim.tv_sec), kLinkMtime); } +#endif } namespace @@ -455,11 +459,13 @@ Void::Testing::Test read_file_bounded_handles_empty_binary_and_limits() std::string::npos); } -#ifndef _WIN32 // A stream that keeps producing data after open must be cut off by the // per-chunk check even though it has no initial size to validate. Void::Testing::Test read_file_bounded_rejects_growth_past_limit() { +#ifdef _WIN32 + Void::Testing::skip("POSIX fifo semantics"); +#else ScopedTestDir dir{"bounded_growth"}; const auto fifo = dir.path / "stream"; Void::Testing::require(::mkfifo(fifo.c_str(), 0600) == 0); @@ -488,5 +494,5 @@ Void::Testing::Test read_file_bounded_rejects_growth_past_limit() Void::Testing::require(!result.has_value()); Void::Testing::expect(result.error().message().find("limit") != std::string::npos); -} #endif +} diff --git a/tests/standalone/System/Process.cpp b/tests/standalone/System/Process.cpp index 78b970f..e115953 100644 --- a/tests/standalone/System/Process.cpp +++ b/tests/standalone/System/Process.cpp @@ -27,32 +27,47 @@ Void::Testing::Test shell_captures_stderr_separately() 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); @@ -60,14 +75,21 @@ Void::Testing::Test run_direct_stdout_and_stderr_independent() 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() @@ -83,6 +105,7 @@ Void::Testing::Test run_stdout_and_stderr_independent() 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()); @@ -90,4 +113,7 @@ Void::Testing::Test run_large_output_is_captured_fully() // "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 } diff --git a/tests/standalone/System/ProcessStream.cpp b/tests/standalone/System/ProcessStream.cpp index acf7b30..9a0ad1c 100644 --- a/tests/standalone/System/ProcessStream.cpp +++ b/tests/standalone/System/ProcessStream.cpp @@ -1,3 +1,4 @@ +// @requires-posix: streaming tests drive the POSIX process helper. #include #include #include diff --git a/tests/standalone/System/SystemHardening.cpp b/tests/standalone/System/SystemHardening.cpp index 4608459..21021f9 100644 --- a/tests/standalone/System/SystemHardening.cpp +++ b/tests/standalone/System/SystemHardening.cpp @@ -1,3 +1,4 @@ +// @requires-posix: process groups, descriptors and /proc are POSIX-only. #include #include #include diff --git a/tests/standalone/Testing/Corpus.cpp b/tests/standalone/Testing/Corpus.cpp index 623cef3..f7ab9ac 100644 --- a/tests/standalone/Testing/Corpus.cpp +++ b/tests/standalone/Testing/Corpus.cpp @@ -7,7 +7,20 @@ #include #include #include +#ifdef _WIN32 +#include +#else #include +#endif + +namespace +{ +#ifdef _WIN32 + [[nodiscard]] int current_pid() noexcept { return ::_getpid(); } +#else + [[nodiscard]] int current_pid() noexcept { return ::getpid(); } +#endif +} // namespace namespace { @@ -15,7 +28,7 @@ namespace { const auto directory = std::filesystem::temp_directory_path() / - ("void-corpus-" + std::to_string(::getpid())); + ("void-corpus-" + std::to_string(current_pid())); std::filesystem::remove_all(directory); std::filesystem::create_directories(directory); return directory;