Skip to content

Commit b23d468

Browse files
committed
Revamp test harness and cleanup CLI temp files
Replace per-test test.c runner with an assertion-based scheme: tests now provide assertion.c; tests/test.c was rewritten to compile/run tests async, run assertion binaries, collect and serialize TestResults, and report a unified summary. tests/test.h gains TestResults parsing/ serialization and helper macros (READ_STDOUTS, INIT_TEST_ENV, CLOSE_TEST_ENV). Add many assertion.c files and remove old test.c stubs. Minor cleanup: remove unused Context path fields and temp files, and silence debug prints in main/cli; adjust top_level_comptime_block to return success after comptime execution.
1 parent f7eb577 commit b23d468

File tree

22 files changed

+364
-113
lines changed

22 files changed

+364
-113
lines changed

cli.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,10 @@ typedef struct {
7272
String_Builder *preprocessed_source;
7373

7474
const char *input_path;
75-
const char *preprocessed_path;
76-
77-
const char *runner_templ_path;
7875
const char *runner_exepath;
7976
const char *runner_defs_path;
8077
const char *runner_main_path;
8178

82-
const char *vals_path;
8379
const char *final_out_path;
8480
const char *gen_header_path;
8581
const char *comptime_safe_path;
@@ -105,9 +101,6 @@ char *leaky_sprintf(const char *fmt, ...) {
105101
}
106102

107103
static void Context_fill_paths(Context *ctx, const char *original_source) {
108-
ctx->preprocessed_path =
109-
leaky_sprintf("%sct-preprocessed.i", original_source);
110-
ctx->runner_templ_path = leaky_sprintf("%sct-runner.c", original_source);
111104
ctx->runner_defs_path = leaky_sprintf("%sc-runner-defs.c", original_source);
112105
ctx->runner_main_path = leaky_sprintf("%sc-runner-main.c", original_source);
113106
ctx->comptime_safe_path = leaky_sprintf("%somptime_safe.c", original_source);
@@ -117,7 +110,6 @@ static void Context_fill_paths(Context *ctx, const char *original_source) {
117110
#else
118111
ctx->runner_exepath = leaky_sprintf("%sct-runner", original_source);
119112
#endif
120-
ctx->vals_path = leaky_sprintf("%sct-vals.cct_vals", original_source);
121113
ctx->final_out_path = leaky_sprintf("%sct-final.c", original_source);
122114
ctx->gen_header_path = leaky_sprintf("%s.h", original_source);
123115
}

main.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,26 +280,23 @@ int main(int argc, char **argv) {
280280

281281
Nob_Cmd cmd = {0};
282282
nob_log(INFO, "Running runner %s", ctx.runner_exepath);
283-
printf("=== Compile time logs ===\n");
283+
// printf("=== Compile time logs ===\n");
284284
// nob_cmd_append(&cmd, nob_temp_sprintf("./%s", ctx.runner_exepath));
285285
nob_cmd_append(&cmd, nob_temp_sprintf("%s", ctx.runner_exepath));
286286
if (!nob_cmd_run(&cmd)) {
287-
nob_log(ERROR, "failed to run runner %s", ctx.runner_templ_path);
287+
nob_log(ERROR, "failed to run runner %s", ctx.runner_exepath);
288288
exit(1);
289289
}
290290
fflush(stdout);
291-
printf("=== end === \n");
291+
// printf("=== end === \n");
292292

293293
write_final_wrapper(&ctx);
294294
parsed_argv.argv[*index] = (char *)ctx.final_out_path;
295295

296-
da_append(&files_to_remove, ctx.preprocessed_path);
297296
da_append(&files_to_remove, ctx.runner_main_path);
298297
da_append(&files_to_remove, ctx.runner_defs_path);
299298
da_append(&files_to_remove, ctx.comptime_safe_path);
300-
da_append(&files_to_remove, ctx.runner_templ_path);
301299
da_append(&files_to_remove, ctx.runner_exepath);
302-
da_append(&files_to_remove, ctx.vals_path);
303300
da_append(&files_to_remove, ctx.final_out_path);
304301
}
305302

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "../test.h"
2+
3+
test({
4+
assert_log_includes(exec_stdout.items, "COMPTIME_VALUE=42",
5+
"COMPTIME_VALUE does not equal 42");
6+
})

tests/auto_header_injection/test.c

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/comptime_type/assertion.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "../test.h"
2+
3+
test({
4+
assert_log_includes(exec_stdout.items, "VALUE=7",
5+
"Expected _ComptimeType to materialize struct literal");
6+
})

tests/comptime_type/test.c

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/include_header_macro/main.cc-runner-defs.c

Whitespace-only changes.

tests/include_header_macro/main.cc-runner-main.c

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
#define _COMPILING
3+
#include <stdio.h>
4+
5+
#include "../../ccomptime.h"
6+
#include "main.c.h"
7+
#include "lib.h"
8+
9+
int main(void) {
10+
int v = get_header_value();
11+
printf("ANSWER=%d\n", v);
12+
return v == 5 ? 0 : 1;
13+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "../test.h"
2+
3+
test({
4+
assert_log_includes(
5+
exec_stdout.items, "SUM=6",
6+
"Expected macro argument reused across _Comptime calls to expand twice");
7+
})

0 commit comments

Comments
 (0)