{"thread":{"id":"63055","subject":"[PATCH 0/2] t/unit-tests: convert unit-tests to use clar","startedAt":"2025-03-04T11:33:33Z","lastAt":"2025-03-04T17:59:15Z","messageCount":4,"participants":["Seyi Kuforiji","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"513525","messageId":"20250304113323.10564-1-kuforiji98@gmail.com","threadId":"63055","inReplyTo":null,"subject":"[PATCH 0/2] t/unit-tests: convert unit-tests to use clar","fromName":"Seyi Kuforiji","fromEmail":"kuforiji98@gmail.com","sentAt":"2025-03-04T11:33:21Z","receivedAt":"2025-03-04T11:33:33Z","isPatch":true,"sender":{"key":"kuforiji98@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94905626?v=4"},"body":"Hello,\n\nThis small patch series transitions a couple more of our existing unit\ntest files to the Clar testing framework. This change is part of our\nongoing effort to standardize our testing framework to enhance\nmaintainability.\n\nThanks\nSeyi\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Pillip Wood <phillip.wood@dunelm.org.uk>\nSigned-off-by: Seyi Kuforiji <kuforiji98@gmail.com>\n\nSeyi Kuforiji (2):\n  t/unit-tests: convert trailer test to use clar\n  t/unit-tests: convert urlmatch-normalization test to clar\n\n Makefile                                      |   4 +-\n t/meson.build                                 |   4 +-\n t/unit-tests/t-trailer.c                      | 317 -----------------\n t/unit-tests/u-trailer.c                      | 320 ++++++++++++++++++\n ...alization.c => u-urlmatch-normalization.c} |  60 +---\n 5 files changed, 342 insertions(+), 363 deletions(-)\n delete mode 100644 t/unit-tests/t-trailer.c\n create mode 100644 t/unit-tests/u-trailer.c\n rename t/unit-tests/{t-urlmatch-normalization.c => u-urlmatch-normalization.c} (84%)\n\n-- \n2.47.0.86.g15030f9556\n\n"},{"id":"513526","messageId":"20250304113323.10564-2-kuforiji98@gmail.com","threadId":"63055","inReplyTo":"20250304113323.10564-1-kuforiji98@gmail.com","subject":"[PATCH 1/2] t/unit-tests: convert trailer test to use clar","fromName":"Seyi Kuforiji","fromEmail":"kuforiji98@gmail.com","sentAt":"2025-03-04T11:33:22Z","receivedAt":"2025-03-04T11:33:37Z","isPatch":true,"sender":{"key":"kuforiji98@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94905626?v=4"},"body":"Adapt trailer test file to use clar testing framework by using clar\nassertions where necessary. Split test into individual test functions\nfor clarity and maintainability. Each test case now has its own\nfunction, making it easier to isolate failures and improve test\nreadability.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Phillip Wood <phillip.wood@dunelm.org.uk>\nSigned-off-by: Seyi Kuforiji <kuforiji98@gmail.com>\n---\n Makefile                 |   2 +-\n t/meson.build            |   2 +-\n t/unit-tests/t-trailer.c | 317 --------------------------------------\n t/unit-tests/u-trailer.c | 320 +++++++++++++++++++++++++++++++++++++++\n 4 files changed, 322 insertions(+), 319 deletions(-)\n delete mode 100644 t/unit-tests/t-trailer.c\n create mode 100644 t/unit-tests/u-trailer.c\n\ndiff --git a/Makefile b/Makefile\nindex a9b2de0692..9cb68aaa61 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1361,6 +1361,7 @@ CLAR_TEST_SUITES += u-reftable-tree\n CLAR_TEST_SUITES += u-strbuf\n CLAR_TEST_SUITES += u-strcmp-offset\n CLAR_TEST_SUITES += u-strvec\n+CLAR_TEST_SUITES += u-trailer\n CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)\n CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))\n CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o\n@@ -1377,7 +1378,6 @@ UNIT_TEST_PROGRAMS += t-reftable-reader\n UNIT_TEST_PROGRAMS += t-reftable-readwrite\n UNIT_TEST_PROGRAMS += t-reftable-record\n UNIT_TEST_PROGRAMS += t-reftable-stack\n-UNIT_TEST_PROGRAMS += t-trailer\n UNIT_TEST_PROGRAMS += t-urlmatch-normalization\n UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS))\n UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o\ndiff --git a/t/meson.build b/t/meson.build\nindex 25ce072707..560aa9a1f1 100644\n--- a/t/meson.build\n+++ b/t/meson.build\n@@ -9,6 +9,7 @@ clar_test_suites = [\n   'unit-tests/u-strbuf.c',\n   'unit-tests/u-strcmp-offset.c',\n   'unit-tests/u-strvec.c',\n+  'unit-tests/u-trailer.c',\n ]\n \n clar_sources = [\n@@ -59,7 +60,6 @@ unit_test_programs = [\n   'unit-tests/t-reftable-readwrite.c',\n   'unit-tests/t-reftable-record.c',\n   'unit-tests/t-reftable-stack.c',\n-  'unit-tests/t-trailer.c',\n   'unit-tests/t-urlmatch-normalization.c',\n ]\n \ndiff --git a/t/unit-tests/t-trailer.c b/t/unit-tests/t-trailer.c\ndeleted file mode 100644\nindex 184593e73d..0000000000\n--- a/t/unit-tests/t-trailer.c\n+++ /dev/null\n@@ -1,317 +0,0 @@\n-#define DISABLE_SIGN_COMPARE_WARNINGS\n-\n-#include \"test-lib.h\"\n-#include \"trailer.h\"\n-\n-struct contents {\n-\tconst char *raw;\n-\tconst char *key;\n-\tconst char *val;\n-};\n-\n-static void t_trailer_iterator(const char *msg, size_t num_expected,\n-\t\t\t       struct contents *contents)\n-{\n-\tstruct trailer_iterator iter;\n-\tsize_t i = 0;\n-\n-\ttrailer_iterator_init(&iter, msg);\n-\twhile (trailer_iterator_advance(&iter)) {\n-\t\tif (num_expected) {\n-\t\t\tcheck_str(iter.raw, contents[i].raw);\n-\t\t\tcheck_str(iter.key.buf, contents[i].key);\n-\t\t\tcheck_str(iter.val.buf, contents[i].val);\n-\t\t}\n-\t\ti++;\n-\t}\n-\ttrailer_iterator_release(&iter);\n-\n-\tcheck_uint(i, ==, num_expected);\n-}\n-\n-static void run_t_trailer_iterator(void)\n-{\n-\n-\tstatic struct test_cases {\n-\t\tconst char *name;\n-\t\tconst char *msg;\n-\t\tsize_t num_expected;\n-\t\tstruct contents contents[10];\n-\t} tc[] = {\n-\t\t{\n-\t\t\t\"empty input\",\n-\t\t\t\"\",\n-\t\t\t0,\n-\t\t\t{{0}},\n-\t\t},\n-\t\t{\n-\t\t\t\"no newline at beginning\",\n-\t\t\t\"Fixes: x\\n\"\n-\t\t\t\"Acked-by: x\\n\"\n-\t\t\t\"Reviewed-by: x\\n\",\n-\t\t\t0,\n-\t\t\t{{0}},\n-\t\t},\n-\t\t{\n-\t\t\t\"newline at beginning\",\n-\t\t\t\"\\n\"\n-\t\t\t\"Fixes: x\\n\"\n-\t\t\t\"Acked-by: x\\n\"\n-\t\t\t\"Reviewed-by: x\\n\",\n-\t\t\t3,\n-\t\t\t{\n-\t\t\t\t{\n-\t\t\t\t\t.raw = \"Fixes: x\\n\",\n-\t\t\t\t\t.key = \"Fixes\",\n-\t\t\t\t\t.val = \"x\",\n-\t\t\t\t},\n-\t\t\t\t{\n-\t\t\t\t\t.raw = \"Acked-by: x\\n\",\n-\t\t\t\t\t.key = \"Acked-by\",\n-\t\t\t\t\t.val = \"x\",\n-\t\t\t\t},\n-\t\t\t\t{\n-\t\t\t\t\t.raw = \"Reviewed-by: x\\n\",\n-\t\t\t\t\t.key = \"Reviewed-by\",\n-\t\t\t\t\t.val = \"x\",\n-\t\t\t\t},\n-\t\t\t\t{\n-\t\t\t\t\t0\n-\t\t\t\t},\n-\t\t\t},\n-\t\t},\n-\t\t{\n-\t\t\t\"without body text\",\n-\t\t\t\"subject: foo bar\\n\"\n-\t\t\t\"\\n\"\n-\t\t\t\"Fixes: x\\n\"\n-\t\t\t\"Acked-by: x\\n\"\n-\t\t\t\"Reviewed-by: x\\n\",\n-\t\t\t3,\n-\t\t\t{\n-\t\t\t\t{\n-\t\t\t\t\t.raw = \"Fixes: x\\n\",\n-\t\t\t\t\t.key = \"Fixes\",\n-\t\t\t\t\t.val = \"x\",\n-\t\t\t\t},\n-\t\t\t\t{\n-\t\t\t\t\t.raw = \"Acked-by: x\\n\",\n-\t\t\t\t\t.key = \"Acked-by\",\n-\t\t\t\t\t.val = \"x\",\n-\t\t\t\t},\n-\t\t\t\t{\n-\t\t\t\t\t.raw = \"Reviewed-by: x\\n\",\n-\t\t\t\t\t.key = \"Reviewed-by\",\n-\t\t\t\t\t.val = \"x\",\n-\t\t\t\t},\n-\t\t\t\t{\n-\t\t\t\t\t0\n-\t\t\t\t},\n-\t\t\t},\n-\t\t},\n-\t\t{\n-\t\t\t\"with body text, without divider\",\n-\t\t\t\"my subject\\n\"\n-\t\t\t\"\\n\"\n-\t\t\t\"my body which is long\\n\"\n-\t\t\t\"and contains some special\\n\"\n-\t\t\t\"chars like : = ? !\\n\"\n-\t\t\t\"hello\\n\"\n-\t\t\t\"\\n\"\n-\t\t\t\"Fixes: x\\n\"\n-\t\t\t\"Acked-by: x\\n\"\n-\t\t\t\"Reviewed-by: x\\n\"\n-\t\t\t\"Signed-off-by: x\\n\",\n-\t\t\t4,\n-\t\t\t{\n-\t\t\t\t{\n-\t\t\t\t\t.raw = \"Fixes: x\\n\",\n-\t\t\t\t\t.key = \"Fixes\",\n-\t\t\t\t\t.val = \"x\",\n-\t\t\t\t},\n-\t\t\t\t{\n-\t\t\t\t\t.raw = \"Acked-by: x\\n\",\n-\t\t\t\t\t.key = \"Acked-by\",\n-\t\t\t\t\t.val = \"x\",\n-\t\t\t\t},\n-\t\t\t\t{\n-\t\t\t\t\t.raw = \"Reviewed-by: x\\n\",\n-\t\t\t\t\t.key = \"Reviewed-by\",\n-\t\t\t\t\t.val = \"x\",\n-\t\t\t\t},\n-\t\t\t\t{\n-\t\t\t\t\t.raw = \"Signed-off-by: x\\n\",\n-\t\t\t\t\t.key = \"Signed-off-by\",\n-\t\t\t\t\t.val = \"x\",\n-\t\t\t\t},\n-\t\t\t\t{\n-\t\t\t\t\t0\n-\t\t\t\t},\n-\t\t\t},\n-\t\t},\n-\t\t{\n-\t\t\t\"with body text, without divider (second trailer block)\",\n-\t\t\t\"my subject\\n\"\n-\t\t\t\"\\n\"\n-\t\t\t\"my body which is long\\n\"\n-\t\t\t\"and contains some special\\n\"\n-\t\t\t\"chars like : = ? !\\n\"\n-\t\t\t\"hello\\n\"\n-\t\t\t\"\\n\"\n-\t\t\t\"Fixes: x\\n\"\n-\t\t\t\"Acked-by: x\\n\"\n-\t\t\t\"Reviewed-by: x\\n\"\n-\t\t\t\"Signed-off-by: x\\n\"\n-\t\t\t\"\\n\"\n-\t\t\t/*\n-\t\t\t * Because this is the last trailer block, it takes\n-\t\t\t * precedence over the first one encountered above.\n-\t\t\t */\n-\t\t\t\"Helped-by: x\\n\"\n-\t\t\t\"Signed-off-by: x\\n\",\n-\t\t\t2,\n-\t\t\t{\n-\t\t\t\t{\n-\t\t\t\t\t.raw = \"Helped-by: x\\n\",\n-\t\t\t\t\t.key = \"Helped-by\",\n-\t\t\t\t\t.val = \"x\",\n-\t\t\t\t},\n-\t\t\t\t{\n-\t\t\t\t\t.raw = \"Signed-off-by: x\\n\",\n-\t\t\t\t\t.key = \"Signed-off-by\",\n-\t\t\t\t\t.val = \"x\",\n-\t\t\t\t},\n-\t\t\t\t{\n-\t\t\t\t\t0\n-\t\t\t\t},\n-\t\t\t},\n-\t\t},\n-\t\t{\n-\t\t\t\"with body text, with divider\",\n-\t\t\t\"my subject\\n\"\n-\t\t\t\"\\n\"\n-\t\t\t\"my body which is long\\n\"\n-\t\t\t\"and contains some special\\n\"\n-\t\t\t\"chars like : = ? !\\n\"\n-\t\t\t\"hello\\n\"\n-\t\t\t\"\\n\"\n-\t\t\t\"---\\n\"\n-\t\t\t\"\\n\"\n-\t\t\t/*\n-\t\t\t * This trailer still counts because the iterator\n-\t\t\t * always ignores the divider.\n-\t\t\t */\n-\t\t\t\"Signed-off-by: x\\n\",\n-\t\t\t1,\n-\t\t\t{\n-\t\t\t\t{\n-\t\t\t\t\t.raw = \"Signed-off-by: x\\n\",\n-\t\t\t\t\t.key = \"Signed-off-by\",\n-\t\t\t\t\t.val = \"x\",\n-\t\t\t\t},\n-\t\t\t\t{\n-\t\t\t\t\t0\n-\t\t\t\t},\n-\t\t\t},\n-\t\t},\n-\t\t{\n-\t\t\t\"with non-trailer lines in trailer block\",\n-\t\t\t\"subject: foo bar\\n\"\n-\t\t\t\"\\n\"\n-\t\t\t/*\n-\t\t\t * Even though this trailer block has a non-trailer line\n-\t\t\t * in it, it's still a valid trailer block because it's\n-\t\t\t * at least 25% trailers and is Git-generated (see\n-\t\t\t * git_generated_prefixes[] in trailer.c).\n-\t\t\t */\n-\t\t\t\"not a trailer line\\n\"\n-\t\t\t\"not a trailer line\\n\"\n-\t\t\t\"not a trailer line\\n\"\n-\t\t\t\"Signed-off-by: x\\n\",\n-\t\t\t/*\n-\t\t\t * Even though there is only really 1 real \"trailer\"\n-\t\t\t * (Signed-off-by), we still have 4 trailer objects\n-\t\t\t * because we still want to iterate through the entire\n-\t\t\t * block.\n-\t\t\t */\n-\t\t\t4,\n-\t\t\t{\n-\t\t\t\t{\n-\t\t\t\t\t.raw = \"not a trailer line\\n\",\n-\t\t\t\t\t.key = \"not a trailer line\",\n-\t\t\t\t\t.val = \"\",\n-\t\t\t\t},\n-\t\t\t\t{\n-\t\t\t\t\t.raw = \"not a trailer line\\n\",\n-\t\t\t\t\t.key = \"not a trailer line\",\n-\t\t\t\t\t.val = \"\",\n-\t\t\t\t},\n-\t\t\t\t{\n-\t\t\t\t\t.raw = \"not a trailer line\\n\",\n-\t\t\t\t\t.key = \"not a trailer line\",\n-\t\t\t\t\t.val = \"\",\n-\t\t\t\t},\n-\t\t\t\t{\n-\t\t\t\t\t.raw = \"Signed-off-by: x\\n\",\n-\t\t\t\t\t.key = \"Signed-off-by\",\n-\t\t\t\t\t.val = \"x\",\n-\t\t\t\t},\n-\t\t\t\t{\n-\t\t\t\t\t0\n-\t\t\t\t},\n-\t\t\t},\n-\t\t},\n-\t\t{\n-\t\t\t\"with non-trailer lines (one too many) in trailer block\",\n-\t\t\t\"subject: foo bar\\n\"\n-\t\t\t\"\\n\"\n-\t\t\t/*\n-\t\t\t * This block has only 20% trailers, so it's below the\n-\t\t\t * 25% threshold.\n-\t\t\t */\n-\t\t\t\"not a trailer line\\n\"\n-\t\t\t\"not a trailer line\\n\"\n-\t\t\t\"not a trailer line\\n\"\n-\t\t\t\"not a trailer line\\n\"\n-\t\t\t\"Signed-off-by: x\\n\",\n-\t\t\t0,\n-\t\t\t{{0}},\n-\t\t},\n-\t\t{\n-\t\t\t\"with non-trailer lines (only 1) in trailer block, but no Git-generated trailers\",\n-\t\t\t\"subject: foo bar\\n\"\n-\t\t\t\"\\n\"\n-\t\t\t/*\n-\t\t\t * This block has only 1 non-trailer out of 10 (IOW, 90%\n-\t\t\t * trailers) but is not considered a trailer block\n-\t\t\t * because the 25% threshold only applies to cases where\n-\t\t\t * there was a Git-generated trailer.\n-\t\t\t */\n-\t\t\t\"Reviewed-by: x\\n\"\n-\t\t\t\"Reviewed-by: x\\n\"\n-\t\t\t\"Reviewed-by: x\\n\"\n-\t\t\t\"Helped-by: x\\n\"\n-\t\t\t\"Helped-by: x\\n\"\n-\t\t\t\"Helped-by: x\\n\"\n-\t\t\t\"Acked-by: x\\n\"\n-\t\t\t\"Acked-by: x\\n\"\n-\t\t\t\"Acked-by: x\\n\"\n-\t\t\t\"not a trailer line\\n\",\n-\t\t\t0,\n-\t\t\t{{0}},\n-\t\t},\n-\t};\n-\n-\tfor (int i = 0; i < sizeof(tc) / sizeof(tc[0]); i++) {\n-\t\tTEST(t_trailer_iterator(tc[i].msg,\n-\t\t\t\t\ttc[i].num_expected,\n-\t\t\t\t\ttc[i].contents),\n-\t\t     \"%s\", tc[i].name);\n-\t}\n-}\n-\n-int cmd_main(int argc UNUSED, const char **argv UNUSED)\n-{\n-\trun_t_trailer_iterator();\n-\treturn test_done();\n-}\ndiff --git a/t/unit-tests/u-trailer.c b/t/unit-tests/u-trailer.c\nnew file mode 100644\nindex 0000000000..3d60ea1603\n--- /dev/null\n+++ b/t/unit-tests/u-trailer.c\n@@ -0,0 +1,320 @@\n+#define DISABLE_SIGN_COMPARE_WARNINGS\n+\n+#include \"unit-test.h\"\n+#include \"trailer.h\"\n+\n+struct contents {\n+\tconst char *raw;\n+\tconst char *key;\n+\tconst char *val;\n+};\n+\n+static void t_trailer_iterator(const char *msg, size_t num_expected,\n+\t\t\t       struct contents *contents)\n+{\n+\tstruct trailer_iterator iter;\n+\tsize_t i = 0;\n+\n+\ttrailer_iterator_init(&iter, msg);\n+\twhile (trailer_iterator_advance(&iter)) {\n+\t\tif (num_expected) {\n+\t\t\tcl_assert_equal_s(iter.raw, contents[i].raw);\n+\t\t\tcl_assert_equal_s(iter.key.buf, contents[i].key);\n+\t\t\tcl_assert_equal_s(iter.val.buf, contents[i].val);\n+\t\t}\n+\t\ti++;\n+\t}\n+\ttrailer_iterator_release(&iter);\n+\n+\tcl_assert_equal_i(i, num_expected);\n+}\n+\n+void test_trailer__empty_input(void)\n+{\n+\tstruct contents expected_contents[] = { 0 };\n+\tt_trailer_iterator(\"\", 0, expected_contents);\n+}\n+\n+void test_trailer__no_newline_start(void)\n+{\n+\tstruct contents expected_contents[] = { 0 };\n+\n+\tt_trailer_iterator(\"Fixes: x\\n\"\n+\t\t\t   \"Acked-by: x\\n\"\n+\t\t\t   \"Reviewed-by: x\\n\",\n+\t\t\t   0,\n+\t\t\t   expected_contents);\n+}\n+\n+void test_trailer__newline_start(void)\n+{\n+\tstruct contents expected_contents[] = {\n+\t\t{\n+\t\t\t.raw = \"Fixes: x\\n\",\n+\t\t\t.key = \"Fixes\",\n+\t\t\t.val = \"x\",\n+\t\t},\n+\t\t{\n+\t\t\t.raw = \"Acked-by: x\\n\",\n+\t\t\t.key = \"Acked-by\",\n+\t\t\t.val = \"x\",\n+\t\t},\n+\t\t{\n+\t\t\t.raw = \"Reviewed-by: x\\n\",\n+\t\t\t.key = \"Reviewed-by\",\n+\t\t\t.val = \"x\",\n+\t\t},\n+\t\t{\n+\t\t\t0\n+\t\t},\n+\t};\n+\n+\tt_trailer_iterator(\"\\n\"\n+\t\t\t   \"Fixes: x\\n\"\n+\t\t\t   \"Acked-by: x\\n\"\n+\t\t\t   \"Reviewed-by: x\\n\",\n+\t\t\t   3,\n+\t\t\t   expected_contents);\n+}\n+\n+void test_trailer__no_body_text(void)\n+{\n+\tstruct contents expected_contents[] = {\n+\n+\t\t{\n+\t\t\t.raw = \"Fixes: x\\n\",\n+\t\t\t.key = \"Fixes\",\n+\t\t\t.val = \"x\",\n+\t\t},\n+\t\t{\n+\t\t\t.raw = \"Acked-by: x\\n\",\n+\t\t\t.key = \"Acked-by\",\n+\t\t\t.val = \"x\",\n+\t\t},\n+\t\t{\n+\t\t\t.raw = \"Reviewed-by: x\\n\",\n+\t\t\t.key = \"Reviewed-by\",\n+\t\t\t.val = \"x\",\n+\t\t},\n+\t\t{\n+\t\t\t0\n+\t\t},\n+\t};\n+\n+\tt_trailer_iterator(\"subject: foo bar\\n\"\n+\t\t\t   \"\\n\"\n+\t\t\t   \"Fixes: x\\n\"\n+\t\t\t   \"Acked-by: x\\n\"\n+\t\t\t   \"Reviewed-by: x\\n\",\n+\t\t\t   3,\n+\t\t\t   expected_contents);\n+}\n+\n+void test_trailer__body_text_no_divider(void)\n+{\n+\tstruct contents expected_contents[] = {\n+\t\t{\n+\t\t\t.raw = \"Fixes: x\\n\",\n+\t\t\t.key = \"Fixes\",\n+\t\t\t.val = \"x\",\n+\t\t},\n+\t\t{\n+\t\t\t.raw = \"Acked-by: x\\n\",\n+\t\t\t.key = \"Acked-by\",\n+\t\t\t.val = \"x\",\n+\t\t},\n+\t\t{\n+\t\t\t.raw = \"Reviewed-by: x\\n\",\n+\t\t\t.key = \"Reviewed-by\",\n+\t\t\t.val = \"x\",\n+\t\t},\n+\t\t{\n+\t\t\t.raw = \"Signed-off-by: x\\n\",\n+\t\t\t.key = \"Signed-off-by\",\n+\t\t\t.val = \"x\",\n+\t\t},\n+\t\t{\n+\t\t\t0\n+\t\t},\n+\t};\n+\n+\tt_trailer_iterator(\"my subject\\n\"\n+\t\t\t   \"\\n\"\n+\t\t\t   \"my body which is long\\n\"\n+\t\t\t   \"and contains some special\\n\"\n+\t\t\t   \"chars like : = ? !\\n\"\n+\t\t\t   \"hello\\n\"\n+\t\t\t   \"\\n\"\n+\t\t\t   \"Fixes: x\\n\"\n+\t\t\t   \"Acked-by: x\\n\"\n+\t\t\t   \"Reviewed-by: x\\n\"\n+\t\t\t   \"Signed-off-by: x\\n\",\n+\t\t\t   4,\n+\t\t\t   expected_contents);\n+}\n+\n+void test_trailer__body_no_divider_2nd_block(void)\n+{\n+\tstruct contents expected_contents[] = {\n+\t\t\t{\n+\t\t\t\t.raw = \"Helped-by: x\\n\",\n+\t\t\t\t.key = \"Helped-by\",\n+\t\t\t\t.val = \"x\",\n+\t\t\t},\n+\t\t\t{\n+\t\t\t\t.raw = \"Signed-off-by: x\\n\",\n+\t\t\t\t.key = \"Signed-off-by\",\n+\t\t\t\t.val = \"x\",\n+\t\t\t},\n+\t\t\t{\n+\t\t\t\t0\n+\t\t\t},\n+\t};\n+\n+\tt_trailer_iterator(\"my subject\\n\"\n+\t\t\t   \"\\n\"\n+\t\t\t   \"my body which is long\\n\"\n+\t\t\t   \"and contains some special\\n\"\n+\t\t\t   \"chars like : = ? !\\n\"\n+\t\t\t   \"hello\\n\"\n+\t\t\t   \"\\n\"\n+\t\t\t   \"Fixes: x\\n\"\n+\t\t\t   \"Acked-by: x\\n\"\n+\t\t\t   \"Reviewed-by: x\\n\"\n+\t\t\t   \"Signed-off-by: x\\n\"\n+\t\t\t   \"\\n\"\n+\t\t\t   /*\n+\t\t\t   * Because this is the last trailer block, it takes\n+\t\t\t   * precedence over the first one encountered above.\n+\t\t\t   */\n+\t\t\t   \"Helped-by: x\\n\"\n+\t\t\t   \"Signed-off-by: x\\n\",\n+\t\t\t   2,\n+\t\t\t   expected_contents);\n+}\n+\n+void test_trailer__body_and_divider(void)\n+{\n+\tstruct contents expected_contents[] = {\n+\t\t\t{\n+\t\t\t\t.raw = \"Signed-off-by: x\\n\",\n+\t\t\t\t.key = \"Signed-off-by\",\n+\t\t\t\t.val = \"x\",\n+\t\t\t},\n+\t\t\t{\n+\t\t\t\t0\n+\t\t\t},\n+\t};\n+\n+\tt_trailer_iterator(\"my subject\\n\"\n+\t\t\t   \"\\n\"\n+\t\t\t   \"my body which is long\\n\"\n+\t\t\t   \"and contains some special\\n\"\n+\t\t\t   \"chars like : = ? !\\n\"\n+\t\t\t   \"hello\\n\"\n+\t\t\t   \"\\n\"\n+\t\t\t   \"---\\n\"\n+\t\t\t   \"\\n\"\n+\t\t\t   /*\n+\t\t\t   * This trailer still counts because the iterator\n+\t\t\t   * always ignores the divider.\n+\t\t\t   */\n+\t\t\t   \"Signed-off-by: x\\n\",\n+\t\t\t   1,\n+\t\t\t   expected_contents);\n+}\n+\n+void test_trailer__non_trailer_in_block(void)\n+{\n+\tstruct contents expected_contents[] = {\n+\t\t{\n+\t\t\t.raw = \"not a trailer line\\n\",\n+\t\t\t.key = \"not a trailer line\",\n+\t\t\t.val = \"\",\n+\t\t},\n+\t\t{\n+\t\t\t.raw = \"not a trailer line\\n\",\n+\t\t\t.key = \"not a trailer line\",\n+\t\t\t.val = \"\",\n+\t\t},\n+\t\t{\n+\t\t\t.raw = \"not a trailer line\\n\",\n+\t\t\t.key = \"not a trailer line\",\n+\t\t\t.val = \"\",\n+\t\t},\n+\t\t{\n+\t\t\t.raw = \"Signed-off-by: x\\n\",\n+\t\t\t.key = \"Signed-off-by\",\n+\t\t\t.val = \"x\",\n+\t\t},\n+\t\t{\n+\t\t\t0\n+\t\t},\n+\t};\n+\n+\tt_trailer_iterator(\"subject: foo bar\\n\"\n+\t\t\t   \"\\n\"\n+\t\t\t   /*\n+\t\t\t   * Even though this trailer block has a non-trailer line\n+\t\t\t   * in it, it's still a valid trailer block because it's\n+\t\t\t   * at least 25% trailers and is Git-generated (see\n+\t\t\t   * git_generated_prefixes[] in trailer.c).\n+\t\t\t   */\n+\t\t\t   \"not a trailer line\\n\"\n+\t\t\t   \"not a trailer line\\n\"\n+\t\t\t   \"not a trailer line\\n\"\n+\t\t\t   \"Signed-off-by: x\\n\",\n+\t\t\t   /*\n+\t\t\t   * Even though there is only really 1 real \"trailer\"\n+\t\t\t   * (Signed-off-by), we still have 4 trailer objects\n+\t\t\t   * because we still want to iterate through the entire\n+\t\t\t   * block.\n+\t\t\t   */\n+\t\t\t   4,\n+\t\t\t   expected_contents);\n+}\n+\n+void test_trailer__too_many_non_trailers(void)\n+{\n+\tstruct contents expected_contents[] = { 0 };\n+\n+\tt_trailer_iterator(\"subject: foo bar\\n\"\n+\t\t\t   \"\\n\"\n+\t\t\t   /*\n+\t\t\t   * This block has only 20% trailers, so it's below the\n+\t\t\t   * 25% threshold.\n+\t\t\t   */\n+\t\t\t   \"not a trailer line\\n\"\n+\t\t\t   \"not a trailer line\\n\"\n+\t\t\t   \"not a trailer line\\n\"\n+\t\t\t   \"not a trailer line\\n\"\n+\t\t\t   \"Signed-off-by: x\\n\",\n+\t\t\t   0,\n+\t\t\t   expected_contents);\n+}\n+\n+void test_trailer__one_non_trailer_no_git_trailers(void)\n+{\n+\tstruct contents expected_contents[] = { 0 };\n+\n+\tt_trailer_iterator(\"subject: foo bar\\n\"\n+\t\t\t   \"\\n\"\n+\t\t\t   /*\n+\t\t\t   * This block has only 1 non-trailer out of 10 (IOW, 90%\n+\t\t\t   * trailers) but is not considered a trailer block\n+\t\t\t   * because the 25% threshold only applies to cases where\n+\t\t\t   * there was a Git-generated trailer.\n+\t\t\t   */\n+\t\t\t   \"Reviewed-by: x\\n\"\n+\t\t\t   \"Reviewed-by: x\\n\"\n+\t\t\t   \"Reviewed-by: x\\n\"\n+\t\t\t   \"Helped-by: x\\n\"\n+\t\t\t   \"Helped-by: x\\n\"\n+\t\t\t   \"Helped-by: x\\n\"\n+\t\t\t   \"Acked-by: x\\n\"\n+\t\t\t   \"Acked-by: x\\n\"\n+\t\t\t   \"Acked-by: x\\n\"\n+\t\t\t   \"not a trailer line\\n\",\n+\t\t\t   0,\n+\t\t\t   expected_contents);\n+}\n-- \n2.47.0.86.g15030f9556\n\n"},{"id":"513527","messageId":"20250304113323.10564-3-kuforiji98@gmail.com","threadId":"63055","inReplyTo":"20250304113323.10564-1-kuforiji98@gmail.com","subject":"[PATCH 2/2] t/unit-tests: convert urlmatch-normalization test to clar","fromName":"Seyi Kuforiji","fromEmail":"kuforiji98@gmail.com","sentAt":"2025-03-04T11:33:23Z","receivedAt":"2025-03-04T11:33:44Z","isPatch":true,"sender":{"key":"kuforiji98@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94905626?v=4"},"body":"Adapt urlmatch-normalization test file to use clar testing framework by\nusing clar assertions where necessary.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Phillip Wood <phillip.wood@dunelm.org.uk>\nSigned-off-by: Seyi Kuforiji <kuforiji98@gmail.com>\n---\n Makefile                                      |  2 +-\n t/meson.build                                 |  2 +-\n ...alization.c => u-urlmatch-normalization.c} | 60 ++++++-------------\n 3 files changed, 20 insertions(+), 44 deletions(-)\n rename t/unit-tests/{t-urlmatch-normalization.c => u-urlmatch-normalization.c} (84%)\n\ndiff --git a/Makefile b/Makefile\nindex 9cb68aaa61..a4787bff5d 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1362,6 +1362,7 @@ CLAR_TEST_SUITES += u-strbuf\n CLAR_TEST_SUITES += u-strcmp-offset\n CLAR_TEST_SUITES += u-strvec\n CLAR_TEST_SUITES += u-trailer\n+CLAR_TEST_SUITES += u-urlmatch-normalization\n CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)\n CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))\n CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o\n@@ -1378,7 +1379,6 @@ UNIT_TEST_PROGRAMS += t-reftable-reader\n UNIT_TEST_PROGRAMS += t-reftable-readwrite\n UNIT_TEST_PROGRAMS += t-reftable-record\n UNIT_TEST_PROGRAMS += t-reftable-stack\n-UNIT_TEST_PROGRAMS += t-urlmatch-normalization\n UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS))\n UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o\n UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o\ndiff --git a/t/meson.build b/t/meson.build\nindex 560aa9a1f1..e6ac23df11 100644\n--- a/t/meson.build\n+++ b/t/meson.build\n@@ -10,6 +10,7 @@ clar_test_suites = [\n   'unit-tests/u-strcmp-offset.c',\n   'unit-tests/u-strvec.c',\n   'unit-tests/u-trailer.c',\n+  'unit-tests/u-urlmatch-normalization.c',\n ]\n \n clar_sources = [\n@@ -60,7 +61,6 @@ unit_test_programs = [\n   'unit-tests/t-reftable-readwrite.c',\n   'unit-tests/t-reftable-record.c',\n   'unit-tests/t-reftable-stack.c',\n-  'unit-tests/t-urlmatch-normalization.c',\n ]\n \n foreach unit_test_program : unit_test_programs\ndiff --git a/t/unit-tests/t-urlmatch-normalization.c b/t/unit-tests/u-urlmatch-normalization.c\nsimilarity index 84%\nrename from t/unit-tests/t-urlmatch-normalization.c\nrename to t/unit-tests/u-urlmatch-normalization.c\nindex 1769c357b9..39f6e1ba26 100644\n--- a/t/unit-tests/t-urlmatch-normalization.c\n+++ b/t/unit-tests/u-urlmatch-normalization.c\n@@ -1,12 +1,11 @@\n-#include \"test-lib.h\"\n+#include \"unit-test.h\"\n #include \"urlmatch.h\"\n \n static void check_url_normalizable(const char *url, unsigned int normalizable)\n {\n \tchar *url_norm = url_normalize(url, NULL);\n \n-\tif (!check_int(normalizable, ==, url_norm ? 1 : 0))\n-\t\ttest_msg(\"input url: %s\", url);\n+\tcl_assert_equal_i(normalizable, url_norm ? 1 : 0);\n \tfree(url_norm);\n }\n \n@@ -14,8 +13,7 @@ static void check_normalized_url(const char *url, const char *expect)\n {\n \tchar *url_norm = url_normalize(url, NULL);\n \n-\tif (!check_str(url_norm, expect))\n-\t\ttest_msg(\"input url: %s\", url);\n+\tcl_assert_equal_s(url_norm, expect);\n \tfree(url_norm);\n }\n \n@@ -26,13 +24,9 @@ static void compare_normalized_urls(const char *url1, const char *url2,\n \tchar *url2_norm = url_normalize(url2, NULL);\n \n \tif (equal) {\n-\t\tif (!check_str(url1_norm, url2_norm))\n-\t\t\ttest_msg(\"input url1: %s\\n  input url2: %s\", url1,\n-\t\t\t\t url2);\n-\t} else if (!check_int(strcmp(url1_norm, url2_norm), !=, 0)) {\n-\t\ttest_msg(\" normalized url1: %s\\n   normalized url2: %s\\n\"\n-\t\t\t \"  input url1: %s\\n  input url2: %s\",\n-\t\t\t url1_norm, url2_norm, url1, url2);\n+\t\tcl_assert_equal_s(url1_norm, url2_norm);\n+\t} else {\n+\t\tcl_assert(strcmp(url1_norm, url2_norm) != 0);\n \t}\n \tfree(url1_norm);\n \tfree(url2_norm);\n@@ -43,14 +37,12 @@ static void check_normalized_url_length(const char *url, size_t len)\n \tstruct url_info info;\n \tchar *url_norm = url_normalize(url, &info);\n \n-\tif (!check_int(info.url_len, ==, len))\n-\t\ttest_msg(\"     input url: %s\\n  normalized url: %s\", url,\n-\t\t\t url_norm);\n+\tcl_assert_equal_i(info.url_len, len);\n \tfree(url_norm);\n }\n \n /* Note that only \"file:\" URLs should be allowed without a host */\n-static void t_url_scheme(void)\n+void test_urlmatch_normalization__scheme(void)\n {\n \tcheck_url_normalizable(\"\", 0);\n \tcheck_url_normalizable(\"_\", 0);\n@@ -73,7 +65,7 @@ static void t_url_scheme(void)\n \tcheck_normalized_url(\"AbCdeF://x.Y\", \"abcdef://x.y/\");\n }\n \n-static void t_url_authority(void)\n+void test_urlmatch_normalization__authority(void)\n {\n \tcheck_url_normalizable(\"scheme://user:pass@\", 0);\n \tcheck_url_normalizable(\"scheme://?\", 0);\n@@ -109,7 +101,7 @@ static void t_url_authority(void)\n \tcheck_url_normalizable(\"scheme://invalid....:[\", 0);\n }\n \n-static void t_url_port(void)\n+void test_urlmatch_normalization__port(void)\n {\n \tcheck_url_normalizable(\"xyz://q@some.host:\", 1);\n \tcheck_url_normalizable(\"xyz://q@some.host:456/\", 1);\n@@ -139,7 +131,7 @@ static void t_url_port(void)\n \tcheck_url_normalizable(\"xyz://[::1]:030f/\", 0);\n }\n \n-static void t_url_port_normalization(void)\n+void test_urlmatch_normalization__port_normalization(void)\n {\n \tcheck_normalized_url(\"http://x:800\", \"http://x:800/\");\n \tcheck_normalized_url(\"http://x:0800\", \"http://x:800/\");\n@@ -154,7 +146,7 @@ static void t_url_port_normalization(void)\n \tcheck_normalized_url(\"https://x:000000443\", \"https://x/\");\n }\n \n-static void t_url_general_escape(void)\n+void test_urlmatch_normalization__general_escape(void)\n {\n \tcheck_url_normalizable(\"http://x.y?%fg\", 0);\n \tcheck_normalized_url(\"X://W/%7e%41^%3a\", \"x://w/~A%5E%3A\");\n@@ -164,7 +156,7 @@ static void t_url_general_escape(void)\n \tcheck_normalized_url(\"X://W?!\", \"x://w/?!\");\n }\n \n-static void t_url_high_bit(void)\n+void test_urlmatch_normalization__high_bit(void)\n {\n \tcheck_normalized_url(\n \t\t\"x://q/\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\x0e\\x0f\\x10\\x11\\x12\",\n@@ -198,26 +190,26 @@ static void t_url_high_bit(void)\n \t\t\"x://q/%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF\");\n }\n \n-static void t_url_utf8_escape(void)\n+void test_urlmatch_normalization__utf8_escape(void)\n {\n \tcheck_normalized_url(\n \t\t\"x://q/\\xc2\\x80\\xdf\\xbf\\xe0\\xa0\\x80\\xef\\xbf\\xbd\\xf0\\x90\\x80\\x80\\xf0\\xaf\\xbf\\xbd\",\n \t\t\"x://q/%C2%80%DF%BF%E0%A0%80%EF%BF%BD%F0%90%80%80%F0%AF%BF%BD\");\n }\n \n-static void t_url_username_pass(void)\n+void test_urlmatch_normalization__username_pass(void)\n {\n \tcheck_normalized_url(\"x://%41%62(^):%70+d@foo\", \"x://Ab(%5E):p+d@foo/\");\n }\n \n-static void t_url_length(void)\n+void test_urlmatch_normalization__length(void)\n {\n \tcheck_normalized_url_length(\"Http://%4d%65:%4d^%70@The.Host\", 25);\n \tcheck_normalized_url_length(\"http://%41:%42@x.y/%61/\", 17);\n \tcheck_normalized_url_length(\"http://@x.y/^\", 15);\n }\n \n-static void t_url_dots(void)\n+void test_urlmatch_normalization__dots(void)\n {\n \tcheck_normalized_url(\"x://y/.\", \"x://y/\");\n \tcheck_normalized_url(\"x://y/./\", \"x://y/\");\n@@ -244,7 +236,7 @@ static void t_url_dots(void)\n  * \"http://foo\" specifies neither a user name nor a password.\n  * So they should not be equivalent.\n  */\n-static void t_url_equivalents(void)\n+void test_urlmatch_normalization__equivalents(void)\n {\n \tcompare_normalized_urls(\"httP://x\", \"Http://X/\", 1);\n \tcompare_normalized_urls(\"Http://%4d%65:%4d^%70@The.Host\", \"hTTP://Me:%4D^p@the.HOST:80/\", 1);\n@@ -253,19 +245,3 @@ static void t_url_equivalents(void)\n \tcompare_normalized_urls(\"https://@x.y/^/../abc\", \"httpS://@x.y:0443/abc\", 1);\n \tcompare_normalized_urls(\"https://@x.y/^/..\", \"httpS://@x.y:0443/\", 1);\n }\n-\n-int cmd_main(int argc UNUSED, const char **argv UNUSED)\n-{\n-\tTEST(t_url_scheme(), \"url scheme\");\n-\tTEST(t_url_authority(), \"url authority\");\n-\tTEST(t_url_port(), \"url port checks\");\n-\tTEST(t_url_port_normalization(), \"url port normalization\");\n-\tTEST(t_url_general_escape(), \"url general escapes\");\n-\tTEST(t_url_high_bit(), \"url high-bit escapes\");\n-\tTEST(t_url_utf8_escape(), \"url utf8 escapes\");\n-\tTEST(t_url_username_pass(), \"url username/password escapes\");\n-\tTEST(t_url_length(), \"url normalized lengths\");\n-\tTEST(t_url_dots(), \"url . and .. segments\");\n-\tTEST(t_url_equivalents(), \"url equivalents\");\n-\treturn test_done();\n-}\n-- \n2.47.0.86.g15030f9556\n\n"},{"id":"513552","messageId":"xmqqzfi0pthr.fsf@gitster.g","threadId":"63055","inReplyTo":"20250304113323.10564-2-kuforiji98@gmail.com","subject":"Re: [PATCH 1/2] t/unit-tests: convert trailer test to use clar","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-03-04T17:59:12Z","receivedAt":"2025-03-04T17:59:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Seyi Kuforiji <kuforiji98@gmail.com> writes:\n\n> diff --git a/t/unit-tests/u-trailer.c b/t/unit-tests/u-trailer.c\n> new file mode 100644\n> index 0000000000..3d60ea1603\n> --- /dev/null\n> +++ b/t/unit-tests/u-trailer.c\n\nIt is a bit sad (not your fault) that this is not shown as a\nrename+modification patch, as most of the logic seem to be straight\nout of the original.\n\n> +void test_trailer__no_newline_start(void)\n> +{\n> +\tstruct contents expected_contents[] = { 0 };\n> +\n> +\tt_trailer_iterator(\"Fixes: x\\n\"\n> +\t\t\t   \"Acked-by: x\\n\"\n> +\t\t\t   \"Reviewed-by: x\\n\",\n> +\t\t\t   0,\n> +\t\t\t   expected_contents);\n> +}\n> +\n> +void test_trailer__newline_start(void)\n> +{\n> +\tstruct contents expected_contents[] = {\n> +\t\t{\n> +\t\t\t.raw = \"Fixes: x\\n\",\n> +\t\t\t.key = \"Fixes\",\n> +\t\t\t.val = \"x\",\n> +\t\t},\n> +\t\t{\n> +\t\t\t.raw = \"Acked-by: x\\n\",\n> +\t\t\t.key = \"Acked-by\",\n> +\t\t\t.val = \"x\",\n> +\t\t},\n> +\t\t{\n> +\t\t\t.raw = \"Reviewed-by: x\\n\",\n> +\t\t\t.key = \"Reviewed-by\",\n> +\t\t\t.val = \"x\",\n> +\t\t},\n> +\t\t{\n> +\t\t\t0\n> +\t\t},\n> +\t};\n> +\n> +\tt_trailer_iterator(\"\\n\"\n> +\t\t\t   \"Fixes: x\\n\"\n> +\t\t\t   \"Acked-by: x\\n\"\n> +\t\t\t   \"Reviewed-by: x\\n\",\n> +\t\t\t   3,\n> +\t\t\t   expected_contents);\n> +}\n\nThis is inherited from the original, but the hardcoded \"3\" feels a\nbit brittle.\n\nWould ARRAY_SIZE(expected_contents)-1 always match the expected\nnumber, I wonder?  Even if it is, improving it is totally outside\nthe scope of this topic.  I am just mentioning this since I will\nforget if I don't ;-).\n"}]}