]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t: move reftable/basics_test.c to the unit testing framework
authorChandra Pratap <chandrapratap3519@gmail.com>
Wed, 29 May 2024 16:59:27 +0000 (22:29 +0530)
committerJunio C Hamano <gitster@pobox.com>
Thu, 30 May 2024 14:30:10 +0000 (07:30 -0700)
reftable/basics_test.c exercise the functions defined in
reftable/basics.{c, h}. Migrate reftable/basics_test.c to the
unit testing framework. Migration involves refactoring the tests
to use the unit testing framework instead of reftable's test
framework.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Makefile
t/helper/test-reftable.c
t/unit-tests/t-reftable-basics.c [moved from reftable/basics_test.c with 65% similarity]

index 1e31acc72eca23274f6ca0b00347f5de12f3a4e6..1807e63e4194edb1eba75e8ad343ef54df177593 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1349,6 +1349,7 @@ THIRD_PARTY_SOURCES += sha1dc/%
 
 UNIT_TEST_PROGRAMS += t-basic
 UNIT_TEST_PROGRAMS += t-mem-pool
+UNIT_TEST_PROGRAMS += t-reftable-basics
 UNIT_TEST_PROGRAMS += t-strbuf
 UNIT_TEST_PROGRAMS += t-ctype
 UNIT_TEST_PROGRAMS += t-prio-queue
@@ -2662,7 +2663,6 @@ REFTABLE_OBJS += reftable/stack.o
 REFTABLE_OBJS += reftable/tree.o
 REFTABLE_OBJS += reftable/writer.o
 
-REFTABLE_TEST_OBJS += reftable/basics_test.o
 REFTABLE_TEST_OBJS += reftable/block_test.o
 REFTABLE_TEST_OBJS += reftable/dump.o
 REFTABLE_TEST_OBJS += reftable/merged_test.o
index 00237ef0d9e08fb9747010891b64d1d5ca421a29..b7d2cc1d996c7ebc2e955ec717524f151c68d2d0 100644 (file)
@@ -5,7 +5,6 @@
 int cmd__reftable(int argc, const char **argv)
 {
        /* test from simple to complex. */
-       basics_test_main(argc, argv);
        record_test_main(argc, argv);
        block_test_main(argc, argv);
        tree_test_main(argc, argv);
similarity index 65%
rename from reftable/basics_test.c
rename to t/unit-tests/t-reftable-basics.c
index 997c4d9e0113ba52fcaaaa423aabe08c511322af..99e6c891200ec5e9ca7e2e82288971dd1c9945bb 100644 (file)
@@ -6,11 +6,8 @@ license that can be found in the LICENSE file or at
 https://developers.google.com/open-source/licenses/bsd
 */
 
-#include "system.h"
-
-#include "basics.h"
-#include "test_framework.h"
-#include "reftable-tests.h"
+#include "test-lib.h"
+#include "reftable/basics.h"
 
 struct integer_needle_lesseq_args {
        int needle;
@@ -42,9 +39,8 @@ static void test_binsearch(void)
                {11, 5},
                {9000, 5},
        };
-       size_t i = 0;
 
-       for (i = 0; i < ARRAY_SIZE(testcases); i++) {
+       for (size_t i = 0; i < ARRAY_SIZE(testcases); i++) {
                struct integer_needle_lesseq_args args = {
                        .haystack = haystack,
                        .needle = testcases[i].needle,
@@ -52,14 +48,14 @@ static void test_binsearch(void)
                size_t idx;
 
                idx = binsearch(ARRAY_SIZE(haystack), &integer_needle_lesseq, &args);
-               EXPECT(idx == testcases[i].expected_idx);
+               check_int(idx, ==, testcases[i].expected_idx);
        }
 }
 
 static void test_names_length(void)
 {
        char *a[] = { "a", "b", NULL };
-       EXPECT(names_length(a) == 2);
+       check_int(names_length(a), ==, 2);
 }
 
 static void test_parse_names_normal(void)
@@ -67,9 +63,9 @@ static void test_parse_names_normal(void)
        char in[] = "a\nb\n";
        char **out = NULL;
        parse_names(in, strlen(in), &out);
-       EXPECT(!strcmp(out[0], "a"));
-       EXPECT(!strcmp(out[1], "b"));
-       EXPECT(!out[2]);
+       check_str(out[0], "a");
+       check_str(out[1], "b");
+       check(!out[2]);
        free_names(out);
 }
 
@@ -78,8 +74,8 @@ static void test_parse_names_drop_empty(void)
        char in[] = "a\n\n";
        char **out = NULL;
        parse_names(in, strlen(in), &out);
-       EXPECT(!strcmp(out[0], "a"));
-       EXPECT(!out[1]);
+       check_str(out[0], "a");
+       check(!out[1]);
        free_names(out);
 }
 
@@ -89,17 +85,18 @@ static void test_common_prefix(void)
        struct strbuf s2 = STRBUF_INIT;
        strbuf_addstr(&s1, "abcdef");
        strbuf_addstr(&s2, "abc");
-       EXPECT(common_prefix_size(&s1, &s2) == 3);
+       check_int(common_prefix_size(&s1, &s2), ==, 3);
        strbuf_release(&s1);
        strbuf_release(&s2);
 }
 
-int basics_test_main(int argc, const char *argv[])
+int cmd_main(int argc, const char *argv[])
 {
-       RUN_TEST(test_common_prefix);
-       RUN_TEST(test_parse_names_normal);
-       RUN_TEST(test_parse_names_drop_empty);
-       RUN_TEST(test_binsearch);
-       RUN_TEST(test_names_length);
-       return 0;
+       TEST(test_common_prefix(), "common_prefix_size works");
+       TEST(test_parse_names_normal(), "parse_names works for basic input");
+       TEST(test_parse_names_drop_empty(), "parse_names drops empty string");
+       TEST(test_binsearch(), "binary search with binsearch works");
+       TEST(test_names_length(), "names_length retuns size of a NULL-terminated string array");
+
+       return test_done();
 }