lib+test: fmt rename fprint→fdprint; add io.stream fprint sink

This commit is contained in:
2026-05-15 11:34:47 +09:00
parent e6045f3ada
commit 0ef94eef04
7 changed files with 485 additions and 40 deletions

View File

@@ -1639,7 +1639,7 @@ static const struct row rows[] = {
"fn main() i32 = { return sumtag(1i64, \"hi\", true): i32; };", 42 },
/* Variadic forwarding: `wrap(args...)` passes the local slice
* directly to `sum`, no re-gather. Mirrors Hare's wrapper shape
* (`fn println(args: formattable...) = fprintln(os.stdout, args...)`). */
* (`fn println(args: formattable...) = fdprintln(os.stdout, args...)`). */
{ "fn sum(args: i64...) i64 = {\n"
" let s: i64 = 0i64;\n"
" let i: i32 = 0;\n"
@@ -1654,8 +1654,8 @@ static const struct row rows[] = {
"};", 42 },
/* lib/fmt user-side: `fmt.println(args: formattable...)` gathers
* mixed-type args at the call site. End-to-end exercises the
* lib/fmt graduation: the wrapper-chain `println → fprintln →
* fprint` is itself variadic-forwarding, so this validates both
* lib/fmt graduation: the wrapper-chain `println → fdprintln →
* fdprint` is itself variadic-forwarding, so this validates both
* gather (at main) and `args...` forward (inside lib/fmt). The
* exit code is bytes printed (`hello 7\n` = 8). */
{ "use fmt;\n"

View File

@@ -33,13 +33,13 @@ static const char *modules[] = {
"lib/math/random/random.ww",
"lib/time/time.ww",
"lib/c/libc/libc.ww",
/* lib/bufio/bufio.ww moved off this list: graduates to the
* io.stream-based scanner, which carries cross-module type
* refs (*io.stream, io.eof, io.closed) that only resolve once
* the driver concatenates `use`d modules. Coverage lives at
* lib/bufio/bufiotest.ww + the bufio.scanline e2e row in
* test/wcc/700_e2e.c. */
"lib/fmt/fmt.ww",
/* lib/bufio/bufio.ww and lib/fmt/fmt.ww moved off this list:
* both graduated to io.stream-based sinks, which carry cross-
* module type refs (*io.stream, io.closed, io.eof) that only
* resolve once the driver concatenates `use`d modules. Coverage
* lives at lib/bufio/bufiotest.ww + lib/fmt/fmttest.ww (wired
* at 998_bufio_run.c and 970_fmt_run.c), plus the bufio.scanline
* and fmt.println e2e rows in test/wcc/700_e2e.c. */
"lib/net/net.ww",
NULL
};

52
test/wcc/970_fmt_run.c Normal file
View File

@@ -0,0 +1,52 @@
/*
* 970_fmt_run — execute the lib/fmt @test fixture under the C-side
* `ww run` driver and assert exit 0.
*
* fmt sits below io conceptually (sinks formatted bytes into an
* io.stream); slotting at 970 keeps it ahead of the 980-989
* stdlib-run sub-band that depends on it. fmttest.ww carries its
* own `export fn main()` that drives the @test fns and signals
* which case failed via the exit code, so this file is a thin
* wrapper — no @test scanning, no synthetic main generation.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
static int
runwait(const char *cmd)
{
int rc = system(cmd);
if (rc == -1) return -1;
if (WIFEXITED(rc)) return WEXITSTATUS(rc);
return 1;
}
int
main(void)
{
const char *bin = getenv("BIN");
if (!bin) bin = "out/bin";
char absbin[1024];
if (bin[0] != '/') {
char cwd[1024];
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
snprintf(absbin, sizeof absbin, "%s/%s", cwd, bin);
bin = absbin;
}
char cwd[1024];
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
const char *src = "lib/fmt/fmttest.ww";
char path[1024], cmd[2048];
snprintf(path, sizeof path, "%s/%s", cwd, src);
snprintf(cmd, sizeof cmd, "%s/ww run %s", bin, path);
int rc = runwait(cmd);
if (rc != 0) {
fprintf(stderr, "fmt_run FAIL: %s exited %d\n", src, rc);
return 1;
}
printf("fmt_run: %s ok\n", src);
return 0;
}