Skip to content

Commit d35fdc6

Browse files
mcpplibs os 0.1.0; member tests/examples/os (#572)
Co-authored-by: speak-agent <248744407+speak-agent@users.noreply.github.com>
1 parent 4a8c86f commit d35fdc6

4 files changed

Lines changed: 105 additions & 0 deletions

File tree

‎mcpp.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ members = [
225225
"tests/examples/openkal-musl",
226226
"tests/examples/compiler-rt-builtins",
227227
"tests/examples/openkal-tools",
228+
"tests/examples/os",
228229
]
229230

230231
# ── The index redirect, hoisted to the workspace root ───────────────────

‎pkgs/o/os.lua‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
-- os --- mcpplibs.os, a C++ operating-system library over openkal.
2+
--
3+
-- Processes, files, the environment, terminals, conventional directories and
4+
-- local IPC, composed from openkal's atoms, with compile-time platform
5+
-- constants for a program built for a system and `host()' answered at load for
6+
-- one built as an ok image (`<arch>-openkal').
7+
--
8+
-- No `deps'. The package names openkal and, for the system it is built for,
9+
-- that system's implementation in its own manifest; a program that builds ok
10+
-- images names the C library and the C++ run-time inside them itself.
11+
package = {
12+
spec = "1",
13+
namespace = "mcpplibs",
14+
name = "os",
15+
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",
16+
licenses = {"Apache-2.0"},
17+
repo = "https://github.com/mcpplibs/os",
18+
type = "package",
19+
20+
xpm = {
21+
linux = {
22+
["0.1.0"] = {
23+
url = {
24+
GLOBAL = "https://github.com/mcpplibs/os/archive/refs/tags/0.1.0.tar.gz",
25+
CN = "https://gitcode.com/mcpp-res/os/releases/download/0.1.0/os-0.1.0.tar.gz",
26+
},
27+
sha256 = "f7e4117612d721da2ae311cb36afab42625391208e4b0f8e8491534a00b6ab18",
28+
},
29+
},
30+
macosx = {
31+
["0.1.0"] = {
32+
url = {
33+
GLOBAL = "https://github.com/mcpplibs/os/archive/refs/tags/0.1.0.tar.gz",
34+
CN = "https://gitcode.com/mcpp-res/os/releases/download/0.1.0/os-0.1.0.tar.gz",
35+
},
36+
sha256 = "f7e4117612d721da2ae311cb36afab42625391208e4b0f8e8491534a00b6ab18",
37+
},
38+
},
39+
windows = {
40+
["0.1.0"] = {
41+
url = {
42+
GLOBAL = "https://github.com/mcpplibs/os/archive/refs/tags/0.1.0.tar.gz",
43+
CN = "https://gitcode.com/mcpp-res/os/releases/download/0.1.0/os-0.1.0.tar.gz",
44+
},
45+
sha256 = "f7e4117612d721da2ae311cb36afab42625391208e4b0f8e8491534a00b6ab18",
46+
},
47+
},
48+
},
49+
50+
mcpp = "*/mcpp.toml",
51+
}

‎tests/examples/os/mcpp.toml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# mcpplibs.os test project: the library over this system's openkal
2+
# implementation, on every runner --- a program started and read, a file
3+
# published, a list of directories split, and the platform the build is for.
4+
[package]
5+
name = "os-tests"
6+
version = "0.1.0"
7+
8+
[dependencies.mcpplibs]
9+
os = "0.1.0"
10+
11+
[indices]
12+
mcpplibs = { path = "../../.." }

‎tests/examples/os/tests/os.cpp‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// mcpplibs.os on this runner: the platform, a published file, a list of directories, and a
2+
// program started and read (this test, started again).
3+
import std;
4+
import mcpplibs.os;
5+
6+
namespace os = mcpplibs::os;
7+
8+
int main(int argc, char** argv) {
9+
if (argc > 1 && std::string_view(argv[1]) == "--echo") {
10+
(void)os::stdio::write_output("echoed");
11+
return 0;
12+
}
13+
int failures = 0;
14+
auto check = [&](bool ok, std::string_view what) { if (!ok) { ++failures; std::println(std::cerr, "FAIL: {}", what); } };
15+
16+
check(os::host() == os::PLATFORM, "built for a system, the host is that system");
17+
const auto dir = os::dirs::temp() / std::format("os-tests-{}", os::process::self()->id);
18+
std::filesystem::create_directories(dir);
19+
const auto file = dir / "published.txt";
20+
check(os::fs::publish(file, "first").has_value(), "a free name is published");
21+
check(!os::fs::publish(file, "second").has_value(), "a published name is not replaced");
22+
check(os::fs::read(file).value_or("") == "first", "and keeps what was published first");
23+
24+
const char sep = os::conventions().path_list_separator;
25+
const auto parts = os::env::split_list(std::string("a") + sep + sep + "b");
26+
check(parts.size() == 2, "a list of directories splits at the host's separator");
27+
28+
const auto again = os::env::self_command();
29+
if (!again.empty()) {
30+
os::process::spawn_options o;
31+
o.program = again.front();
32+
o.args.assign(again.begin() + 1, again.end());
33+
o.args.push_back("--echo");
34+
auto r = os::process::run(o);
35+
check(r && r->status.success() && r->out == "echoed", "a started program's output is read");
36+
}
37+
std::error_code ec;
38+
std::filesystem::remove_all(dir, ec);
39+
if (failures == 0) std::println("os-tests: held");
40+
return failures;
41+
}

0 commit comments

Comments
 (0)