nx_tool_census_run_test.nx source
↩ module page · 50 lines · 1850 B
1// nx_tool_census_run_test.nx -- end-to-end bits-up audit binary.
2//
3// Composes nx_dir_list (syscall walk) + sys_openat_rd / sys_read /
4// sys_close (per-file I/O) + nx_tool_census_classify (sealed-enum
5// classifier) + nx_tool_census_accumulate (counts) -- all in
6// bits-up NishiLang. No bash / grep / xargs / awk in the LOGIC
7// or I/O paths.
8//
9// Smoke harness creates /tmp/nx_census_fixture/ with 4 synthetic
10// files:
11// nx_alpha.nx header has 'AUTO-GENERATED' -> AUTO_GENERATED
12// nx_bravo.nx header has 'Composes: nx_x' -> HAND_WRITTEN_DECLARED
13// nx_charlie.nx header is plain -> HAND_WRITTEN_UNDECLARED
14// nx_delta_test.nx any content (suffix wins) -> TEST
15//
16// This binary walks that dir + verifies counts match. Exit 0 = PASS;
17// non-zero codes identify which assertion failed. Substrate's first
18// end-to-end bits-up audit executable.
19
20import "nx_syscalls.nx"
21import "nx_string_ops.nx"
22import "nx_dir.nx"
23import "nx_grep.nx"
24import "nx_tool_census.nx"
25
26func main() -> i64 {
27 let path: *u8 = "/tmp/nx_census_fixture"
28 let path_len: i64 = 22
29
30 let counts_buf: *u8 = sys_mmap(128)
31 let counts: *NxToolCensusCounts = counts_buf as *NxToolCensusCounts
32 nx_tool_census_counts_init(counts)
33
34 let rc: i64 = nx_tool_census_walk_dir(path, path_len, counts)
35 if rc != 0 { return 10 }
36
37 // ----- Verify expected counts -----
38 if counts.n_total != 4 { return 1 }
39 if counts.n_test != 1 { return 2 }
40 if counts.n_offc != 0 { return 3 }
41 if counts.n_auto_generated != 1 { return 4 }
42 if counts.n_hand_written != 2 { return 5 }
43 if counts.n_declared != 1 { return 6 }
44 if counts.n_undeclared != 1 { return 7 }
45
46 // ----- Verify pct_declared = 50 (1 of 2 hand-written) -----
47 if nx_tool_census_pct_declared(counts) != 50 { return 8 }
48
49 return 0
50}