lib/io tests: hand-main plumbing -> assert (@test conversion B5)
This commit is contained in:
@@ -11,11 +11,6 @@ package errors_test;
|
||||
import errors;
|
||||
import os;
|
||||
|
||||
// signalled — bumped by main before each test so a failing exit code
|
||||
// pinpoints the offending case.
|
||||
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; };
|
||||
let i: i32 = 0;
|
||||
@@ -85,7 +80,7 @@ fn errtag(e: errors.error) int = {
|
||||
// regardless — it is how errno is actually used (cf
|
||||
// lib/io/stream.ww:53, and Hare's errors/rt.ha callers).
|
||||
let er: errors.error = errors.errno(ins[i]);
|
||||
if (errtag(er) != exp[i]) { fail(); };
|
||||
assert(!(errtag(er) != exp[i]));
|
||||
i += 1;
|
||||
};
|
||||
};
|
||||
@@ -94,25 +89,25 @@ fn errtag(e: errors.error) int = {
|
||||
@test fn opaquetail() void = {
|
||||
// EIO (5) is outside the mapped set, so it wraps opaque_.
|
||||
let e: errors.error = errors.errno(5);
|
||||
if (errtag(e) != 99) { fail(); };
|
||||
assert(!(errtag(e) != 99));
|
||||
match (e) {
|
||||
case let o: errors.opaque_ =>
|
||||
if (!streq((*o.strerror)(&o.data), "Unknown error")) { fail(); };
|
||||
assert(!(!streq((*o.strerror)(&o.data), "Unknown error")));
|
||||
case =>
|
||||
fail();
|
||||
abort();
|
||||
};
|
||||
};
|
||||
|
||||
// ---- os.strerror mapped path --------------------------------------
|
||||
@test fn strerrortext() void = {
|
||||
if (!streq(os.strerror(os.ENOENT), "No such file or directory")) { fail(); };
|
||||
if (!streq(os.strerror(os.EINVAL), "Invalid argument")) { fail(); };
|
||||
if (!streq(os.strerror(5), "Unknown error")) { fail(); };
|
||||
assert(!(!streq(os.strerror(os.ENOENT), "No such file or directory")));
|
||||
assert(!(!streq(os.strerror(os.EINVAL), "Invalid argument")));
|
||||
assert(!(!streq(os.strerror(5), "Unknown error")));
|
||||
};
|
||||
|
||||
export fn main() i32 = {
|
||||
signalled = 1; mapping();
|
||||
signalled = 2; opaquetail();
|
||||
signalled = 3; strerrortext();
|
||||
mapping();
|
||||
opaquetail();
|
||||
strerrortext();
|
||||
return 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user