From 62d517918f04f91de191d9974fc2a035b5fbad60 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 13 Oct 2025 14:25:22 +1030 Subject: [PATCH] tal/str: fix up test cases now take(NULL) is not passed through. This was changed in b22095b2757 (Rusty Russell 2024-04-04: ccan: update tal so we can annote allcators as never returning NULL.) but unit tests were not updated to match. Signed-off-by: Rusty Russell --- ccan/tal/str/test/run-string.c | 20 +------------------- ccan/tal/str/test/run-strreg.c | 6 +----- ccan/tal/str/test/run-take.c | 8 +------- ccan/tal/str/test/run.c | 11 +---------- 4 files changed, 4 insertions(+), 41 deletions(-) diff --git a/ccan/tal/str/test/run-string.c b/ccan/tal/str/test/run-string.c index 03d4eb51..a4f5f9b1 100644 --- a/ccan/tal/str/test/run-string.c +++ b/ccan/tal/str/test/run-string.c @@ -7,7 +7,7 @@ int main(void) { char *parent, *c; - plan_tests(43); + plan_tests(34); parent = tal(NULL, char); ok1(parent); @@ -69,20 +69,6 @@ int main(void) ok1(tal_parent(c) == parent); ok1(single_child(parent, c)); - /* NULL pass through works... */ - c = tal_strcat(parent, take(NULL), take(c)); - ok1(!c); - ok1(no_children(parent)); - - c = tal_strcat(parent, take(tal_strdup(parent, "hi")), - take(NULL)); - ok1(!c); - ok1(no_children(parent)); - - c = tal_strcat(parent, take(NULL), take(NULL)); - ok1(!c); - ok1(no_children(parent)); - /* Appending formatted strings. */ c = tal_strdup(parent, "hi"); ok1(tal_count(c) == strlen(c) + 1); @@ -91,10 +77,6 @@ int main(void) ok1(tal_count(c) == strlen(c) + 1); ok1(tal_parent(c) == parent); - ok1(!tal_append_fmt(&c, take(NULL), "there", "world")); - ok1(strcmp(c, "hithere world") == 0); - ok1(tal_count(c) == strlen(c) + 1); - tal_free(parent); return exit_status(); diff --git a/ccan/tal/str/test/run-strreg.c b/ccan/tal/str/test/run-strreg.c index 55e244c6..dab3b2a3 100644 --- a/ccan/tal/str/test/run-strreg.c +++ b/ccan/tal/str/test/run-strreg.c @@ -21,7 +21,7 @@ int main(void) /* If it accesses this, it will crash. */ char **invalid = (char **)1L; - plan_tests(54); + plan_tests(53); /* Simple matching. */ ok1(tal_strreg(ctx, "hello world!", "hello") == true); ok1(tal_strreg(ctx, "hello world!", "hi") == false); @@ -90,10 +90,6 @@ int main(void) /* No leaks! */ ok1(no_children(ctx)); - /* NULL arg with take means always fail. */ - ok1(tal_strreg(ctx, take(NULL), "((hello|goodbye) world)", - &b, NULL, invalid) == false); - /* Take string. */ a = tal_strdup(ctx, "hello world!"); ok1(tal_strreg(ctx, take(a), "([a-z]+)", &b, invalid) == true); diff --git a/ccan/tal/str/test/run-take.c b/ccan/tal/str/test/run-take.c index edf173f8..f12c8ea4 100644 --- a/ccan/tal/str/test/run-take.c +++ b/ccan/tal/str/test/run-take.c @@ -7,7 +7,7 @@ int main(void) { char *parent, *c; - plan_tests(14); + plan_tests(11); parent = tal(NULL, char); ok1(parent); @@ -38,11 +38,5 @@ int main(void) tal_free(parent); ok1(!taken_any()); - /* NULL pass-through. */ - c = NULL; - ok1(tal_strdup(NULL, take(c)) == NULL); - ok1(tal_strndup(NULL, take(c), 5) == NULL); - ok1(tal_fmt(NULL, take(c), 0) == NULL); - return exit_status(); } diff --git a/ccan/tal/str/test/run.c b/ccan/tal/str/test/run.c index 626434c3..6c50373f 100644 --- a/ccan/tal/str/test/run.c +++ b/ccan/tal/str/test/run.c @@ -15,7 +15,7 @@ int main(void) char **split, *str; void *ctx; - plan_tests(78); + plan_tests(72); split = tal_strsplit(NULL, "hello world", " ", STR_EMPTY_OK); ok1(!strcmp(split[0], "hello")); ok1(!strcmp(split[1], "")); @@ -71,9 +71,6 @@ int main(void) tal_free(ctx); ctx = tal_strdup(NULL, "context"); - /* Pass through NULLs from take. */ - ok1(tal_strsplit(NULL, take(NULL), " ", STR_EMPTY_OK) == NULL); - ok1(tal_strsplit(NULL, "foo", take(NULL), STR_EMPTY_OK) == NULL); /* tal_strsplit take string. It reallocs it to same size, but * that sometimes causes a move, so we can't directly check @@ -120,12 +117,6 @@ int main(void) /* temp allocs are gone... */ ok1(no_children(ctx)); - /* tal_strjoin passthrough taken NULLs OK. */ - ok1(tal_strjoin(ctx, take(NULL), "", STR_TRAIL) == NULL); - ok1(tal_strjoin(ctx, take(NULL), "", STR_NO_TRAIL) == NULL); - ok1(tal_strjoin(ctx, split, take(NULL), STR_TRAIL) == NULL); - ok1(tal_strjoin(ctx, split, take(NULL), STR_NO_TRAIL) == NULL); - /* tal_strjoin take strings[] */ split = tal_strsplit(ctx, "hello world", " ", STR_EMPTY_OK); str = tal_strjoin(ctx, take(split), " there ", STR_NO_TRAIL); -- 2.47.3