Files
ww/lib/log/funcs_test.ww
Hojun-Cho 53919b3404 lib: split log tests into funcs+global per ref/hare/log
Pure move: log_test.ww dissolves along its banner seams into
funcs_test.ww (the six logger-arg rows — lprintlnbasic/single/empty,
lprintflnbasic/indexed/mods — plus the fatal-family subprocess TODO;
ref/hare/log/funcs.ha owns lprintln/lprintfln and the fatal/lfatal
forms) and global_test.ww (defaultwiredtoglobal, setloggerswap,
printflnglobal; ref/hare/log/global.ha owns default/global/setlogger).
Moved blocks are byte-identical; the 9 banner lines are deleted.
Imports minimized per file (log + memio; the stale fmt/io imports
drop).

Helper inventory: streq spans both halves (all six funcs rows;
setloggerswap + printflnglobal on the global side), so it is
duplicated under per-file names per the sanctioned strconv
streq/fstreq precedent — fstreq in funcs_test.ww (decl + 6 call
sites), gstreq in global_test.ww (decl + 6 call sites); bodies
byte-identical apart from the name. Line-multiset diff old-vs-concat
(heads/banners excluded, names normalized): the only residue is the
9-line streq helper counted twice.

Order-safety, proven on the composed run: dir-mode executes
declaration order per file, files byte-lexicographic (funcs_test <
global_test < silent_test). Observed order: lprintlnbasic,
lprintlnsingle, lprintlnempty, lprintflnbasic, lprintflnindexed,
lprintflnmods, defaultwiredtoglobal, setloggerswap, printflnglobal,
silentwritesnothing, silentignoresprintfln — defaultwiredtoglobal
still precedes every log.setlogger caller (setloggerswap and
printflnglobal, both later in its own file; funcs and silent rows
never call setlogger).

Consumers: Makefile LIBRARY_TESTS replaces the log_test.ww entry with
the two new entries in place; test/byteid/libbyteid_test.ww roster row
becomes two fx rows, NENTEXPECT 59->60.

Validation: standalone ww test lib/log/funcs_test.ww (6 passed) and
lib/log/global_test.ww (3 passed); dir mode ww test lib/log (11
passed, no duplicate symbols); byteid compile-only build exit 0, 60
roster appends == NENTEXPECT.
2026-08-08 18:09:19 +09:00

105 lines
2.4 KiB
Plaintext

// funcstest — exercises the logger-arg print family (lprintln /
// lprintfln) per ref/hare/log/funcs.ha ownership. Each scenario
// constructs a stdlogger over a memio.stream and asserts the bytes
// the logger produced. No row here touches log.setlogger, so these
// rows are order-independent of the global-wiring rows in
// global_test.ww.
package log_test;
import log;
import memio;
fn fstreq(a: str, b: str) bool = {
if (a.len != b.len) { return false; };
let i: i32 = 0;
for (i < a.len) {
if (a[i] != b[i]) { return false; };
i += 1;
};
return true;
};
@test fn lprintlnbasic() void = {
let buf: [32]u8;
let mem = memio.fixed(buf[0:32]);
let s = &mem.vt;
let sl = log.new(s);
log.lprintln(&sl.logger, "hello", 42i64);
assert(!(!fstreq(memio.string(&mem), "hello 42\n")));
};
@test fn lprintlnsingle() void = {
let buf: [16]u8;
let mem = memio.fixed(buf[0:16]);
let s = &mem.vt;
let sl = log.new(s);
log.lprintln(&sl.logger, "only");
assert(!(!fstreq(memio.string(&mem), "only\n")));
};
@test fn lprintlnempty() void = {
let buf: [4]u8;
let mem = memio.fixed(buf[0:4]);
let s = &mem.vt;
let sl = log.new(s);
log.lprintln(&sl.logger);
assert(!(!fstreq(memio.string(&mem), "\n")));
};
@test fn lprintflnbasic() void = {
let buf: [32]u8;
let mem = memio.fixed(buf[0:32]);
let s = &mem.vt;
let sl = log.new(s);
log.lprintfln(&sl.logger, "x={} y={}", 42i64, "hi");
assert(!(!fstreq(memio.string(&mem), "x=42 y=hi\n")));
};
// The fmt parser proper is covered in fmttest; this pins that log's
// variadic forwarding propagates argv order so indexed placeholders
// resolve correctly.
@test fn lprintflnindexed() void = {
let buf: [16]u8;
let mem = memio.fixed(buf[0:16]);
let s = &mem.vt;
let sl = log.new(s);
log.lprintfln(&sl.logger, "{1} {0}", "a", "b");
assert(!(!fstreq(memio.string(&mem), "b a\n")));
};
// Pins that mod-bearing placeholders flow through log's forwarding
// intact (parser proper covered in fmttest).
@test fn lprintflnmods() void = {
let buf: [16]u8;
let mem = memio.fixed(buf[0:16]);
let s = &mem.vt;
let sl = log.new(s);
log.lprintfln(&sl.logger, "{:5}", 42i64);
assert(!(!fstreq(memio.string(&mem), " 42\n")));
};
// TODO subprocess: log.fatal / log.lfatal / log.fatalf / log.lfatalf
// exit(255). Verifying them needs a fork+wait fixture so the parent
// can assert WEXITSTATUS == 255 without the test process itself
// terminating. lib/os doesn't ship process spawning yet; revisit
// when that lands.