ww: lib tests run via -T test mode; bare mains retired (closes @test conversion)
'ww test' gains the istest build path (-T injection in build_one/ buildone) and do_test/dotest accept -I, mirroring do_run - both twins. The 35 converted lib tests drop their interim bare mains (-T synthesizes the entry from @test fns and rejects a user main); their 35 C run-drivers flip 'ww run' -> 'ww test'; 989_lib_byteid compiles lib tests under -T (8 user-main probe fixtures stay non-T, gated on the fixture field). Abort-on-first-failure stands until the deferred record-and-continue harness lands with the multi-package arc.
This commit is contained in:
@@ -384,7 +384,7 @@ expand(FILE *out, const char *path, struct ImportSet *visited,
|
||||
static int
|
||||
build_one(const char *src, int entry_is_dir, const char *out,
|
||||
const char *objstem, const char *extra_includes, const char *extra_libs,
|
||||
const char *extra_libdirs)
|
||||
const char *extra_libdirs, int is_test)
|
||||
{
|
||||
const char *c6 = toolpath("WW_W6C", "w6c");
|
||||
const char *a6 = toolpath("WW_W6A", "w6a");
|
||||
@@ -478,7 +478,8 @@ build_one(const char *src, int entry_is_dir, const char *out,
|
||||
}
|
||||
|
||||
char cmd[4096];
|
||||
snprintf(cmd, sizeof cmd, "%s -o %s %s", c6, asmf, combined);
|
||||
snprintf(cmd, sizeof cmd, "%s %s-o %s %s", c6, is_test ? "-T " : "",
|
||||
asmf, combined);
|
||||
if (run(cmd) != 0) {
|
||||
fprintf(stderr, "ww: w6c failed\n");
|
||||
return 1;
|
||||
@@ -714,7 +715,7 @@ do_build(int argc, char **argv)
|
||||
} else {
|
||||
basename_no_ext(resolved, out, sizeof out);
|
||||
}
|
||||
return build_one(resolved, is_dir, out, objstem, incs, libs, libdirs);
|
||||
return build_one(resolved, is_dir, out, objstem, incs, libs, libdirs, 0);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -739,7 +740,7 @@ do_run(int argc, char **argv)
|
||||
snprintf(tmp, sizeof tmp, "/tmp/ww_run_%d", getpid());
|
||||
/* objstem = tmp → intermediates land at /tmp/ww_run_<pid>.{s,o,
|
||||
* combined.ww}, never next to the source (T3). */
|
||||
if (build_one(resolved, is_dir, tmp, tmp, incs, libs, libdirs) != 0)
|
||||
if (build_one(resolved, is_dir, tmp, tmp, incs, libs, libdirs, 0) != 0)
|
||||
return 1;
|
||||
/* exec the built binary with any trailing argv as its argv. */
|
||||
pid_t pid = fork();
|
||||
@@ -764,21 +765,29 @@ do_run(int argc, char **argv)
|
||||
static int
|
||||
do_test(int argc, char **argv)
|
||||
{
|
||||
const char *target = (argc > 0) ? argv[0] : ".";
|
||||
const char *src = NULL;
|
||||
char libs[2048] = {0};
|
||||
char libdirs[2048] = {0};
|
||||
char incs[2048] = {0};
|
||||
char outflag[1024] = {0}; /* -o accepted+ignored: test uses the temp */
|
||||
parse_build_flags(argc, argv, incs, sizeof incs,
|
||||
libdirs, sizeof libdirs, libs, sizeof libs,
|
||||
outflag, sizeof outflag, &src);
|
||||
const char *target = src ? src : ".";
|
||||
struct stat st;
|
||||
if (stat(target, &st) != 0) {
|
||||
/* not a literal path — try module resolution and run as
|
||||
* a single test program. */
|
||||
char resolved[1024];
|
||||
int is_dir = 0;
|
||||
if (!resolve_module(target, "", resolved, sizeof resolved,
|
||||
if (!resolve_module(target, incs, resolved, sizeof resolved,
|
||||
&is_dir)) {
|
||||
fprintf(stderr, "ww test: cannot find %s\n", target);
|
||||
return 1;
|
||||
}
|
||||
char tmp[1024];
|
||||
snprintf(tmp, sizeof tmp, "/tmp/ww_test_%d", getpid());
|
||||
if (build_one(resolved, is_dir, tmp, NULL, "", "", "") != 0) return 1;
|
||||
if (build_one(resolved, is_dir, tmp, NULL, incs, "", "", 1) != 0) return 1;
|
||||
int rc = run(tmp);
|
||||
unlink(tmp);
|
||||
return rc;
|
||||
@@ -787,7 +796,7 @@ do_test(int argc, char **argv)
|
||||
/* single .ww file — build+run it. */
|
||||
char tmp[1024];
|
||||
snprintf(tmp, sizeof tmp, "/tmp/ww_test_%d", getpid());
|
||||
if (build_one(target, 0, tmp, NULL, "", "", "") != 0) return 1;
|
||||
if (build_one(target, 0, tmp, NULL, incs, "", "", 1) != 0) return 1;
|
||||
int rc = run(tmp);
|
||||
unlink(tmp);
|
||||
return rc;
|
||||
@@ -813,7 +822,7 @@ do_test(int argc, char **argv)
|
||||
snprintf(tmp, sizeof tmp, "/tmp/ww_test_%d_%d", getpid(), i);
|
||||
const char *label = strrchr(files[i], '/');
|
||||
label = label ? label + 1 : files[i];
|
||||
int rc = build_one(files[i], 0, tmp, NULL, target, "", "");
|
||||
int rc = build_one(files[i], 0, tmp, NULL, target, "", "", 1);
|
||||
if (rc != 0) {
|
||||
fprintf(stderr, "FAIL %s (build)\n", label);
|
||||
fail++;
|
||||
|
||||
Reference in New Issue
Block a user