]> git.ozlabs.org Git - ccan/commitdiff
tal/str: fix up test cases now take(NULL) is not passed through.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 13 Oct 2025 03:55:22 +0000 (14:25 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 13 Oct 2025 03:55:22 +0000 (14:25 +1030)
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 <rusty@rustcorp.com.au>
ccan/tal/str/test/run-string.c
ccan/tal/str/test/run-strreg.c
ccan/tal/str/test/run-take.c
ccan/tal/str/test/run.c

index 03d4eb51b9c061283a3a822977b909bacdacd0bf..a4f5f9b14f07e2e23af9cdb8f8058be283553fd0 100644 (file)
@@ -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();
index 55e244c61e7bba769326a331dee91622bcdca478..dab3b2a3e7151658c84f45546c8fa730ade9eb65 100644 (file)
@@ -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);
index edf173f81462e346f4c759c5b7ce732de6295a42..f12c8ea48ec2d91c3a617e6aadc3383a011cf0c1 100644 (file)
@@ -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();
 }
index 626434c31043382d63cb683dd0397c98f0426b08..6c50373fc595af57157aed3e7216475015d17ee6 100644 (file)
@@ -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);