stage3 ai编写新语法语义 同时提供fflush

This commit is contained in:
zzy committed 2026-11-05 09:48:43 +08:00
1 parent bb8761d392
commit 126b979f72
170 files changed
+10729 -3175

No files matched your search

+56 -6
View File
@@ -458,6 +458,7 @@ typedef struct {
bool has_location;
int line;
int col;
bool pending;
} test_expect_t;
static bool test_parse_error_code(Nob_String_View value, int *out) {
@@ -539,8 +540,11 @@ static bool test_parse_expect(const char *fname, test_expect_t *expect) {
break;
continue;
}
if (nob_sv_eq(key, nob_sv_from_cstr("location"))) {
if (expect->has_location) {
if (nob_sv_eq(key, nob_sv_from_cstr("pending"))) {
expect->pending = true;
continue;
}
if (nob_sv_eq(key, nob_sv_from_cstr("location"))) { if (expect->has_location) {
malformed = true;
break;
}
@@ -622,6 +626,7 @@ typedef struct {
const scc_argparse_list_t *filters; // 按文件名子串过滤,空则全跑
int passed;
int failed;
int pending; // `// Expect pending` 的预期失败数
int no_expect; // 没写 Expect 注解、按 0 期望的文件数
} test_ctx_t;
@@ -631,6 +636,47 @@ static bool test_has_error_code(const Nob_Cmd_Result *result, int code) {
return result->out.items != NULL && strstr(result->out.items, needle) != NULL;
}
static void test_pending_compile_and_run(const char *fname, test_ctx_t *ctx) {
Nob_Cmd compile = {0};
nob_cmd_extend(&compile, &ctx->compiler);
nob_cmd_append(&compile, fname, ctx->out_sir);
Nob_Cmd_Result compile_result = {0};
if (!run_capture(&compile, &compile_result)) {
nob_log(NOB_ERROR, "%s: failed to launch compiler", fname);
nob_cmd_free(compile);
ctx->failed += 1;
return;
}
nob_cmd_free(compile);
if (compile_result.exit_code != 0) {
nob_log(NOB_INFO, "%s: pending (compile failed as expected)", fname);
nob_cmd_result_free(compile_result);
ctx->pending += 1;
return;
}
nob_cmd_result_free(compile_result);
Nob_Cmd run = {0};
nob_cmd_extend(&run, &ctx->vm);
nob_cmd_append(&run, ctx->out_sir);
Nob_Cmd_Result result = {0};
if (!run_capture(&run, &result)) {
nob_log(NOB_ERROR, "%s: failed to run", fname);
nob_cmd_free(run);
ctx->failed += 1;
return;
}
nob_cmd_free(run);
if (result.exit_code != 0) {
nob_log(NOB_INFO, "%s: pending (run failed as expected)", fname);
ctx->pending += 1;
} else {
nob_log(NOB_ERROR, "%s: pending test passed unexpectedly; remove `// Expect pending`", fname);
ctx->failed += 1;
}
nob_cmd_result_free(result);
}
static void test_compile_and_run(const char *fname, test_ctx_t *ctx) {
test_expect_t expect = {0};
if (!test_parse_expect(fname, &expect)) {
@@ -638,6 +684,10 @@ static void test_compile_and_run(const char *fname, test_ctx_t *ctx) {
ctx->failed += 1;
return;
}
if (expect.pending) {
test_pending_compile_and_run(fname, ctx);
return;
}
Nob_Cmd compile = {0};
nob_cmd_extend(&compile, &ctx->compiler);
@@ -976,11 +1026,11 @@ static int cli_test(nob_cli_t *cli) {
bool walked = walk_spl_files(suite->dir, &cli->test_filters, test_run_file, &ctx);
if (ctx.no_expect > 0)
nob_log(NOB_INFO, "%s (`%s`): %d passed, %d failed (%d without `// Expect`)", suite->name,
target, ctx.passed, ctx.failed, ctx.no_expect);
nob_log(NOB_INFO, "%s (`%s`): %d passed, %d failed, %d pending (%d without `// Expect`)", suite->name,
target, ctx.passed, ctx.failed, ctx.pending, ctx.no_expect);
else
nob_log(NOB_INFO, "%s (`%s`): %d passed, %d failed", suite->name, target, ctx.passed,
ctx.failed);
nob_log(NOB_INFO, "%s (`%s`): %d passed, %d failed, %d pending", suite->name, target,
ctx.passed, ctx.failed, ctx.pending);
nob_cmd_free(ctx.compiler);
nob_cmd_free(ctx.vm);