]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t: move reftable/pq_test.c to the unit testing framework
authorChandra Pratap <chandrapratap3519@gmail.com>
Thu, 1 Aug 2024 10:59:44 +0000 (16:29 +0530)
committerJunio C Hamano <gitster@pobox.com>
Thu, 1 Aug 2024 16:07:29 +0000 (09:07 -0700)
reftable/pq_test.c exercises a priority queue defined by
reftable/pq.{c, h}. Migrate reftable/pq_test.c to the unit testing
framework. Migration involves refactoring the tests to use the unit
testing framework instead of reftable's test framework, and
renaming the tests to align with unit-tests' standards.

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
reftable/reftable-tests.h
t/helper/test-reftable.c
t/unit-tests/t-reftable-pq.c [moved from reftable/pq_test.c with 61% similarity]

index d6479092a0b8df4933fe4944d11d03d206ef65b8..1ee83e98dc587493494fc27e6abc1739feeee306 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1340,6 +1340,7 @@ UNIT_TEST_PROGRAMS += t-oidmap
 UNIT_TEST_PROGRAMS += t-oidtree
 UNIT_TEST_PROGRAMS += t-prio-queue
 UNIT_TEST_PROGRAMS += t-reftable-basics
+UNIT_TEST_PROGRAMS += t-reftable-pq
 UNIT_TEST_PROGRAMS += t-reftable-record
 UNIT_TEST_PROGRAMS += t-strbuf
 UNIT_TEST_PROGRAMS += t-strcmp-offset
@@ -2681,7 +2682,6 @@ REFTABLE_OBJS += reftable/writer.o
 REFTABLE_TEST_OBJS += reftable/block_test.o
 REFTABLE_TEST_OBJS += reftable/dump.o
 REFTABLE_TEST_OBJS += reftable/merged_test.o
-REFTABLE_TEST_OBJS += reftable/pq_test.o
 REFTABLE_TEST_OBJS += reftable/readwrite_test.o
 REFTABLE_TEST_OBJS += reftable/stack_test.o
 REFTABLE_TEST_OBJS += reftable/test_framework.o
index 114cc3d0535809fb7d641ff7c0e6613261ebb9af..67283faf06c2f2fe89641fc45f7e716bb8140da3 100644 (file)
@@ -12,7 +12,6 @@ https://developers.google.com/open-source/licenses/bsd
 int basics_test_main(int argc, const char **argv);
 int block_test_main(int argc, const char **argv);
 int merged_test_main(int argc, const char **argv);
-int pq_test_main(int argc, const char **argv);
 int record_test_main(int argc, const char **argv);
 int readwrite_test_main(int argc, const char **argv);
 int stack_test_main(int argc, const char **argv);
index aa6538a8da3264a41d47031c6c4f9a350b8dfea8..b808ad3e128f6037d4e7ede449ebdca280080fc5 100644 (file)
@@ -7,7 +7,6 @@ int cmd__reftable(int argc, const char **argv)
        /* test from simple to complex. */
        block_test_main(argc, argv);
        tree_test_main(argc, argv);
-       pq_test_main(argc, argv);
        readwrite_test_main(argc, argv);
        merged_test_main(argc, argv);
        stack_test_main(argc, argv);
similarity index 61%
rename from reftable/pq_test.c
rename to t/unit-tests/t-reftable-pq.c
index b7d3c80cc7260298749800696e4a8bcc5be3284c..a78aba9e71f805646b121d79ce45c5d149ea4218 100644 (file)
@@ -6,35 +6,28 @@ 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 "constants.h"
-#include "pq.h"
-#include "record.h"
-#include "reftable-tests.h"
-#include "test_framework.h"
+#include "test-lib.h"
+#include "reftable/constants.h"
+#include "reftable/pq.h"
 
 void merged_iter_pqueue_check(struct merged_iter_pqueue pq)
 {
-       int i;
-       for (i = 1; i < pq.len; i++) {
-               int parent = (i - 1) / 2;
-
-               EXPECT(pq_less(&pq.heap[parent], &pq.heap[i]));
+       for (size_t i = 1; i < pq.len; i++) {
+               size_t parent = (i - 1) / 2;
+               check(pq_less(&pq.heap[parent], &pq.heap[i]));
        }
 }
 
-static void test_pq(void)
+static void t_pq(void)
 {
-       struct merged_iter_pqueue pq = { NULL };
+       struct merged_iter_pqueue pq = { 0 };
        struct reftable_record recs[54];
-       int N = ARRAY_SIZE(recs) - 1, i;
+       size_t N = ARRAY_SIZE(recs) - 1, i;
        char *last = NULL;
 
        for (i = 0; i < N; i++) {
                struct strbuf refname = STRBUF_INIT;
-               strbuf_addf(&refname, "%02d", i);
+               strbuf_addf(&refname, "%02"PRIuMAX, (uintmax_t)i);
 
                reftable_record_init(&recs[i], BLOCK_TYPE_REF);
                recs[i].u.ref.refname = strbuf_detach(&refname, NULL);
@@ -48,7 +41,6 @@ static void test_pq(void)
 
                merged_iter_pqueue_add(&pq, &e);
                merged_iter_pqueue_check(pq);
-
                i = (i * 7) % N;
        } while (i != 1);
 
@@ -56,9 +48,9 @@ static void test_pq(void)
                struct pq_entry e = merged_iter_pqueue_remove(&pq);
                merged_iter_pqueue_check(pq);
 
-               EXPECT(reftable_record_type(e.rec) == BLOCK_TYPE_REF);
+               check(reftable_record_type(e.rec) == BLOCK_TYPE_REF);
                if (last)
-                       EXPECT(strcmp(last, e.rec->u.ref.refname) < 0);
+                       check_int(strcmp(last, e.rec->u.ref.refname), <, 0);
                last = e.rec->u.ref.refname;
        }
 
@@ -67,8 +59,9 @@ static void test_pq(void)
        merged_iter_pqueue_release(&pq);
 }
 
-int pq_test_main(int argc, const char *argv[])
+int cmd_main(int argc, const char *argv[])
 {
-       RUN_TEST(test_pq);
-       return 0;
+       TEST(t_pq(), "pq works");
+
+       return test_done();
 }