From 89aec47f10696f2ea49035693fc2289726b5919e Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Tue, 27 Oct 2026 04:34:46 +0900 Subject: [PATCH] mcpplibs os 0.1.0; member tests/examples/os Co-authored-by: speak-agent <248744407+speak-agent@users.noreply.github.com> --- mcpp.toml | 1 + pkgs/o/os.lua | 51 ++++++++++++++++++++++++++++++++++ tests/examples/os/mcpp.toml | 12 ++++++++ tests/examples/os/tests/os.cpp | 41 +++++++++++++++++++++++++++ 4 files changed, 105 insertions(+) create mode 100644 pkgs/o/os.lua create mode 100644 tests/examples/os/mcpp.toml create mode 100644 tests/examples/os/tests/os.cpp diff --git a/mcpp.toml b/mcpp.toml index 9a510bcb..5580ff63 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -225,6 +225,7 @@ members = [ "tests/examples/openkal-musl", "tests/examples/compiler-rt-builtins", "tests/examples/openkal-tools", + "tests/examples/os", ] # ── The index redirect, hoisted to the workspace root ─────────────────── diff --git a/pkgs/o/os.lua b/pkgs/o/os.lua new file mode 100644 index 00000000..6bb851a5 --- /dev/null +++ b/pkgs/o/os.lua @@ -0,0 +1,51 @@ +-- os --- mcpplibs.os, a C++ operating-system library over openkal. +-- +-- Processes, files, the environment, terminals, conventional directories and +-- local IPC, composed from openkal's atoms, with compile-time platform +-- constants for a program built for a system and `host()' answered at load for +-- one built as an ok image (`-openkal'). +-- +-- No `deps'. The package names openkal and, for the system it is built for, +-- that system's implementation in its own manifest; a program that builds ok +-- images names the C library and the C++ run-time inside them itself. +package = { + spec = "1", + namespace = "mcpplibs", + name = "os", + description = "mcpplibs.os: a C++ operating-system library over openkal --- processes, files, environment, terminals, directories and local IPC, with compile-time platform constants and a few platform modules", + licenses = {"Apache-2.0"}, + repo = "https://github.com/mcpplibs/os", + type = "package", + + xpm = { + linux = { + ["0.1.0"] = { + url = { + GLOBAL = "https://github.com/mcpplibs/os/archive/refs/tags/0.1.0.tar.gz", + CN = "https://gitcode.com/mcpp-res/os/releases/download/0.1.0/os-0.1.0.tar.gz", + }, + sha256 = "f7e4117612d721da2ae311cb36afab42625391208e4b0f8e8491534a00b6ab18", + }, + }, + macosx = { + ["0.1.0"] = { + url = { + GLOBAL = "https://github.com/mcpplibs/os/archive/refs/tags/0.1.0.tar.gz", + CN = "https://gitcode.com/mcpp-res/os/releases/download/0.1.0/os-0.1.0.tar.gz", + }, + sha256 = "f7e4117612d721da2ae311cb36afab42625391208e4b0f8e8491534a00b6ab18", + }, + }, + windows = { + ["0.1.0"] = { + url = { + GLOBAL = "https://github.com/mcpplibs/os/archive/refs/tags/0.1.0.tar.gz", + CN = "https://gitcode.com/mcpp-res/os/releases/download/0.1.0/os-0.1.0.tar.gz", + }, + sha256 = "f7e4117612d721da2ae311cb36afab42625391208e4b0f8e8491534a00b6ab18", + }, + }, + }, + + mcpp = "*/mcpp.toml", +} diff --git a/tests/examples/os/mcpp.toml b/tests/examples/os/mcpp.toml new file mode 100644 index 00000000..90a02f63 --- /dev/null +++ b/tests/examples/os/mcpp.toml @@ -0,0 +1,12 @@ +# mcpplibs.os test project: the library over this system's openkal +# implementation, on every runner --- a program started and read, a file +# published, a list of directories split, and the platform the build is for. +[package] +name = "os-tests" +version = "0.1.0" + +[dependencies.mcpplibs] +os = "0.1.0" + +[indices] +mcpplibs = { path = "../../.." } diff --git a/tests/examples/os/tests/os.cpp b/tests/examples/os/tests/os.cpp new file mode 100644 index 00000000..978a1610 --- /dev/null +++ b/tests/examples/os/tests/os.cpp @@ -0,0 +1,41 @@ +// mcpplibs.os on this runner: the platform, a published file, a list of directories, and a +// program started and read (this test, started again). +import std; +import mcpplibs.os; + +namespace os = mcpplibs::os; + +int main(int argc, char** argv) { + if (argc > 1 && std::string_view(argv[1]) == "--echo") { + (void)os::stdio::write_output("echoed"); + return 0; + } + int failures = 0; + auto check = [&](bool ok, std::string_view what) { if (!ok) { ++failures; std::println(std::cerr, "FAIL: {}", what); } }; + + check(os::host() == os::PLATFORM, "built for a system, the host is that system"); + const auto dir = os::dirs::temp() / std::format("os-tests-{}", os::process::self()->id); + std::filesystem::create_directories(dir); + const auto file = dir / "published.txt"; + check(os::fs::publish(file, "first").has_value(), "a free name is published"); + check(!os::fs::publish(file, "second").has_value(), "a published name is not replaced"); + check(os::fs::read(file).value_or("") == "first", "and keeps what was published first"); + + const char sep = os::conventions().path_list_separator; + const auto parts = os::env::split_list(std::string("a") + sep + sep + "b"); + check(parts.size() == 2, "a list of directories splits at the host's separator"); + + const auto again = os::env::self_command(); + if (!again.empty()) { + os::process::spawn_options o; + o.program = again.front(); + o.args.assign(again.begin() + 1, again.end()); + o.args.push_back("--echo"); + auto r = os::process::run(o); + check(r && r->status.success() && r->out == "echoed", "a started program's output is read"); + } + std::error_code ec; + std::filesystem::remove_all(dir, ec); + if (failures == 0) std::println("os-tests: held"); + return failures; +}