t/unit-tests: convert unit-tests to use clar
Subsystems (2)
cover t/unit-tests: convert unit-tests to use clar
Hello,
This small patch series transitions a couple more of our existing unit test files to the Clar testing framework. This change is part of our ongoing effort to standardize our testing framework to enhance maintainability.
Thanks
Seyi
Seyi Kuforiji (2):
t/unit-tests: convert trailer test to use clar t/unit-tests: convert urlmatch-normalization test to clar
Makefile | 4 +-
t/meson.build | 4 +-
t/unit-tests/t-trailer.c | 317 -----------------
t/unit-tests/u-trailer.c | 320 ++++++++++++++++++
...alization.c => u-urlmatch-normalization.c} | 60 +---
5 files changed, 342 insertions(+), 363 deletions(-)
delete mode 100644 t/unit-tests/t-trailer.c
create mode 100644 t/unit-tests/u-trailer.c
rename t/unit-tests/{t-urlmatch-normalization.c => u-urlmatch-normalization.c} (84%)Signature · 1 line
2.47.0.86.g15030f9556
PATCH 1/2 t/unit-tests: convert trailer test to use clar
Adapt trailer test file to use clar testing framework by using clar assertions where necessary. Split test into individual test functions for clarity and maintainability. Each test case now has its own function, making it easier to isolate failures and improve test readability.
--- Makefile | 2 +- t/meson.build | 2 +- t/unit-tests/t-trailer.c | 317 -------------------------------------- t/unit-tests/u-trailer.c | 320 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 322 insertions(+), 319 deletions(-) delete mode 100644 t/unit-tests/t-trailer.c create mode 100644 t/unit-tests/u-trailer.c
Makefile +1 -1
@@ -1361,6 +1361,7 @@ CLAR_TEST_SUITES += u-reftable-tree CLAR_TEST_SUITES += u-strbuf CLAR_TEST_SUITES += u-strcmp-offset CLAR_TEST_SUITES += u-strvec +CLAR_TEST_SUITES += u-trailer CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X) CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES)) CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
@@ -1377,7 +1378,6 @@ UNIT_TEST_PROGRAMS += t-reftable-reader UNIT_TEST_PROGRAMS += t-reftable-readwrite UNIT_TEST_PROGRAMS += t-reftable-record UNIT_TEST_PROGRAMS += t-reftable-stack -UNIT_TEST_PROGRAMS += t-trailer UNIT_TEST_PROGRAMS += t-urlmatch-normalization UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS)) UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o
t/meson.build +1 -1
@@ -9,6 +9,7 @@ clar_test_suites = [ 'unit-tests/u-strbuf.c', 'unit-tests/u-strcmp-offset.c', 'unit-tests/u-strvec.c', + 'unit-tests/u-trailer.c', ] clar_sources = [
@@ -59,7 +60,6 @@ unit_test_programs = [ 'unit-tests/t-reftable-readwrite.c', 'unit-tests/t-reftable-record.c', 'unit-tests/t-reftable-stack.c', - 'unit-tests/t-trailer.c', 'unit-tests/t-urlmatch-normalization.c', ]
t/unit-tests/t-trailer.c deleted +0 -317
317 lines not on this page · raw message
t/unit-tests/u-trailer.c new file +320 -0
320 lines not on this page · raw message
Signature · 1 line
2.47.0.86.g15030f9556
Re: [PATCH 1/2] t/unit-tests: convert trailer test to use clar
t/unit-tests/u-trailer.c
Quoted 5 lines · Seyi Kuforiji
t/unit-tests/u-trailer.c new file +0
-0
It is a bit sad (not your fault) that this is not shown as a rename+modification patch, as most of the logic seem to be straight out of the original.
Quoted 31 lines
t/unit-tests/u-trailer.c new file +31
-0+void test_trailer__no_newline_start (void ) +{ +struct contents expected_contents[] = {0 }; + +t_trailer_iterator ("Fixes: x\n" +"Acked-by: x\n" +"Reviewed-by: x\n" , +0 , + expected_contents); +} + +void test_trailer__newline_start (void ) +{ +struct contents expected_contents[] = { + { + .raw ="Fixes: x\n" , + .key ="Fixes" , + .val ="x" , + }, + { + .raw ="Acked-by: x\n" , + .key ="Acked-by" , + .val ="x" , + }, + { + .raw ="Reviewed-by: x\n" , + .key ="Reviewed-by" , + .val ="x" , + }, + { +0
t/unit-tests/u-trailer.c line 78
Quoted 10 lines
t/unit-tests/u-trailer.c new file +10
-0+ }, + }; + +t_trailer_iterator ("\n" +"Fixes: x\n" +"Acked-by: x\n" +"Reviewed-by: x\n" , +3 , + expected_contents); +}
This is inherited from the original, but the hardcoded "3" feels a bit brittle.
Would ARRAY_SIZE(expected_contents)-1 always match the expected number, I wonder? Even if it is, improving it is totally outside the scope of this topic. I am just mentioning this since I will forget if I don't ;-).
PATCH 2/2 t/unit-tests: convert urlmatch-normalization test to clar
In reply to Seyi KuforijiAdapt urlmatch-normalization test file to use clar testing framework by using clar assertions where necessary.
---
Makefile | 2 +-
t/meson.build | 2 +-
...alization.c => u-urlmatch-normalization.c} | 60 ++++++-------------
3 files changed, 20 insertions(+), 44 deletions(-)
rename t/unit-tests/{t-urlmatch-normalization.c => u-urlmatch-normalization.c} (84%)Makefile +1 -1
@@ -1362,6 +1362,7 @@ CLAR_TEST_SUITES += u-strbuf CLAR_TEST_SUITES += u-strcmp-offset CLAR_TEST_SUITES += u-strvec CLAR_TEST_SUITES += u-trailer +CLAR_TEST_SUITES += u-urlmatch-normalization CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X) CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES)) CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
@@ -1378,7 +1379,6 @@ UNIT_TEST_PROGRAMS += t-reftable-reader UNIT_TEST_PROGRAMS += t-reftable-readwrite UNIT_TEST_PROGRAMS += t-reftable-record UNIT_TEST_PROGRAMS += t-reftable-stack -UNIT_TEST_PROGRAMS += t-urlmatch-normalization UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS)) UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
t/meson.build +1 -1
@@ -10,6 +10,7 @@ clar_test_suites = [ 'unit-tests/u-strcmp-offset.c', 'unit-tests/u-strvec.c', 'unit-tests/u-trailer.c', + 'unit-tests/u-urlmatch-normalization.c', ] clar_sources = [
@@ -60,7 +61,6 @@ unit_test_programs = [ 'unit-tests/t-reftable-readwrite.c', 'unit-tests/t-reftable-record.c', 'unit-tests/t-reftable-stack.c', - 'unit-tests/t-urlmatch-normalization.c', ] foreach unit_test_program : unit_test_programs
t/unit-tests/u-urlmatch-normalization.c renamed from t/unit-tests/t-urlmatch-normalization.c +18 -42
152 lines not on this page · raw message
Signature · 1 line
2.47.0.86.g15030f9556