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

[GSoC][PATCH v2 2/4] t: move tests from reftable/stack_test.c to the new unit test

From
CPChandra Pratap <chandrapratap3519@gmail.com>
Date
May 29, 2024, 06:55 UTC
Message-ID
<20240529070341.4248-3-chandrapratap3519@gmail.com>
In-Reply-To
<20240529070341.4248-1-chandrapratap3519@gmail.com>

parse_names() and names_equal() are functions defined in reftable/basics.{c, h}. Move the tests for these functions from reftable/stack_test.c to the newly ported test.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
---
 reftable/stack_test.c            | 25 -------------------------
 t/unit-tests/t-reftable-basics.c | 25 ++++++++++++++++++++++---
 2 files changed, 22 insertions(+), 28 deletions(-)
diff --git a/reftable/stack_test.c b/reftable/stack_test.c
index 7889f818d1..6f6af11e53 100644
--- a/reftable/stack_test.c
+++ b/reftable/stack_test.c
@@ -102,29 +102,6 @@ static void test_read_file(void)
 	(void) remove(fn);
 }
 
-static void test_parse_names(void)
-{
-	char buf[] = "line\n";
-	char **names = NULL;
-	parse_names(buf, strlen(buf), &names);
-
-	EXPECT(NULL != names[0]);
-	EXPECT(0 == strcmp(names[0], "line"));
-	EXPECT(NULL == names[1]);
-	free_names(names);
-}
-
-static void test_names_equal(void)
-{
-	char *a[] = { "a", "b", "c", NULL };
-	char *b[] = { "a", "b", "d", NULL };
-	char *c[] = { "a", "b", NULL };
-
-	EXPECT(names_equal(a, a));
-	EXPECT(!names_equal(a, b));
-	EXPECT(!names_equal(a, c));
-}
-
 static int write_test_ref(struct reftable_writer *wr, void *arg)
 {
 	struct reftable_ref_record *ref = arg;
@@ -1048,8 +1025,6 @@ static void test_reftable_stack_compaction_concurrent_clean(void)
 int stack_test_main(int argc, const char *argv[])
 {
 	RUN_TEST(test_empty_add);
-	RUN_TEST(test_names_equal);
-	RUN_TEST(test_parse_names);
 	RUN_TEST(test_read_file);
 	RUN_TEST(test_reflog_expire);
 	RUN_TEST(test_reftable_stack_add);
diff --git a/t/unit-tests/t-reftable-basics.c b/t/unit-tests/t-reftable-basics.c
index 99e6c89120..55fcff12d9 100644
--- a/t/unit-tests/t-reftable-basics.c
+++ b/t/unit-tests/t-reftable-basics.c
@@ -58,14 +58,32 @@ static void test_names_length(void)
 	check_int(names_length(a), ==, 2);
 }
 
+static void test_names_equal(void)
+{
+	char *a[] = { "a", "b", "c", NULL };
+	char *b[] = { "a", "b", "d", NULL };
+	char *c[] = { "a", "b", NULL };
+
+	check(names_equal(a, a));
+	check(!names_equal(a, b));
+	check(!names_equal(a, c));
+}
+
 static void test_parse_names_normal(void)
 {
-	char in[] = "a\nb\n";
+	char in1[] = "line\n";
+	char in2[] = "a\nb\nc";
 	char **out = NULL;
-	parse_names(in, strlen(in), &out);
+	parse_names(in1, strlen(in1), &out);
+	check_str(out[0], "line");
+	check(!out[1]);
+	free_names(out);
+
+	parse_names(in2, strlen(in2), &out);
 	check_str(out[0], "a");
 	check_str(out[1], "b");
-	check(!out[2]);
+	check_str(out[2], "c");
+	check(!out[3]);
 	free_names(out);
 }
 
@@ -97,6 +115,7 @@ int cmd_main(int argc, const char *argv[])
 	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");
+	TEST(test_names_equal(), "names_equal compares NULL-terminated string arrays");
 
 	return test_done();
 }
-- 
2.45.GIT
Previous: Chandra PratapNext: Chandra Pratap
Message 3 of 18 in “t: port reftable/basics_test.c to the unit testing”
  1. Chandra PratapMay 29, 2024
  2. [GSoC][PATCH v2 1/4] t: move reftable/basics_test.c to the unit testing frameworkChandra Pratap, May 29, 2024
  3. [GSoC][PATCH v2 2/4] t: move tests from reftable/stack_test.c to the new unit testChandra Pratap, May 29, 2024
  4. [GSoC][PATCH v2 3/4] t: move tests from reftable/record_test.c to the new unit testChandra Pratap, May 29, 2024
  5. Patrick SteinhardtMay 29, 2024
  6. Junio C HamanoMay 29, 2024
  7. [GSoC][PATCH v2 4/4] t: add test for put_be16() and improve test-case for parse_names()Chandra Pratap, May 29, 2024
  8. Patrick SteinhardtMay 29, 2024
  9. Patrick SteinhardtMay 29, 2024
  10. [GSoC][PATCH v3 0/4] t: port reftable/basics_test.c to the unit testingChandra Pratap, May 29, 2024
  11. [GSoC][PATCH v3 1/5] t: move reftable/basics_test.c to the unit testing frameworkChandra Pratap, May 29, 2024
  12. [GSoC][PATCH v3 2/5] t: move tests from reftable/stack_test.c to the new unit testChandra Pratap, May 29, 2024
  13. [GSoC][PATCH v3 3/5] t: move tests from reftable/record_test.c to the new unit testChandra Pratap, May 29, 2024
  14. [GSoC][PATCH v3 4/5] t: add test for put_be16()Chandra Pratap, May 29, 2024
  15. [GSoC][PATCH v3 5/5] t: improve the test-case for parse_names()Chandra Pratap, May 29, 2024
  16. Patrick SteinhardtMay 30, 2024
  17. Christian CouderMay 30, 2024
  18. Junio C HamanoMay 30, 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.