feat(build-time-versioning): version macro/helper functions with unknown fallback
Adds xce_version_field()/xce_compose_version() (utils.h/utils.c) to compose a version string carrying commit id + build time, rendering "unknown" for either field when its underlying meson-supplied define is empty -- ready for controller/scheduler/worker to consume. MK_VERSION/STR (the pre-existing, compile-time-only macro pair) can't express this empty-to-"unknown" substitution at the preprocessor level, so this is a runtime mechanism instead. Round 1 review REJECTED an earlier version of this task for silently orphaning MK_VERSION/STR (the task explicitly asked to "extend" them) and for leaving an undocumented architectural trap: argp_program_version is a file-scope const char* initialized at compile time, which cannot call a runtime function -- consuming code must instead compute into a static buffer inside main() and assign the pointer before argp_parse() runs. Round 2 adds an explicit SUPERSEDED doc comment on MK_VERSION/STR plus NOTE FOR CALLERS guidance covering both points, and was APPROVED. Also expands task 3.2's boundary to include controller/testsuite/test.c (a third MK_VERSION/STR call site discovered during review) so no caller of the superseded macro survives implementation. 5 new unit tests in test_utils.c (RED->GREEN, TDD). Task 3.1/13 of build-time-versioning. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
d08fda76a5
commit
48a86cdab6
4 changed files with 159 additions and 7 deletions
|
|
@ -140,6 +140,55 @@ void test_parse_jobid2(void)
|
|||
do_parse_jobid_test(jobid);
|
||||
}
|
||||
|
||||
/* build-time-versioning task 3.1: xce_version_field()'s empty/NULL ->
|
||||
* "unknown" fallback, used to keep the composed --version string free of
|
||||
* blank gaps when VERSION_COMMIT_ID/VERSION_BUILD_TIME are unset. */
|
||||
void test_version_field_unknown_fallback(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_STRING("unknown", xce_version_field(NULL));
|
||||
TEST_ASSERT_EQUAL_STRING("unknown", xce_version_field(""));
|
||||
}
|
||||
|
||||
void test_version_field_passthrough(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_STRING("a1b2c3d", xce_version_field("a1b2c3d"));
|
||||
TEST_ASSERT_EQUAL_STRING("2026-08-20T10:00:00Z",
|
||||
xce_version_field("2026-08-20T10:00:00Z"));
|
||||
}
|
||||
|
||||
void test_compose_version_both_set(void)
|
||||
{
|
||||
char buf[128];
|
||||
int n;
|
||||
|
||||
n = xce_compose_version(buf, sizeof(buf), "xce v0.0.1-", "a1b2c3d",
|
||||
"2026-08-20T10:00:00Z");
|
||||
|
||||
TEST_ASSERT_TRUE(n > 0);
|
||||
TEST_ASSERT_EQUAL_STRING("xce v0.0.1-a1b2c3d built 2026-08-20T10:00:00Z",
|
||||
buf);
|
||||
}
|
||||
|
||||
void test_compose_version_both_unset(void)
|
||||
{
|
||||
char buf[128];
|
||||
|
||||
xce_compose_version(buf, sizeof(buf), "xce v0.0.1-", "", "");
|
||||
|
||||
/* both fields must render as the literal word "unknown", never a
|
||||
* blank/garbled gap (e.g. NOT "xce v0.0.1- built "). */
|
||||
TEST_ASSERT_EQUAL_STRING("xce v0.0.1-unknown built unknown", buf);
|
||||
}
|
||||
|
||||
void test_compose_version_null_fields(void)
|
||||
{
|
||||
char buf[128];
|
||||
|
||||
xce_compose_version(buf, sizeof(buf), "xce v0.0.1-", NULL, NULL);
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING("xce v0.0.1-unknown built unknown", buf);
|
||||
}
|
||||
|
||||
void test_utils(void)
|
||||
{
|
||||
printf("\n>> utils test\n\n");
|
||||
|
|
@ -150,4 +199,9 @@ void test_utils(void)
|
|||
RUN_TEST(test_extract_bits);
|
||||
RUN_TEST(test_parse_jobid1);
|
||||
RUN_TEST(test_parse_jobid2);
|
||||
RUN_TEST(test_version_field_unknown_fallback);
|
||||
RUN_TEST(test_version_field_passthrough);
|
||||
RUN_TEST(test_compose_version_both_set);
|
||||
RUN_TEST(test_compose_version_both_unset);
|
||||
RUN_TEST(test_compose_version_null_fields);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue