git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 3/7] t: move reftable/pq_test.c to the unit testing framework

From
CPChandra Pratap <chandrapratap3519@gmail.com>
Date
Jun 11, 2024, 08:19 UTC
Message-ID
<20240611083157.9876-4-chandrapratap3519@gmail.com>
In-Reply-To
<20240611083157.9876-1-chandrapratap3519@gmail.com>

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.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
---
 Makefile                                      |  2 +-
 t/helper/test-reftable.c                      |  1 -
 .../pq_test.c => t/unit-tests/t-reftable-pq.c | 37 ++++++++-----------
 3 files changed, 16 insertions(+), 24 deletions(-)
 rename reftable/pq_test.c => t/unit-tests/t-reftable-pq.c (62%)
diff --git a/Makefile b/Makefile
index 59d98ba688..1cabe4cc69 100644
--- a/Makefile
+++ b/Makefile
@@ -1336,6 +1336,7 @@ THIRD_PARTY_SOURCES += sha1dc/%
 UNIT_TEST_PROGRAMS += t-ctype
 UNIT_TEST_PROGRAMS += t-mem-pool
 UNIT_TEST_PROGRAMS += t-prio-queue
+UNIT_TEST_PROGRAMS += t-reftable-pq
 UNIT_TEST_PROGRAMS += t-strbuf
 UNIT_TEST_PROGRAMS += t-strcmp-offset
 UNIT_TEST_PROGRAMS += t-trailer
@@ -2675,7 +2676,6 @@ 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
-REFTABLE_TEST_OBJS += reftable/pq_test.o
 REFTABLE_TEST_OBJS += reftable/record_test.o
 REFTABLE_TEST_OBJS += reftable/readwrite_test.o
 REFTABLE_TEST_OBJS += reftable/stack_test.o
diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c
index bae731669c..86a2b0f91a 100644
--- a/t/helper/test-reftable.c
+++ b/t/helper/test-reftable.c
@@ -9,7 +9,6 @@ int cmd__reftable(int argc, const char **argv)
 	record_test_main(argc, argv);
 	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);
diff --git a/reftable/pq_test.c b/t/unit-tests/t-reftable-pq.c
similarity index 62%
rename from reftable/pq_test.c
rename to t/unit-tests/t-reftable-pq.c
index b7d3c80cc7..a47a9473f3 100644
--- a/reftable/pq_test.c
+++ b/t/unit-tests/t-reftable-pq.c
@@ -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)
 {
-	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(test_pq(), "pq works");
+
+	return test_done();
 }
-- 
2.45.2.404.g9eaef5822c
Previous: Patrick SteinhardtNext: Chandra Pratap
Message 27 of 78 in “t: port reftable/pq_test.c to the unit testing”
  1. Chandra PratapJun 6, 2024
  2. [GSoC][PATCH 1/6] reftable: clean up reftable/pq.cChandra Pratap, Jun 6, 2024
  3. Christian CouderJun 6, 2024
  4. Chandra PratapJun 6, 2024
  5. Christian CouderJun 6, 2024
  6. [GSoC][PATCH 2/6] t: move reftable/pq_test.c to the unit testing frameworkChandra Pratap, Jun 6, 2024
  7. Patrick SteinhardtJun 6, 2024
  8. [GSoC][PATCH 3/6] t-reftable-pq: make merged_iter_pqueue_check() staticChandra Pratap, Jun 6, 2024
  9. [GSoC][PATCH 4/6] t-reftable-pq: make merged_iter_pqueue_check() callable by referenceChandra Pratap, Jun 6, 2024
  10. Patrick SteinhardtJun 6, 2024
  11. [GSoC][PATCH 5/6] t-reftable-pq: add test for index based comparisonChandra Pratap, Jun 6, 2024
  12. Patrick SteinhardtJun 6, 2024
  13. [GSoC][PATCH 6/6] t-reftable-pq: add tests for merged_iter_pqueue_top()Chandra Pratap, Jun 6, 2024
  14. Patrick SteinhardtJun 6, 2024
  15. [GSoC][PATCH v2 0/6] t: port reftable/pq_test.c to the unit testingChandra Pratap, Jun 6, 2024
  16. [GSoC][PATCH v2 1/6] reftable: clean up reftable/pq.cChandra Pratap, Jun 6, 2024
  17. Patrick SteinhardtJun 10, 2024
  18. [GSoC][PATCH v2 2/6] t: move reftable/pq_test.c to the unit testing frameworkChandra Pratap, Jun 6, 2024
  19. [GSoC][PATCH v2 3/6] t-reftable-pq: make merged_iter_pqueue_check() staticChandra Pratap, Jun 6, 2024
  20. [GSoC][PATCH v2 4/6] t-reftable-pq: make merged_iter_pqueue_check() callable by referenceChandra Pratap, Jun 6, 2024
  21. [GSoC][PATCH v2 5/6] t-reftable-pq: add test for index based comparisonChandra Pratap, Jun 6, 2024
  22. [GSoC][PATCH v2 6/6] t-reftable-pq: add tests for merged_iter_pqueue_top()Chandra Pratap, Jun 6, 2024
  23. [GSoC][PATCH v3 0/7] t: port reftable/pq_test.c to the unit testing frameworkChandra Pratap, Jun 11, 2024
  24. 1/7 reftable: remove unncessary curly braces in reftable/pq.cChandra Pratap, Jun 11, 2024
  25. 2/7 reftable: change the type of array indices to 'size_t' in reftable/pq.cChandra Pratap, Jun 11, 2024
  26. Patrick SteinhardtJun 11, 2024
  27. 3/7 t: move reftable/pq_test.c to the unit testing frameworkChandra Pratap, Jun 11, 2024
  28. 4/7 t-reftable-pq: make merged_iter_pqueue_check() staticChandra Pratap, Jun 11, 2024
  29. 5/7 t-reftable-pq: make merged_iter_pqueue_check() callable by referenceChandra Pratap, Jun 11, 2024
  30. 6/7 t-reftable-pq: add test for index based comparisonChandra Pratap, Jun 11, 2024
  31. 7/7 t-reftable-pq: add tests for merged_iter_pqueue_top()Chandra Pratap, Jun 11, 2024
  32. [GSoC][PATCH v4 0/7] t: port reftable/pq_test.c to the unit testing frameworkChandra Pratap, Jun 14, 2024
  33. 1/7 reftable: remove unncessary curly braces in reftable/pq.cChandra Pratap, Jun 14, 2024
  34. 2/7 reftable: change the type of array indices to 'size_t' in reftable/pq.cChandra Pratap, Jun 14, 2024
  35. 3/7 t: move reftable/pq_test.c to the unit testing frameworkChandra Pratap, Jun 14, 2024
  36. 4/7 t-reftable-pq: make merged_iter_pqueue_check() staticChandra Pratap, Jun 14, 2024
  37. 5/7 t-reftable-pq: make merged_iter_pqueue_check() callable by referenceChandra Pratap, Jun 14, 2024
  38. 6/7 t-reftable-pq: add test for index based comparisonChandra Pratap, Jun 14, 2024
  39. 7/7 t-reftable-pq: add tests for merged_iter_pqueue_top()Chandra Pratap, Jun 14, 2024
  40. Junio C HamanoJun 14, 2024
  41. [GSoC][PATCH v5 0/7] t: port reftable/pq_test.c to the unit testing frameworkChandra Pratap, Jul 23, 2024
  42. 1/7 reftable: remove unncessary curly braces in reftable/pq.cChandra Pratap, Jul 23, 2024
  43. 2/7 reftable: change the type of array indices to 'size_t' in reftable/pq.cChandra Pratap, Jul 23, 2024
  44. 3/7 t: move reftable/pq_test.c to the unit testing frameworkChandra Pratap, Jul 23, 2024
  45. 4/7 t-reftable-pq: make merged_iter_pqueue_check() staticChandra Pratap, Jul 23, 2024
  46. 5/7 t-reftable-pq: make merged_iter_pqueue_check() callable by referenceChandra Pratap, Jul 23, 2024
  47. 6/7 t-reftable-pq: add test for index based comparisonChandra Pratap, Jul 23, 2024
  48. Patrick SteinhardtJul 24, 2024
  49. Junio C HamanoJul 24, 2024
  50. Patrick SteinhardtJul 25, 2024
  51. 7/7 t-reftable-pq: add tests for merged_iter_pqueue_top()Chandra Pratap, Jul 23, 2024
  52. Junio C HamanoJul 23, 2024
  53. Chandra PratapJul 24, 2024
  54. Christian CouderJul 24, 2024
  55. Chandra PratapJul 24, 2024
  56. Patrick SteinhardtJul 24, 2024
  57. Junio C HamanoJul 24, 2024
  58. [GSoC][PATCH v6 0/7] t: port reftable/pq_test.c to the unit testing frameworkChandra Pratap, Jul 25, 2024
  59. 1/7 reftable: remove unncessary curly braces in reftable/pq.cChandra Pratap, Jul 25, 2024
  60. Kristoffer HaugsbakkJul 25, 2024
  61. 2/7 reftable: change the type of array indices to 'size_t' in reftable/pq.cChandra Pratap, Jul 25, 2024
  62. 3/7 t: move reftable/pq_test.c to the unit testing frameworkChandra Pratap, Jul 25, 2024
  63. 4/7 t-reftable-pq: make merged_iter_pqueue_check() staticChandra Pratap, Jul 25, 2024
  64. 5/7 t-reftable-pq: make merged_iter_pqueue_check() callable by referenceChandra Pratap, Jul 25, 2024
  65. 6/7 t-reftable-pq: add test for index based comparisonChandra Pratap, Jul 25, 2024
  66. Patrick SteinhardtJul 30, 2024
  67. 7/7 t-reftable-pq: add tests for merged_iter_pqueue_top()Chandra Pratap, Jul 25, 2024
  68. Patrick SteinhardtJul 30, 2024
  69. [GSoC][PATCH v7 0/7] t: port reftable/pq_test.c to the unit testing frameworkChandra Pratap, Aug 1, 2024
  70. 1/7 reftable: remove unnecessary curly braces in reftable/pq.cChandra Pratap, Aug 1, 2024
  71. 2/7 reftable: change the type of array indices to 'size_t' in reftable/pq.cChandra Pratap, Aug 1, 2024
  72. 3/7 t: move reftable/pq_test.c to the unit testing frameworkChandra Pratap, Aug 1, 2024
  73. 4/7 t-reftable-pq: make merged_iter_pqueue_check() staticChandra Pratap, Aug 1, 2024
  74. 5/7 t-reftable-pq: make merged_iter_pqueue_check() callable by referenceChandra Pratap, Aug 1, 2024
  75. 6/7 t-reftable-pq: add test for index based comparisonChandra Pratap, Aug 1, 2024
  76. 7/7 t-reftable-pq: add tests for merged_iter_pqueue_top()Chandra Pratap, Aug 1, 2024
  77. Patrick SteinhardtAug 1, 2024
  78. Junio C HamanoAug 1, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.