From c3b81eb79365177758fe3c1dcec86ca9e965fef3 Mon Sep 17 00:00:00 2001 From: Hojun-Cho Date: Sat, 8 Aug 2026 16:48:38 +0900 Subject: [PATCH] test: split log silent rows into silent_test.ww per ref/hare/log/silent.ha Pure file-boundary move: the two silent-logger rows (silentwritesnothing, silentignoresprintfln) leave lib/log/log_test.ww for lib/log/silent_test.ww, mirroring ref/hare/log/silent.ha's ownership (ref/hare/log has no test files of its own; the file name follows the impl layout as directed). Only the two banner lines are deleted; both moved blocks are byte-identical. silent_test.ww imports log + memio only (neither row uses streq/fmt/io). The specced funcs_test/global_test halves stay merged in log_test.ww: the streq helper is consumed by six lprint* rows AND the setloggerswap/printflnglobal global rows, and same-package test files compile as one unit in dir mode (duplicate fn rejected), so that boundary cannot be a pure move; reported upstream rather than relocating the majority of rows. Ordering: defaultwiredtoglobal must precede any log.setlogger caller. All setlogger callers (setloggerswap, printflnglobal) remain after it in log_test.ww; the silent rows never touch setlogger, and dir-mode concat order (pkgsort: log_test.ww < silent_test.ww) keeps defaultwiredtoglobal first overall. Consumers: Makefile LIBRARY_TESTS gains lib/log/silent_test.ww beside the log_test.ww entry; test/byteid/libbyteid_test.ww roster gains fx("lib/log/silent_test.ww") after the log_test row, roster 44->45 (+1, NENTEXPECT bumped). Validation: standalone ww test lib/log/log_test.ww (9 passed) and lib/log/silent_test.ww (2 passed); dir mode ww test lib/log (11 passed, defaultwiredtoglobal first); test/byteid/libbyteid_test.ww compile-only build exit 0, 45 roster appends == NENTEXPECT. --- Makefile | 2 +- lib/log/log_test.ww | 41 ----------------------------------- lib/log/silent_test.ww | 41 +++++++++++++++++++++++++++++++++++ test/byteid/libbyteid_test.ww | 3 ++- 4 files changed, 44 insertions(+), 43 deletions(-) create mode 100644 lib/log/silent_test.ww diff --git a/Makefile b/Makefile index 4f93dba5..1f1835cc 100644 --- a/Makefile +++ b/Makefile @@ -488,7 +488,7 @@ LIBRARY_TESTS = lib/errors/errno_test.ww lib/ascii/ascii_test.ww \ lib/bytes/bytes_test.ww lib/encoding/utf8/utf8_test.ww \ lib/bufio/bufio_test.ww lib/math/random/random_test.ww \ lib/math/checked/checked_test.ww lib/fmt/fmt_test.ww \ - lib/log/log_test.ww lib/fnmatch/fnmatch_test.ww \ + lib/log/log_test.ww lib/log/silent_test.ww lib/fnmatch/fnmatch_test.ww \ lib/shlex/shlex_test.ww lib/time/time_test.ww \ lib/encoding/hex/hex_test.ww lib/memio/memio_test.ww \ lib/temp/temp_test.ww lib/getopt/getopt_test.ww \ diff --git a/lib/log/log_test.ww b/lib/log/log_test.ww index 2db86ce2..9c2937f1 100644 --- a/lib/log/log_test.ww +++ b/lib/log/log_test.ww @@ -89,28 +89,6 @@ fn streq(a: str, b: str) bool = { assert(!(!streq(memio.string(&mem), "\n"))); }; -// ---- silent: lprintln through log.silent writes no bytes -------------- - -// The silent logger's callback discards args without touching fmt or -// any sink. Verified indirectly: we wire a memio.stream and never -// pass it to log.silent — but the @test fn calling log.new first -// triggers [[log.ensureinit]] so log.silent is non-nil here. Then -// lprintln(silent, ...) must not crash and the memio sink must stay -// empty (silent has no path to it anyway). -@test fn silentwritesnothing() void = { - let buf: [16]u8; - let mem = memio.fixed(buf[0:16]); - let s = &mem.vt; - - let sl = log.new(s); // triggers log.ensureinit; populates log.silent - - assert(!(log.silent == nil)); - - log.lprintln(log.silent, "ignored", 1i64, true); - - assert(!(mem.pos != 0)); -}; - // ---- setlogger swap: global redirects to a new sink, then to silent -- // Three-phase: install sl1 as global, println writes there; swap to @@ -181,25 +159,6 @@ fn streq(a: str, b: str) bool = { assert(!(mem2.pos != 0)); }; -// ---- silent.printfln writes nothing --------------------------------- - -// The silent logger's printfln callback discards args without touching -// fmt or any sink. Same pattern as [[silentwritesnothing]] for the -// bare-args path. -@test fn silentignoresprintfln() void = { - let buf: [16]u8; - let mem = memio.fixed(buf[0:16]); - let s = &mem.vt; - - let sl = log.new(s); // triggers log.ensureinit; populates log.silent - - assert(!(log.silent == nil)); - - log.lprintfln(log.silent, "ignored={}", 1i64); - - assert(!(mem.pos != 0)); -}; - // ---- lprintfln: indexed {N} placeholder across log → fmt seam ------- // The fmt parser proper is covered in fmttest; this pins that log's diff --git a/lib/log/silent_test.ww b/lib/log/silent_test.ww new file mode 100644 index 00000000..06476b3a --- /dev/null +++ b/lib/log/silent_test.ww @@ -0,0 +1,41 @@ +package log_test; + +import log; +import memio; + +// The silent logger's callback discards args without touching fmt or +// any sink. Verified indirectly: we wire a memio.stream and never +// pass it to log.silent — but the @test fn calling log.new first +// triggers [[log.ensureinit]] so log.silent is non-nil here. Then +// lprintln(silent, ...) must not crash and the memio sink must stay +// empty (silent has no path to it anyway). +@test fn silentwritesnothing() void = { + let buf: [16]u8; + let mem = memio.fixed(buf[0:16]); + let s = &mem.vt; + + let sl = log.new(s); // triggers log.ensureinit; populates log.silent + + assert(!(log.silent == nil)); + + log.lprintln(log.silent, "ignored", 1i64, true); + + assert(!(mem.pos != 0)); +}; + +// The silent logger's printfln callback discards args without touching +// fmt or any sink. Same pattern as [[silentwritesnothing]] for the +// bare-args path. +@test fn silentignoresprintfln() void = { + let buf: [16]u8; + let mem = memio.fixed(buf[0:16]); + let s = &mem.vt; + + let sl = log.new(s); // triggers log.ensureinit; populates log.silent + + assert(!(log.silent == nil)); + + log.lprintfln(log.silent, "ignored={}", 1i64); + + assert(!(mem.pos != 0)); +}; diff --git a/test/byteid/libbyteid_test.ww b/test/byteid/libbyteid_test.ww index 6868b73e..8941fc11 100644 --- a/test/byteid/libbyteid_test.ww +++ b/test/byteid/libbyteid_test.ww @@ -43,7 +43,7 @@ import time; def MID: i32 = 0; def MDIVERGE: i32 = 1; def MWWREJECT: i32 = 2; -def NENTEXPECT: i32 = 44; +def NENTEXPECT: i32 = 45; type ent = struct { fixture: str, // repo-relative .ww; "" -> probe entry @@ -142,6 +142,7 @@ fn corpus() []ent = { append(es, fx("lib/encoding/base64/base64_test.ww")); append(es, fx("lib/errors/errno_test.ww")); append(es, fx("lib/log/log_test.ww")); + append(es, fx("lib/log/silent_test.ww")); append(es, fx("lib/os/stat_test.ww")); // toktest/asttest resolve `import syntax` via -I lib/ww, cf 905 append(es, fxi("lib/ww/syntax/tok_test.ww", "lib/ww"));