Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mcpp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ───────────────────
Expand Down
51 changes: 51 additions & 0 deletions pkgs/o/os.lua
Original file line number Diff line number Diff line change
@@ -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 (`<arch>-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",
}
12 changes: 12 additions & 0 deletions tests/examples/os/mcpp.toml
Original file line number Diff line number Diff line change
@@ -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 = "../../.." }
41 changes: 41 additions & 0 deletions tests/examples/os/tests/os.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
Loading