From patchwork Wed May 29 16:59:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13679292 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DEA2C187335 for ; Wed, 29 May 2024 17:15:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717002954; cv=none; b=Fmbf6MSpqYcaqqyROoAxy7/JeSsR7o0HXZEGcMZeUJB2YyuApoRd/FmOoVopMAyWYAs0nEr47Fc26jIAihlWFwGdgB8c2BJAmUzY7J89enODw4ccZZ/85AnOiyUGpQwGLkw6t03ur6NASjOkEOpmHeRdiOidxMhX1rOiWgqjhX8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717002954; c=relaxed/simple; bh=/+aGEYVCOMt3BDaTUudEV0KrKN/9yegm/HoSNkEWai0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e7vQNx2N3vBvjnExxoQMFRSjbl2rG0ZOr/pPwHkPBK/P6y0DkqVdyK3rjkixoHVW85Ou6/3PI5Z/Br3QLF5A7e3yjFS1dxI2AXsX9k3CTBfrClk9nvdopZL18LvvwiIIJ87LS/6f3RiJ3rsgXlIDzvJq88HCvWJPvXdLVTUGFpY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kcOVMsMM; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kcOVMsMM" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1f4a52b94c3so20665595ad.3 for ; Wed, 29 May 2024 10:15:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717002949; x=1717607749; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tjntirJwz5N0hilgEj+W5M3lOc4eyCJjtBTq8ybzxHc=; b=kcOVMsMMfsORcsW2dfNEWCEN/S/Xof3VXVDa5UCijqH606+TOEYRNW/PGhGF7BB61g LZUoddfboUIqIshkyknh8esW+6lkcfht3DJSnTZ79kDmh/Z131sDUSC6h7DcyVOws+fW qr71E91oNqeByw4YZIJP9dRGqRSYgKAHsdL+1JuXLW3M+hSvxdSfGeEQbznn9weuVsaz j2LyLkbHf9dIfnGK16YsDjKWoCeAsTktJHB8NvFHvZSFEceFmQVKVw8Xh3Uet+09RF7r 0H0ghf+HmCIZGm7fleDcLlkS5sWuqgjzUkr8zVhrmZUedLyy/HokdPLtr/CiBfAZOOb6 Qqzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717002949; x=1717607749; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tjntirJwz5N0hilgEj+W5M3lOc4eyCJjtBTq8ybzxHc=; b=AjBzG2ufetqz8hKK5bJ++HhefYcLr7BzNE83DBjbzKV90L5ZRJhCoBgcfWZJOuGIFK 8u7NjhM93XxeVi3Ga6xdyTim6Ea/mxBcmqQ/6Pb6s9/Ghgg0tYTt+aaqsrV9kzuCJxPg Lq8jroOCXEmkkPyYCWSG6jr2tFAyzwXcxb5mucAftt8oUBjAhg1p+l4QTv8aXLCWczIB 4FkG5spR8bRiw10MLM5niVOMG/XGF+4sgGiqWIaGb2p4MuWxnHPm2XgIAYe0TOBStDuR IIWkbYwcxmKBmCIUSprcuwWsAL9KZyZkSbgV05lXK/qkwLxyHm9QQGuydwoyWKx+pBpg 9L3Q== X-Gm-Message-State: AOJu0YwJaPAxPyFtJCezONNbHofQOUexID7b7vjhzwe2U9Q2oBrabrKh NHRs/nx4ofyDTOLSlRvRpxgkJKNrwf7wwg1dA5xj1mGCv2Kbp70lMMXY2A9jk5s= X-Google-Smtp-Source: AGHT+IFMQyaeSmzHLovP2UoysRYK3U00MZb8SivXkmEMsYlaiE6nlYbpNJmnPuyhscYC6F64adnQFw== X-Received: by 2002:a17:902:f54c:b0:1f4:a008:29d3 with SMTP id d9443c01a7336-1f4a0082e01mr98008195ad.15.1717002948636; Wed, 29 May 2024 10:15:48 -0700 (PDT) Received: from Ubuntu.. ([171.51.169.75]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f4757734b6sm79720225ad.234.2024.05.29.10.15.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 10:15:48 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [GSoC][PATCH v3 1/5] t: move reftable/basics_test.c to the unit testing framework Date: Wed, 29 May 2024 22:29:27 +0530 Message-ID: <20240529171439.18271-2-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240529171439.18271-1-chandrapratap3519@gmail.com> References: <20240529070341.4248-1-chandrapratap3519@gmail.com> <20240529171439.18271-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- Makefile | 2 +- t/helper/test-reftable.c | 1 - .../unit-tests/t-reftable-basics.c | 41 +++++++++---------- 3 files changed, 20 insertions(+), 24 deletions(-) rename reftable/basics_test.c => t/unit-tests/t-reftable-basics.c (65%) diff --git a/Makefile b/Makefile index 8f4432ae57..36188ca256 100644 --- a/Makefile +++ b/Makefile @@ -1337,6 +1337,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-basics UNIT_TEST_PROGRAMS += t-strbuf UNIT_TEST_PROGRAMS += t-trailer UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS)) @@ -2671,7 +2672,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 diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c index bae731669c..9160bc5da6 100644 --- a/t/helper/test-reftable.c +++ b/t/helper/test-reftable.c @@ -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); diff --git a/reftable/basics_test.c b/t/unit-tests/t-reftable-basics.c similarity index 65% rename from reftable/basics_test.c rename to t/unit-tests/t-reftable-basics.c index 997c4d9e01..99e6c89120 100644 --- a/reftable/basics_test.c +++ b/t/unit-tests/t-reftable-basics.c @@ -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(); } From patchwork Wed May 29 16:59:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13679291 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38A84D27E for ; Wed, 29 May 2024 17:15:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717002953; cv=none; b=ixhnLTcRk+PiX9IojalR5VHY+EG7sat7Ue+p9oZ+BRJUoY2N0LZ7QaIW7aO3g7p+rEu34dNRZ3wYLv2ceJw6M5mgVZh8wfj3bqaxURoQgyDwr12SdI9QyQWGxIgHKZYDmGxIDpHdSKEmDPKikuAtiVpPCKiL/3uPqVY6lST8HvU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717002953; c=relaxed/simple; bh=xg3BzUGxdqlLQJCI2sza5JvZPdESVZ31Y6f7GLMd+4k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D4GArVEi+3KieoXtREtC+2DG1AiTILmtUFiTp5KfnQtAompf7AtwB7qL2pppVBo11kbWbFivwk+wqO3Ah5kiXh5tzpRCT+8AGrWAdqc3/WiVoYXE6kM/5y5/LcDRv2+0FWacUAfy+y67dAxo2bg3KB9u+xkQNWwHsxWf7z1yWI0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mLiE83tJ; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mLiE83tJ" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1f480624d04so19995735ad.2 for ; Wed, 29 May 2024 10:15:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717002951; x=1717607751; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wr8ozju04b/fENvmFIgkx7p6m+nNn/O94ghV0XkCMIc=; b=mLiE83tJHRZqJbu/t24a+m1GnsnQGbxMaGBubJ9a1+MiVSaxqC1yXfmDDCrc3sdlVN Ad9Aszb1iaNuZrq6XTBSAvpeWe7z2GTla9+w4tFE8ECpLsnf885bClXTTbCIEtp7Xb2k PgG7ib7g2qzT6gANfrFz3NPKMMJrlVbC6LXNx3o15BVgpSUnaVxnQc5gnhoYnP26/9I4 hgKf/CcfEx8s5Ma2Odf1zSHvr72Db7p78ZZ97w6ZR8gdOP1+5hW+3hxKhdIuXieQTxJv 33Ct+esGiZjuizj4D3q/j3uDkrKw50udCZPAz/JIIiMq+WaC+BecgqSAIMJAP44JFSQT bh4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717002951; x=1717607751; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wr8ozju04b/fENvmFIgkx7p6m+nNn/O94ghV0XkCMIc=; b=YVk+KJNr3jCayG2nnPqyw8Nufcl7S/X4WWYNj6b2NBxLInlE2Q+s9kUbsiNlNNMcg+ g/BxhGPjL+HzIcY3wM2AOPmbMLFd5PGBVx+QI8qrUkRWWehZvSdAUIhGwp4C4GzT+q3r O08OxeSavmc1GCyTe/jqMh4K43QkLID5h847c3vnIQHyNdMvqcVARhGU2RtrJwz+CWI3 i+vvcG/lXPAxfncMNjWZ87/ouk7l/fvSBJJUCs7iiBdIrnmPAshh9mNj/xh0MrcC1ms1 UaZabDEBKfydhRoNOy4lJ9GdIATaQACWt0DIQeNy9RdtY6Ci7wxvqEHkIN5cpEZ/4ecF mgJw== X-Gm-Message-State: AOJu0YzmlumJ6PT+ue/mPBe8pOPaDLd7fe0/e0vrPRCQWaxzKhzn1dh+ M7XvKRuKwGV94tpHI2Br5tkRC1ZKImglhbhnegn4/UrVceaxaCDdL/oxca3oHsY= X-Google-Smtp-Source: AGHT+IF9MnAeNDwTANzJeKmikO09RnmHk1aM9khyXjXvD3IiCj84gbxHEb5KPw6u2wKgofBD2C8s1g== X-Received: by 2002:a17:902:ce84:b0:1f4:a3a1:789d with SMTP id d9443c01a7336-1f4a3a17a19mr113775845ad.64.1717002951185; Wed, 29 May 2024 10:15:51 -0700 (PDT) Received: from Ubuntu.. ([171.51.169.75]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f4757734b6sm79720225ad.234.2024.05.29.10.15.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 10:15:50 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [GSoC][PATCH v3 2/5] t: move tests from reftable/stack_test.c to the new unit test Date: Wed, 29 May 2024 22:29:28 +0530 Message-ID: <20240529171439.18271-3-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240529171439.18271-1-chandrapratap3519@gmail.com> References: <20240529070341.4248-1-chandrapratap3519@gmail.com> <20240529171439.18271-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- 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(); } From patchwork Wed May 29 16:59:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13679293 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACA14187337 for ; Wed, 29 May 2024 17:15:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717002956; cv=none; b=TJCBefZ1+62J0ty9WMAo/CKxGk2i2abwg4LVL4AQTaTGJj1uFDRRQsN8xjblneGYfYTiDr8p0aP3NGs+/gfDQuX+zhcBe++xOJa7Z93cnB32B2038eDLz5POCgMeXg0bX9n+Jn7WycYArwi5brYLkkcvKT6dTEfGoE/PkXTdSEY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717002956; c=relaxed/simple; bh=imdnwdQUYDNWkCiEh4mYuhPwizZLaM7MOlyvKNKB1vw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G5tUk/SdQqBprjoqH096Jh+E7TXDcPgScuIAhPsFcmkehRfA4hul5yvz6po95ErcJ+pSvW+6Q+mP0TEPd6wAzV8M+pecBlhzc2EVgoXFqBGx4fRkpq0NeZkGR75FA5KZQXWxuN21sSjhH594cycVF3ExMOEwqP4nkzIqrWVEl0I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mpPl+V9Y; arc=none smtp.client-ip=209.85.215.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mpPl+V9Y" Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-681bee6bb13so156964a12.1 for ; Wed, 29 May 2024 10:15:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717002954; x=1717607754; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wJZL6qpmxYDLfog5CD0nPWSmmHVEn+XkBlmUnCocPwc=; b=mpPl+V9YL5zg98F/Txf6YmHBEOQoT08sdYyXHIP2CZiUNb5tpoFomlBK1A2ZtrJwXY tEatBFvGLxJdGl2D3+CfMA6qz6duRhPalvAIhyyGyRPkU2S8QqwZNYJSJUjN5WL3tgUy 4o9MPrxZ+CqpHl/lBmB2P+kbdMij3zP6nC7piHjpY46ixe5r6FT4QCc5AgEZvL15qvYI mdnm2r5OKfZsgDhYn8zr6J/0HMkMVp7mQNtmGCIACYdV8CxXcdDupl8pa66oVsbB9CJ2 7x9A0GVEPiXPcMlRzdrZFzYkXiiusPRYe9ENFHiqhavNKWpIgNL8lVBPTiOgsGIELYK6 7xtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717002954; x=1717607754; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wJZL6qpmxYDLfog5CD0nPWSmmHVEn+XkBlmUnCocPwc=; b=t0Phodh+frGRoqfmZhV+4fMN5X7Na3GUJmvaG/YG3J01kFXk2rHBKuchsi0ySQ+ai6 Q0mwLsmjKwh3wtcjEgb2Y0sKOqNd39tx55CNJs4Rp8JpMWECwN2AKP1UdQWnLH94nWet tpwet0mDlTvh3T00ofUMCymiM0IYo0MmUscZpbz5aV25XLaTPuHM7TJyLiAf8wh/sKGI UdtlezUW2IP9Xr9C/bxP2XURQHwX3I3RJn0cE+up6V0UhXrxssiKZzxbTF7k8oyMDwnq CZzK/VZSRcc5Q3s6lWUvMAO7G6wbGy/H904iFAZu2PggFG3BEdhkKx6NABgl6isHoQ4G jZTQ== X-Gm-Message-State: AOJu0Yyme3l3KwQk7Rlhi3Lnv5krIolODtQd2ZxeqJvy7W2K+BvMdHh2 IpH94bmSbRb/o5g4QTVounylqRSI4hp1OlXRfbGXliIJ8i1WBg1EZ2j0OxsPt+w= X-Google-Smtp-Source: AGHT+IHadA/2DERl0/vUgi/0tYx0Iee4DvKIe3MT0csbE0CkFDa+i4s+5iG4SCdwIsjYraDn0SLhGA== X-Received: by 2002:a17:902:d485:b0:1f3:1092:ab45 with SMTP id d9443c01a7336-1f4eaaebf79mr34448495ad.26.1717002953702; Wed, 29 May 2024 10:15:53 -0700 (PDT) Received: from Ubuntu.. ([171.51.169.75]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f4757734b6sm79720225ad.234.2024.05.29.10.15.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 10:15:53 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [GSoC][PATCH v3 3/5] t: move tests from reftable/record_test.c to the new unit test Date: Wed, 29 May 2024 22:29:29 +0530 Message-ID: <20240529171439.18271-4-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240529171439.18271-1-chandrapratap3519@gmail.com> References: <20240529070341.4248-1-chandrapratap3519@gmail.com> <20240529171439.18271-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 common_prefix_size(), get_be24() and put_be24() are functions defined in reftable/basics.{c, h}. Move the tests for these functions from reftable/record_test.c to the newly ported test. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- reftable/record_test.c | 37 ----------------------------- t/unit-tests/t-reftable-basics.c | 40 ++++++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 44 deletions(-) diff --git a/reftable/record_test.c b/reftable/record_test.c index c158ee79ff..58290bdba3 100644 --- a/reftable/record_test.c +++ b/reftable/record_test.c @@ -64,31 +64,6 @@ static void test_varint_roundtrip(void) } } -static void test_common_prefix(void) -{ - struct { - const char *a, *b; - int want; - } cases[] = { - { "abc", "ab", 2 }, - { "", "abc", 0 }, - { "abc", "abd", 2 }, - { "abc", "pqr", 0 }, - }; - - int i = 0; - for (i = 0; i < ARRAY_SIZE(cases); i++) { - struct strbuf a = STRBUF_INIT; - struct strbuf b = STRBUF_INIT; - strbuf_addstr(&a, cases[i].a); - strbuf_addstr(&b, cases[i].b); - EXPECT(common_prefix_size(&a, &b) == cases[i].want); - - strbuf_release(&a); - strbuf_release(&b); - } -} - static void set_hash(uint8_t *h, int j) { int i = 0; @@ -258,16 +233,6 @@ static void test_reftable_log_record_roundtrip(void) strbuf_release(&scratch); } -static void test_u24_roundtrip(void) -{ - uint32_t in = 0x112233; - uint8_t dest[3]; - uint32_t out; - put_be24(dest, in); - out = get_be24(dest); - EXPECT(in == out); -} - static void test_key_roundtrip(void) { uint8_t buffer[1024] = { 0 }; @@ -411,9 +376,7 @@ int record_test_main(int argc, const char *argv[]) RUN_TEST(test_reftable_ref_record_roundtrip); RUN_TEST(test_varint_roundtrip); RUN_TEST(test_key_roundtrip); - RUN_TEST(test_common_prefix); RUN_TEST(test_reftable_obj_record_roundtrip); RUN_TEST(test_reftable_index_record_roundtrip); - RUN_TEST(test_u24_roundtrip); return 0; } diff --git a/t/unit-tests/t-reftable-basics.c b/t/unit-tests/t-reftable-basics.c index 55fcff12d9..b02ca02040 100644 --- a/t/unit-tests/t-reftable-basics.c +++ b/t/unit-tests/t-reftable-basics.c @@ -99,13 +99,38 @@ static void test_parse_names_drop_empty(void) static void test_common_prefix(void) { - struct strbuf s1 = STRBUF_INIT; - struct strbuf s2 = STRBUF_INIT; - strbuf_addstr(&s1, "abcdef"); - strbuf_addstr(&s2, "abc"); - check_int(common_prefix_size(&s1, &s2), ==, 3); - strbuf_release(&s1); - strbuf_release(&s2); + struct strbuf a = STRBUF_INIT; + struct strbuf b = STRBUF_INIT; + struct { + const char *a, *b; + int want; + } cases[] = { + {"abcdef", "abc", 3}, + { "abc", "ab", 2 }, + { "", "abc", 0 }, + { "abc", "abd", 2 }, + { "abc", "pqr", 0 }, + }; + + for (size_t i = 0; i < ARRAY_SIZE(cases); i++) { + strbuf_addstr(&a, cases[i].a); + strbuf_addstr(&b, cases[i].b); + check_int(common_prefix_size(&a, &b), ==, cases[i].want); + strbuf_reset(&a); + strbuf_reset(&b); + } + strbuf_release(&a); + strbuf_release(&b); +} + +static void test_u24_roundtrip(void) +{ + uint32_t in = 0x112233; + uint8_t dest[3]; + uint32_t out; + put_be24(dest, in); + out = get_be24(dest); + check_int(in, ==, out); } int cmd_main(int argc, const char *argv[]) @@ -116,6 +141,7 @@ int cmd_main(int argc, const char *argv[]) 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"); + TEST(test_u24_roundtrip(), "put_be24 and get_be24 work"); return test_done(); } From patchwork Wed May 29 16:59:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13679294 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 616EA18735A for ; Wed, 29 May 2024 17:15:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717002958; cv=none; b=OCqOjmuyp7SO7Ou8Q+g3n6/MgtycB8PhIn2/3tM3ubm5Xg/d+xovKe72vrKpKqg0jvjFfZaPJ0ONY7Ac1zhC0PCYXIR5SHSIqr9PSePvS2cq70aFPPUjQsmmJoSsRg9YWFpAg/MTtUJqvhQPNx2ek1025aJHtZRmJ8vyT973iHU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717002958; c=relaxed/simple; bh=csLaUWzI2K/ecCG+2Ut3u9xalpjSiGE48Rooc7Ra9GQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kehJXyidiUIuBv6OaYZH9svHI59zyDjMFTTHgLau+vMu1gi3y7zGZEoz3dsJbuwasJE2xa4DdmT1KoY/9jahM3wIdzYI1d05bjIZ7/E/w/xF/0km4gY+J6T6rQZUeXEOfG9M+2AYrQpBbydP+r0sIMGhBGq2ikL3yWfGUOvv8HM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IgNgz1nM; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IgNgz1nM" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1f082d92864so17438605ad.1 for ; Wed, 29 May 2024 10:15:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717002956; x=1717607756; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1esfsk1a9qwBh9D8DxGv1vLbnu5VRmdjNnTBMedCCUE=; b=IgNgz1nM2hZDnPSGzpE/6Msu65R+dFqUtllfI2HhNuLJs/MJOgPoQO7OINluSIQ+se 08K99i79O1+tmUbpjySLEqpdOHf+J3Dm/gLxADh815grEjsGs6o+1r5qgg6n5MY4FPNw OlGxPydX+3Cg923FdhhNnRDINPi7vxhRTif7Ps6PpidNbhwnhu7wbmLmpVaNs+MGFdOE Zz9mdzD8+nURgkYIK8ZNxAad9A4WQXAKkd7VDgmOrhPIBw33XLLUGo0aNO4w39pE8f/3 VZJg1NnAU88OsSMWdyFzIogwraSmzgwUKVcz0nKHXTWhynRmnbepBbkfVH6tWG5L9sJC XpHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717002956; x=1717607756; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1esfsk1a9qwBh9D8DxGv1vLbnu5VRmdjNnTBMedCCUE=; b=UKlvKGwyDJn/HA0wBzieqJt088GtJVqzMMwD8ExP3nfHKKxtF858xZyCb1klwY4iW4 zXDknfVIYHCOTSTS7uTgPYWWoNb2RTYJ/fAzEzA3XSIhlzHRakCrHTjpNJoc/scnWiWC gOkTO7twzaiEMN05xQXHSMsQc0Cw2gojoFbwl+Hcc3J2CySXVi79uv4ZeVmCHMp2PB7y V5VCS8epZbVLYepK/SshaVsVdchNiklNwLRbLGktBKPDDN6kXaWsqN7J5mV8xYtgFeMe ZGTdRBf5oJ7lapBYEF34gfTnxxeYXrpmmOsJrWQ8quTeGKNTj/tHiPDFWscIKzTBqjGe fyPQ== X-Gm-Message-State: AOJu0YyGiItpHjTT0W8tzAn/BT2GcxyIQB/BVeQ3SL2lzPq9tEUZ4v/o iXiyPAdlXUfT5t8IltpYAIJsXpucsFyKVcZP9M6D4mQDkSZaL0ROSdFSdYDsWvE= X-Google-Smtp-Source: AGHT+IHlAVvyc3EQOrRlZUMu5ENx4SvewKFYlgS4hfTQMOtqxqf5ykQB/IxdIlHTksJNhHsuTP8Upw== X-Received: by 2002:a17:902:684f:b0:1e3:e246:2cd1 with SMTP id d9443c01a7336-1f4497e0a2amr146469285ad.62.1717002956157; Wed, 29 May 2024 10:15:56 -0700 (PDT) Received: from Ubuntu.. ([171.51.169.75]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f4757734b6sm79720225ad.234.2024.05.29.10.15.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 10:15:55 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [GSoC][PATCH v3 4/5] t: add test for put_be16() Date: Wed, 29 May 2024 22:29:30 +0530 Message-ID: <20240529171439.18271-5-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240529171439.18271-1-chandrapratap3519@gmail.com> References: <20240529070341.4248-1-chandrapratap3519@gmail.com> <20240529171439.18271-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 put_be16() is a function defined in reftable/basics.{c, h} for which there are no tests in the current setup. Add a test for the same. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-basics.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/t/unit-tests/t-reftable-basics.c b/t/unit-tests/t-reftable-basics.c index b02ca02040..3c08218257 100644 --- a/t/unit-tests/t-reftable-basics.c +++ b/t/unit-tests/t-reftable-basics.c @@ -133,6 +133,16 @@ static void test_u24_roundtrip(void) check_int(in, ==, out); } +static void test_u16_roundtrip(void) +{ + uint32_t in = 0xfef1; + uint8_t dest[3]; + uint32_t out; + put_be16(dest, in); + out = get_be16(dest); + check_int(in, ==, out); +} + int cmd_main(int argc, const char *argv[]) { TEST(test_common_prefix(), "common_prefix_size works"); @@ -142,6 +152,7 @@ int cmd_main(int argc, const char *argv[]) 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"); TEST(test_u24_roundtrip(), "put_be24 and get_be24 work"); + TEST(test_u16_roundtrip(), "put_be16 and get_be16 work"); return test_done(); } From patchwork Wed May 29 16:59:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13679295 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7F0219066F for ; Wed, 29 May 2024 17:15:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717002961; cv=none; b=lgkadi5/65cYv8pHjGPsFI0plemHe2lV/SumMHlNNWd0odeu1CO2CMREIhej8UfGfb8hUCpa97s4Itsd1aQwnXvlAQU8GXFn6YeRmnsX5HB1joAnbsUlEEcDkRpeTARdIlcmMUlQS9cTNtNeXMINnHpvmsmPHFwGwFAnVtBeEds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717002961; c=relaxed/simple; bh=fijzJDkuq8RIpqIOnXZkBl1yU6jFP9QouKhKuHe9jNo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d5RV9+gn35FVWHnczh+aNA3mV/IQOa6u5GZCu3GPOejlUJE30HHPH0BfIGhqYsXV5u8VK4MncgNrt83n0ahVWGOgtgjXCUX1W5XAtfL7PCCBf9aEsOlSKg20BHVNb4nIq93ouIA7FBXYwJ3M2as5CiZl+CDVsuIVrUgm+KgiBO0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nkV0Zppd; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nkV0Zppd" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1f32b1b5429so16635375ad.2 for ; Wed, 29 May 2024 10:15:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717002959; x=1717607759; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8WEdWttlzRRyVg20QgIAGZdIILyC7g5qVxk5PmFt3Bg=; b=nkV0Zppd6h9b2TmlOEOApeXKaCmx0qTPQ+DcQhWhbf2r6Lc4lD8jjNRg6ZxO5IBeez WNz2SFYOm5eiGNMgBaG1CPNK/E2m87WzU1PCL5N9iD9CnzwIQYCWtZ+l0FpZhum64Ox2 VyX4FDV9b50At5x246HY84+n1GsJ2+OXjUEuBVGJoYxNNgYXrmmQ5DXbLftl4s69b3YM NougR8eFDrkfs/MYpcVT9jU6IuX9knD07lnae7extABGiZvhwOLC60RWnFDDTH1mv3PX 1lS1/UsWT2Hsx4MsYFrFw5oIULlDoO9OqAOI9HoTxOOFH3RO6PIdOsWg0uZ/08tDpV4l MNrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717002959; x=1717607759; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8WEdWttlzRRyVg20QgIAGZdIILyC7g5qVxk5PmFt3Bg=; b=B1DtkyMOeX/Ga9FSR2yMaeVKGLA2ToMdlg5nujGH5JAMNQ8s2HaMsRJ0G216RxmS94 Qv/kH61XFbLNte+Fb8wQE2X8RViMRJ2rGQYkps2rlfO9SxnoVmRrgf8c5akTeFhO+i5q 5exxfdlWAnrq6cN2S2iqpmxFVgiyy96oYbuKJ1biy/ot9quBOg8uiRAfHhOvWGd5kulO /qh/MiustngJ8iJELBWi379quJ08XE3IhsXd2J7X2LZXyhVuLcYLZYdDcP+Zv3UTh+ah EAMYt8+uPI5vWIfIEEwJMWTwAfkxcEvxiIniFf+/puJOsnymcRp/r6qd04aq+qOtL5gW e+tQ== X-Gm-Message-State: AOJu0Yzrf4g7fUkl+mGM3NcMcPg14yl7ImT4SZIZxI20QoECyQ42JQrL UIGSB+F/1FbpikwuD0ToUFSbek0dPf+pNH/zsdr0/PIF2HQAEYL++s1h3GqSx1U= X-Google-Smtp-Source: AGHT+IHP9uYEyyBKm4gF3K5D1uX5qyW+8mQBDpY1isgb3I1R8hOozmCwE7H5R+s86PrPBvwIJK0ulg== X-Received: by 2002:a17:902:ecc6:b0:1f5:e6a0:c176 with SMTP id d9443c01a7336-1f5e6a0c42cmr19568765ad.26.1717002958670; Wed, 29 May 2024 10:15:58 -0700 (PDT) Received: from Ubuntu.. ([171.51.169.75]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f4757734b6sm79720225ad.234.2024.05.29.10.15.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 10:15:58 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [GSoC][PATCH v3 5/5] t: improve the test-case for parse_names() Date: Wed, 29 May 2024 22:29:31 +0530 Message-ID: <20240529171439.18271-6-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240529171439.18271-1-chandrapratap3519@gmail.com> References: <20240529070341.4248-1-chandrapratap3519@gmail.com> <20240529171439.18271-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In the existing test-case for parse_names(), the fact that empty lines should be ignored is not obvious because the empty line is immediately followed by end-of-string. This can be mistaken as the empty line getting replaced by NULL. Improve this by adding a non-empty line after the empty one to demonstrate the intended behavior. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-basics.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/t/unit-tests/t-reftable-basics.c b/t/unit-tests/t-reftable-basics.c index 3c08218257..529049af12 100644 --- a/t/unit-tests/t-reftable-basics.c +++ b/t/unit-tests/t-reftable-basics.c @@ -89,11 +89,13 @@ static void test_parse_names_normal(void) static void test_parse_names_drop_empty(void) { - char in[] = "a\n\n"; + char in[] = "a\n\nb\n"; char **out = NULL; parse_names(in, strlen(in), &out); check_str(out[0], "a"); - check(!out[1]); + /* simply '\n' should be dropped as empty string */ + check_str(out[1], "b"); + check(!out[2]); free_names(out); }