Git fork

t/unit-tests: convert urlmatch-normalization test to clar

Adapt urlmatch-normalization test file to use clar testing framework by
using clar assertions where necessary.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Seyi Kuforiji <kuforiji98@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Seyi Kuforiji and committed by
Junio C Hamano
7d4212b8 bc934277

+20 -44
+1 -1
Makefile
··· 1362 1362 CLAR_TEST_SUITES += u-strcmp-offset 1363 1363 CLAR_TEST_SUITES += u-strvec 1364 1364 CLAR_TEST_SUITES += u-trailer 1365 + CLAR_TEST_SUITES += u-urlmatch-normalization 1365 1366 CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X) 1366 1367 CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES)) 1367 1368 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o ··· 1378 1379 UNIT_TEST_PROGRAMS += t-reftable-readwrite 1379 1380 UNIT_TEST_PROGRAMS += t-reftable-record 1380 1381 UNIT_TEST_PROGRAMS += t-reftable-stack 1381 - UNIT_TEST_PROGRAMS += t-urlmatch-normalization 1382 1382 UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS)) 1383 1383 UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o 1384 1384 UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
+1 -1
t/meson.build
··· 10 10 'unit-tests/u-strcmp-offset.c', 11 11 'unit-tests/u-strvec.c', 12 12 'unit-tests/u-trailer.c', 13 + 'unit-tests/u-urlmatch-normalization.c', 13 14 ] 14 15 15 16 clar_sources = [ ··· 60 61 'unit-tests/t-reftable-readwrite.c', 61 62 'unit-tests/t-reftable-record.c', 62 63 'unit-tests/t-reftable-stack.c', 63 - 'unit-tests/t-urlmatch-normalization.c', 64 64 ] 65 65 66 66 foreach unit_test_program : unit_test_programs
+18 -42
t/unit-tests/t-urlmatch-normalization.c t/unit-tests/u-urlmatch-normalization.c
··· 1 - #include "test-lib.h" 1 + #include "unit-test.h" 2 2 #include "urlmatch.h" 3 3 4 4 static void check_url_normalizable(const char *url, unsigned int normalizable) 5 5 { 6 6 char *url_norm = url_normalize(url, NULL); 7 7 8 - if (!check_int(normalizable, ==, url_norm ? 1 : 0)) 9 - test_msg("input url: %s", url); 8 + cl_assert_equal_i(normalizable, url_norm ? 1 : 0); 10 9 free(url_norm); 11 10 } 12 11 ··· 14 13 { 15 14 char *url_norm = url_normalize(url, NULL); 16 15 17 - if (!check_str(url_norm, expect)) 18 - test_msg("input url: %s", url); 16 + cl_assert_equal_s(url_norm, expect); 19 17 free(url_norm); 20 18 } 21 19 ··· 26 24 char *url2_norm = url_normalize(url2, NULL); 27 25 28 26 if (equal) { 29 - if (!check_str(url1_norm, url2_norm)) 30 - test_msg("input url1: %s\n input url2: %s", url1, 31 - url2); 32 - } else if (!check_int(strcmp(url1_norm, url2_norm), !=, 0)) { 33 - test_msg(" normalized url1: %s\n normalized url2: %s\n" 34 - " input url1: %s\n input url2: %s", 35 - url1_norm, url2_norm, url1, url2); 27 + cl_assert_equal_s(url1_norm, url2_norm); 28 + } else { 29 + cl_assert(strcmp(url1_norm, url2_norm) != 0); 36 30 } 37 31 free(url1_norm); 38 32 free(url2_norm); ··· 43 37 struct url_info info; 44 38 char *url_norm = url_normalize(url, &info); 45 39 46 - if (!check_int(info.url_len, ==, len)) 47 - test_msg(" input url: %s\n normalized url: %s", url, 48 - url_norm); 40 + cl_assert_equal_i(info.url_len, len); 49 41 free(url_norm); 50 42 } 51 43 52 44 /* Note that only "file:" URLs should be allowed without a host */ 53 - static void t_url_scheme(void) 45 + void test_urlmatch_normalization__scheme(void) 54 46 { 55 47 check_url_normalizable("", 0); 56 48 check_url_normalizable("_", 0); ··· 73 65 check_normalized_url("AbCdeF://x.Y", "abcdef://x.y/"); 74 66 } 75 67 76 - static void t_url_authority(void) 68 + void test_urlmatch_normalization__authority(void) 77 69 { 78 70 check_url_normalizable("scheme://user:pass@", 0); 79 71 check_url_normalizable("scheme://?", 0); ··· 109 101 check_url_normalizable("scheme://invalid....:[", 0); 110 102 } 111 103 112 - static void t_url_port(void) 104 + void test_urlmatch_normalization__port(void) 113 105 { 114 106 check_url_normalizable("xyz://q@some.host:", 1); 115 107 check_url_normalizable("xyz://q@some.host:456/", 1); ··· 139 131 check_url_normalizable("xyz://[::1]:030f/", 0); 140 132 } 141 133 142 - static void t_url_port_normalization(void) 134 + void test_urlmatch_normalization__port_normalization(void) 143 135 { 144 136 check_normalized_url("http://x:800", "http://x:800/"); 145 137 check_normalized_url("http://x:0800", "http://x:800/"); ··· 154 146 check_normalized_url("https://x:000000443", "https://x/"); 155 147 } 156 148 157 - static void t_url_general_escape(void) 149 + void test_urlmatch_normalization__general_escape(void) 158 150 { 159 151 check_url_normalizable("http://x.y?%fg", 0); 160 152 check_normalized_url("X://W/%7e%41^%3a", "x://w/~A%5E%3A"); ··· 164 156 check_normalized_url("X://W?!", "x://w/?!"); 165 157 } 166 158 167 - static void t_url_high_bit(void) 159 + void test_urlmatch_normalization__high_bit(void) 168 160 { 169 161 check_normalized_url( 170 162 "x://q/\x01\x02\x03\x04\x05\x06\x07\x08\x0e\x0f\x10\x11\x12", ··· 198 190 "x://q/%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF"); 199 191 } 200 192 201 - static void t_url_utf8_escape(void) 193 + void test_urlmatch_normalization__utf8_escape(void) 202 194 { 203 195 check_normalized_url( 204 196 "x://q/\xc2\x80\xdf\xbf\xe0\xa0\x80\xef\xbf\xbd\xf0\x90\x80\x80\xf0\xaf\xbf\xbd", 205 197 "x://q/%C2%80%DF%BF%E0%A0%80%EF%BF%BD%F0%90%80%80%F0%AF%BF%BD"); 206 198 } 207 199 208 - static void t_url_username_pass(void) 200 + void test_urlmatch_normalization__username_pass(void) 209 201 { 210 202 check_normalized_url("x://%41%62(^):%70+d@foo", "x://Ab(%5E):p+d@foo/"); 211 203 } 212 204 213 - static void t_url_length(void) 205 + void test_urlmatch_normalization__length(void) 214 206 { 215 207 check_normalized_url_length("Http://%4d%65:%4d^%70@The.Host", 25); 216 208 check_normalized_url_length("http://%41:%42@x.y/%61/", 17); 217 209 check_normalized_url_length("http://@x.y/^", 15); 218 210 } 219 211 220 - static void t_url_dots(void) 212 + void test_urlmatch_normalization__dots(void) 221 213 { 222 214 check_normalized_url("x://y/.", "x://y/"); 223 215 check_normalized_url("x://y/./", "x://y/"); ··· 244 236 * "http://foo" specifies neither a user name nor a password. 245 237 * So they should not be equivalent. 246 238 */ 247 - static void t_url_equivalents(void) 239 + void test_urlmatch_normalization__equivalents(void) 248 240 { 249 241 compare_normalized_urls("httP://x", "Http://X/", 1); 250 242 compare_normalized_urls("Http://%4d%65:%4d^%70@The.Host", "hTTP://Me:%4D^p@the.HOST:80/", 1); ··· 253 245 compare_normalized_urls("https://@x.y/^/../abc", "httpS://@x.y:0443/abc", 1); 254 246 compare_normalized_urls("https://@x.y/^/..", "httpS://@x.y:0443/", 1); 255 247 } 256 - 257 - int cmd_main(int argc UNUSED, const char **argv UNUSED) 258 - { 259 - TEST(t_url_scheme(), "url scheme"); 260 - TEST(t_url_authority(), "url authority"); 261 - TEST(t_url_port(), "url port checks"); 262 - TEST(t_url_port_normalization(), "url port normalization"); 263 - TEST(t_url_general_escape(), "url general escapes"); 264 - TEST(t_url_high_bit(), "url high-bit escapes"); 265 - TEST(t_url_utf8_escape(), "url utf8 escapes"); 266 - TEST(t_url_username_pass(), "url username/password escapes"); 267 - TEST(t_url_length(), "url normalized lengths"); 268 - TEST(t_url_dots(), "url . and .. segments"); 269 - TEST(t_url_equivalents(), "url equivalents"); 270 - return test_done(); 271 - }