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:
@@ -26,21 +26,18 @@
|
||||
// asserts immediately. Don't call two dirs.* fns and compare across
|
||||
// — the second clobbers the first's view.
|
||||
//
|
||||
// `signalled` global bumps before each test so a failing exit code
|
||||
// pinpoints the offending row (WEXITSTATUS = signalled + 10). Same
|
||||
// shape as temptest / shlextest / fnmatchtest / ostest.
|
||||
// A failing row aborts via the assert/abort builtin (task #5 @test
|
||||
// conversion).
|
||||
//
|
||||
// Don't `use io;` here — lib/os and lib/io collide on read/write/
|
||||
// close (task #17). We need only os.getenv + os.exit.
|
||||
// close (task #17). We need only os.getenv.
|
||||
|
||||
package dirs_test;
|
||||
|
||||
import dirs;
|
||||
import os;
|
||||
|
||||
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; };
|
||||
@@ -87,7 +84,7 @@ fn gettmpdir() str = {
|
||||
match (os.getenv("WW_TEST_TMPDIR")) {
|
||||
case let s: str => return s;
|
||||
case void => {
|
||||
fail();
|
||||
abort();
|
||||
let empty: str;
|
||||
return empty;
|
||||
};
|
||||
@@ -100,7 +97,7 @@ fn gettmpdir() str = {
|
||||
let tmpl = gettmpdir();
|
||||
let exp = expected(tmpl, "cfg", "myapp");
|
||||
let got = dirs.config("myapp");
|
||||
if (!streq(got, exp)) { fail(); };
|
||||
assert(!(!streq(got, exp)));
|
||||
};
|
||||
|
||||
// ---- 2: XDG_CACHE_HOME="relative/path" → fallback to $HOME/.cache --
|
||||
@@ -112,7 +109,7 @@ fn gettmpdir() str = {
|
||||
let tmpl = gettmpdir();
|
||||
let exp = expected(tmpl, ".cache", "myapp");
|
||||
let got = dirs.cache("myapp");
|
||||
if (!streq(got, exp)) { fail(); };
|
||||
assert(!(!streq(got, exp)));
|
||||
};
|
||||
|
||||
// ---- 3: XDG_DATA_HOME unset → fallback to $HOME/.local/share -------
|
||||
@@ -121,7 +118,7 @@ fn gettmpdir() str = {
|
||||
let tmpl = gettmpdir();
|
||||
let exp = expected(tmpl, ".local/share", "myapp");
|
||||
let got = dirs.data("myapp");
|
||||
if (!streq(got, exp)) { fail(); };
|
||||
assert(!(!streq(got, exp)));
|
||||
};
|
||||
|
||||
// ---- 4: XDG_STATE_HOME unset → fallback to $HOME/.local/state ------
|
||||
@@ -130,13 +127,13 @@ fn gettmpdir() str = {
|
||||
let tmpl = gettmpdir();
|
||||
let exp = expected(tmpl, ".local/state", "myapp");
|
||||
let got = dirs.state("myapp");
|
||||
if (!streq(got, exp)) { fail(); };
|
||||
assert(!(!streq(got, exp)));
|
||||
};
|
||||
|
||||
export fn main() i32 = {
|
||||
signalled = 1; test_config_xdg_set();
|
||||
signalled = 2; test_cache_xdg_relative_fallback();
|
||||
signalled = 3; test_data_unset_fallback();
|
||||
signalled = 4; test_state_unset_fallback();
|
||||
test_config_xdg_set();
|
||||
test_cache_xdg_relative_fallback();
|
||||
test_data_unset_fallback();
|
||||
test_state_unset_fallback();
|
||||
return 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user