aboutsummaryrefslogtreecommitdiffstats
path: root/t/unit-tests/t-strvec.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-09-18 18:02:05 -0700
committerJunio C Hamano <gitster@pobox.com>2024-09-18 18:02:05 -0700
commit5d55832f5cf914d583881cdb6f7b76b1793e2b16 (patch)
tree665698b7e6c23568a0f081469c2f990973abbed6 /t/unit-tests/t-strvec.c
parent3fb745257b30a643ee78c9a7c52ab107c82e4745 (diff)
parentc3de556a841f132832f742d1c4d3a2618ee3b355 (diff)
downloadgit-5d55832f5cf914d583881cdb6f7b76b1793e2b16.tar.gz
Merge branch 'ps/clar-unit-test'
Import clar unit tests framework libgit2 folks invented for our use. * ps/clar-unit-test: Makefile: rename clar-related variables to avoid confusion clar: add CMake support t/unit-tests: convert ctype tests to use clar t/unit-tests: convert strvec tests to use clar t/unit-tests: implement test driver Makefile: wire up the clar unit testing framework Makefile: do not use sparse on third-party sources Makefile: make hdr-check depend on generated headers Makefile: fix sparse dependency on GENERATED_H clar: stop including `shellapi.h` unnecessarily clar(win32): avoid compile error due to unused `fs_copy()` clar: avoid compile error with mingw-w64 t/clar: fix compatibility with NonStop t: import the clar unit testing framework t: do not pass GIT_TEST_OPTS to unit tests with prove
Diffstat (limited to 't/unit-tests/t-strvec.c')
-rw-r--r--t/unit-tests/t-strvec.c211
1 files changed, 0 insertions, 211 deletions
diff --git a/t/unit-tests/t-strvec.c b/t/unit-tests/t-strvec.c
deleted file mode 100644
index 5c844cf0c9..0000000000
--- a/t/unit-tests/t-strvec.c
+++ /dev/null
@@ -1,211 +0,0 @@
-#include "test-lib.h"
-#include "strbuf.h"
-#include "strvec.h"
-
-#define check_strvec(vec, ...) \
- do { \
- const char *expect[] = { __VA_ARGS__ }; \
- if (check_uint(ARRAY_SIZE(expect), >, 0) && \
- check_pointer_eq(expect[ARRAY_SIZE(expect) - 1], NULL) && \
- check_uint((vec)->nr, ==, ARRAY_SIZE(expect) - 1) && \
- check_uint((vec)->nr, <=, (vec)->alloc)) { \
- for (size_t i = 0; i < ARRAY_SIZE(expect); i++) { \
- if (!check_str((vec)->v[i], expect[i])) { \
- test_msg(" i: %"PRIuMAX, \
- (uintmax_t)i); \
- break; \
- } \
- } \
- } \
- } while (0)
-
-int cmd_main(int argc UNUSED, const char **argv UNUSED)
-{
- if_test ("static initialization") {
- struct strvec vec = STRVEC_INIT;
- check_pointer_eq(vec.v, empty_strvec);
- check_uint(vec.nr, ==, 0);
- check_uint(vec.alloc, ==, 0);
- }
-
- if_test ("dynamic initialization") {
- struct strvec vec;
- strvec_init(&vec);
- check_pointer_eq(vec.v, empty_strvec);
- check_uint(vec.nr, ==, 0);
- check_uint(vec.alloc, ==, 0);
- }
-
- if_test ("clear") {
- struct strvec vec = STRVEC_INIT;
- strvec_push(&vec, "foo");
- strvec_clear(&vec);
- check_pointer_eq(vec.v, empty_strvec);
- check_uint(vec.nr, ==, 0);
- check_uint(vec.alloc, ==, 0);
- }
-
- if_test ("push") {
- struct strvec vec = STRVEC_INIT;
-
- strvec_push(&vec, "foo");
- check_strvec(&vec, "foo", NULL);
-
- strvec_push(&vec, "bar");
- check_strvec(&vec, "foo", "bar", NULL);
-
- strvec_clear(&vec);
- }
-
- if_test ("pushf") {
- struct strvec vec = STRVEC_INIT;
- strvec_pushf(&vec, "foo: %d", 1);
- check_strvec(&vec, "foo: 1", NULL);
- strvec_clear(&vec);
- }
-
- if_test ("pushl") {
- struct strvec vec = STRVEC_INIT;
- strvec_pushl(&vec, "foo", "bar", "baz", NULL);
- check_strvec(&vec, "foo", "bar", "baz", NULL);
- strvec_clear(&vec);
- }
-
- if_test ("pushv") {
- const char *strings[] = {
- "foo", "bar", "baz", NULL,
- };
- struct strvec vec = STRVEC_INIT;
-
- strvec_pushv(&vec, strings);
- check_strvec(&vec, "foo", "bar", "baz", NULL);
-
- strvec_clear(&vec);
- }
-
- if_test ("replace at head") {
- struct strvec vec = STRVEC_INIT;
- strvec_pushl(&vec, "foo", "bar", "baz", NULL);
- strvec_replace(&vec, 0, "replaced");
- check_strvec(&vec, "replaced", "bar", "baz", NULL);
- strvec_clear(&vec);
- }
-
- if_test ("replace at tail") {
- struct strvec vec = STRVEC_INIT;
- strvec_pushl(&vec, "foo", "bar", "baz", NULL);
- strvec_replace(&vec, 2, "replaced");
- check_strvec(&vec, "foo", "bar", "replaced", NULL);
- strvec_clear(&vec);
- }
-
- if_test ("replace in between") {
- struct strvec vec = STRVEC_INIT;
- strvec_pushl(&vec, "foo", "bar", "baz", NULL);
- strvec_replace(&vec, 1, "replaced");
- check_strvec(&vec, "foo", "replaced", "baz", NULL);
- strvec_clear(&vec);
- }
-
- if_test ("replace with substring") {
- struct strvec vec = STRVEC_INIT;
- strvec_pushl(&vec, "foo", NULL);
- strvec_replace(&vec, 0, vec.v[0] + 1);
- check_strvec(&vec, "oo", NULL);
- strvec_clear(&vec);
- }
-
- if_test ("remove at head") {
- struct strvec vec = STRVEC_INIT;
- strvec_pushl(&vec, "foo", "bar", "baz", NULL);
- strvec_remove(&vec, 0);
- check_strvec(&vec, "bar", "baz", NULL);
- strvec_clear(&vec);
- }
-
- if_test ("remove at tail") {
- struct strvec vec = STRVEC_INIT;
- strvec_pushl(&vec, "foo", "bar", "baz", NULL);
- strvec_remove(&vec, 2);
- check_strvec(&vec, "foo", "bar", NULL);
- strvec_clear(&vec);
- }
-
- if_test ("remove in between") {
- struct strvec vec = STRVEC_INIT;
- strvec_pushl(&vec, "foo", "bar", "baz", NULL);
- strvec_remove(&vec, 1);
- check_strvec(&vec, "foo", "baz", NULL);
- strvec_clear(&vec);
- }
-
- if_test ("pop with empty array") {
- struct strvec vec = STRVEC_INIT;
- strvec_pop(&vec);
- check_strvec(&vec, NULL);
- strvec_clear(&vec);
- }
-
- if_test ("pop with non-empty array") {
- struct strvec vec = STRVEC_INIT;
- strvec_pushl(&vec, "foo", "bar", "baz", NULL);
- strvec_pop(&vec);
- check_strvec(&vec, "foo", "bar", NULL);
- strvec_clear(&vec);
- }
-
- if_test ("split empty string") {
- struct strvec vec = STRVEC_INIT;
- strvec_split(&vec, "");
- check_strvec(&vec, NULL);
- strvec_clear(&vec);
- }
-
- if_test ("split single item") {
- struct strvec vec = STRVEC_INIT;
- strvec_split(&vec, "foo");
- check_strvec(&vec, "foo", NULL);
- strvec_clear(&vec);
- }
-
- if_test ("split multiple items") {
- struct strvec vec = STRVEC_INIT;
- strvec_split(&vec, "foo bar baz");
- check_strvec(&vec, "foo", "bar", "baz", NULL);
- strvec_clear(&vec);
- }
-
- if_test ("split whitespace only") {
- struct strvec vec = STRVEC_INIT;
- strvec_split(&vec, " \t\n");
- check_strvec(&vec, NULL);
- strvec_clear(&vec);
- }
-
- if_test ("split multiple consecutive whitespaces") {
- struct strvec vec = STRVEC_INIT;
- strvec_split(&vec, "foo\n\t bar");
- check_strvec(&vec, "foo", "bar", NULL);
- strvec_clear(&vec);
- }
-
- if_test ("detach") {
- struct strvec vec = STRVEC_INIT;
- const char **detached;
-
- strvec_push(&vec, "foo");
-
- detached = strvec_detach(&vec);
- check_str(detached[0], "foo");
- check_pointer_eq(detached[1], NULL);
-
- check_pointer_eq(vec.v, empty_strvec);
- check_uint(vec.nr, ==, 0);
- check_uint(vec.alloc, ==, 0);
-
- free((char *) detached[0]);
- free(detached);
- }
-
- return test_done();
-}