Move xce_test's 15 production sources + headers from src/controller/testsuite/ into a new src/harness/ component with its own meson.build, and strip every now-dangling controller-side reference (11 controller_unit_test_src entries, 4 standalone test-binary blocks, 11 controller_test.c extern/RUN_TEST lines) so the controller build is never left broken. Fixes a broken relative-symlink bridge (xce_test_controller_link) added to keep two controller-embedded tests (test_test_cli.c, test_xcetest_process_entry.c) finding the relocated xce_test binary until task 2.1 moves them too. Discovered and documented in design.md: four controller-domain regression tests call functions directly from four of xce_test's own files, requiring controller_unit_test to permanently recompile them from src/harness/ — a real dependency neither the original discovery nor design audit caught. controller_unit_test: 1228 Tests 0 Failures 0 Ignored (verified via the Unity binary's own printed summary line, not just meson's aggregate count). Task 1.1 of xce-harness-component. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RLSNJhNoULvVcUhXEFafQC
54 lines
2.6 KiB
C
54 lines
2.6 KiB
C
#pragma once
|
|
/*
|
|
* listfmt_json.h -- shared cJSON array/object plumbing for xce_test's
|
|
* listing commands' JSON output mode (xce-test-cli-ux spec, task 2.2;
|
|
* Requirements 5.1, 5.3).
|
|
*
|
|
* This module owns ONLY the JSON array/object lifecycle: start an array,
|
|
* append a new row object to it, add string/number fields to a row, then
|
|
* print + free the whole array. It does NOT know about workerlist's/
|
|
* joblist's/reslist's own field sets -- each command's existing row
|
|
* struct already exists and is stable (design.md's Simplification lens),
|
|
* so this library introduces no generic "record"/"row" abstraction beyond
|
|
* the bare cJSON object handle itself. Wiring this into cmd_workerlist/
|
|
* cmd_joblist/cmd_reslist (their field mapping, their --json flag) is
|
|
* task 3.4, not this one.
|
|
*
|
|
* cJSON is already linked into xce_test (struct2json_dep, per
|
|
* research.md) and already used for job exdata blobs (test.c's
|
|
* build_job_envs()) -- this module reuses that exact same cJSON API
|
|
* surface, not a different one.
|
|
*/
|
|
|
|
#include <cjson/cJSON.h>
|
|
|
|
/* Creates a new, empty JSON array meant to hold one object per output
|
|
* row. The caller passes the returned array to listfmt_json_new_row()
|
|
* once per row, then to listfmt_json_finish() exactly once when done.
|
|
* Returns NULL on allocation failure. */
|
|
cJSON* listfmt_json_begin(void);
|
|
|
|
/* Adds a string field `key`: `val` to `row`. `val` is copied in full,
|
|
* regardless of its length -- no field is ever truncated or dropped for
|
|
* being "too long" (Requirement 5.3). A NULL `val` is stored as an
|
|
* explicit JSON null rather than silently omitted or crashing. No-op if
|
|
* `row` or `key` is NULL. */
|
|
void listfmt_json_add_string(cJSON* row, const char* key, const char* val);
|
|
|
|
/* Adds a numeric field `key`: `val` to `row`. No-op if `row` or `key` is
|
|
* NULL. */
|
|
void listfmt_json_add_number(cJSON* row, const char* key, double val);
|
|
|
|
/* Creates a new, empty JSON object, appends it to `array`, and returns
|
|
* that object so the caller can then call listfmt_json_add_string()/
|
|
* listfmt_json_add_number() on it for each of this row's fields. Returns
|
|
* NULL (leaving `array` unmodified) if `array` is NULL or the new object
|
|
* could not be allocated. */
|
|
cJSON* listfmt_json_new_row(cJSON* array);
|
|
|
|
/* Prints `array` to stdout as JSON -- command-RESULT data, per
|
|
* Requirement 3's stdout/stderr discipline, so it is written to stdout
|
|
* only, never stderr -- and then frees the entire cJSON structure
|
|
* (`array` and every row/field it holds). `array` must not be
|
|
* referenced again after this call. No-op if `array` is NULL. */
|
|
void listfmt_json_finish(cJSON* array);
|