lib/os+dirs tests: hand-main plumbing -> assert (@test conversion B6)
WW_TEST_* env arrangement logic untouched; only the fail/exit plumbing converts.
This commit is contained in:
@@ -5,11 +5,9 @@
|
||||
// cover alloc/free; the direct row here pins the FFI shape under
|
||||
// lib/os itself so future bindings refactors can't quietly drift.
|
||||
//
|
||||
// Convention follows the stdlib `_run` test fixtures: hand-rolled
|
||||
// @test fns dispatched from `main()` in numeric order, with a
|
||||
// `signalled` global the main fn bumps so a failing case exits with
|
||||
// `WEXITSTATUS = signalled + 10` — the harness then knows which
|
||||
// scenario tripped. Same shape as temptest / shlextest / fnmatchtest.
|
||||
// Hand-rolled @test fns dispatched from `main()` in source order; a
|
||||
// failing case aborts via the assert/abort builtin (task #5 @test
|
||||
// conversion).
|
||||
//
|
||||
// Pre-arranged env state (set by 974_getenv_run.c via setenv/unsetenv
|
||||
// before exec'ing `ww run lib/os/ostest.ww`):
|
||||
@@ -20,17 +18,15 @@
|
||||
//
|
||||
// Don't `use io;` here — lib/os and lib/io both export read/write/
|
||||
// close as C symbols that collide under the driver's flat-scope
|
||||
// concat (task #17). os alone is sufficient: getenv + exit are the
|
||||
// only primitives needed.
|
||||
// concat (task #17). os alone is sufficient: getenv + alloc/free are
|
||||
// the only primitives needed.
|
||||
|
||||
package os_test;
|
||||
|
||||
import os;
|
||||
import rt;
|
||||
|
||||
let signalled: i32 = 0;
|
||||
|
||||
fn fail() void = { os.exit(signalled + 10); };
|
||||
|
||||
fn streq(a: str, b: str) bool = {
|
||||
if (a.len != b.len) { return false; };
|
||||
@@ -47,9 +43,9 @@ fn streq(a: str, b: str) bool = {
|
||||
@test fn test_getenv_set() void = {
|
||||
let r = os.getenv("WW_TEST_GETENV");
|
||||
match (r) {
|
||||
case void => fail();
|
||||
case void => abort();
|
||||
case let s: str => {
|
||||
if (!streq(s, "hello-world")) { fail(); };
|
||||
assert(!(!streq(s, "hello-world")));
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -63,9 +59,9 @@ fn streq(a: str, b: str) bool = {
|
||||
@test fn test_getenv_empty() void = {
|
||||
let r = os.getenv("WW_TEST_EMPTY");
|
||||
match (r) {
|
||||
case void => fail();
|
||||
case void => abort();
|
||||
case let s: str => {
|
||||
if (s.len != 0) { fail(); };
|
||||
assert(!(s.len != 0));
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -76,7 +72,7 @@ fn streq(a: str, b: str) bool = {
|
||||
let r = os.getenv("WW_TEST_NOT_SET");
|
||||
match (r) {
|
||||
case void => {};
|
||||
case let s: str => fail();
|
||||
case let s: str => abort();
|
||||
};
|
||||
};
|
||||
|
||||
@@ -91,7 +87,7 @@ fn streq(a: str, b: str) bool = {
|
||||
let r = os.getenv("WW_TEST_GETEN");
|
||||
match (r) {
|
||||
case void => {};
|
||||
case let s: str => fail();
|
||||
case let s: str => abort();
|
||||
};
|
||||
};
|
||||
|
||||
@@ -106,16 +102,16 @@ fn streq(a: str, b: str) bool = {
|
||||
p.len = 4096;
|
||||
p[0] = 90u8; // 0x5a
|
||||
p[4095] = 165u8; // 0xa5
|
||||
if (p[0] != 90u8) { fail(); };
|
||||
if (p[4095] != 165u8) { fail(); };
|
||||
assert(!(p[0] != 90u8));
|
||||
assert(!(p[4095] != 165u8));
|
||||
os.free(p.ptr: *void, 4096u64);
|
||||
};
|
||||
|
||||
export fn main() i32 = {
|
||||
signalled = 1; test_getenv_set();
|
||||
signalled = 2; test_getenv_empty();
|
||||
signalled = 3; test_getenv_unset();
|
||||
signalled = 4; test_getenv_prefix_no_match();
|
||||
signalled = 5; test_alloc_free_roundtrip();
|
||||
test_getenv_set();
|
||||
test_getenv_empty();
|
||||
test_getenv_unset();
|
||||
test_getenv_prefix_no_match();
|
||||
test_alloc_free_roundtrip();
|
||||
return 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user