]> git.ipfire.org Git - thirdparty/git.git/blob - t/helper/test-urlmatch-normalization.c
Merge branch 'jk/clone-allow-bare-and-o-together'
[thirdparty/git.git] / t / helper / test-urlmatch-normalization.c
1 #include "test-tool.h"
2 #include "git-compat-util.h"
3 #include "urlmatch.h"
4
5 int cmd__urlmatch_normalization(int argc, const char **argv)
6 {
7 const char usage[] = "test-tool urlmatch-normalization [-p | -l] <url1> | <url1> <url2>";
8 char *url1 = NULL, *url2 = NULL;
9 int opt_p = 0, opt_l = 0;
10 int ret = 0;
11
12 /*
13 * For one url, succeed if url_normalize succeeds on it, fail otherwise.
14 * For two urls, succeed only if url_normalize succeeds on both and
15 * the results compare equal with strcmp. If -p is given (one url only)
16 * and url_normalize succeeds, print the result followed by "\n". If
17 * -l is given (one url only) and url_normalize succeeds, print the
18 * returned length in decimal followed by "\n".
19 */
20
21 if (argc > 1 && !strcmp(argv[1], "-p")) {
22 opt_p = 1;
23 argc--;
24 argv++;
25 } else if (argc > 1 && !strcmp(argv[1], "-l")) {
26 opt_l = 1;
27 argc--;
28 argv++;
29 }
30
31 if (argc < 2 || argc > 3)
32 die("%s", usage);
33
34 if (argc == 2) {
35 struct url_info info;
36 url1 = url_normalize(argv[1], &info);
37 if (!url1)
38 return 1;
39 if (opt_p)
40 printf("%s\n", url1);
41 if (opt_l)
42 printf("%u\n", (unsigned)info.url_len);
43 goto cleanup;
44 }
45
46 if (opt_p || opt_l)
47 die("%s", usage);
48
49 url1 = url_normalize(argv[1], NULL);
50 url2 = url_normalize(argv[2], NULL);
51 ret = (url1 && url2 && !strcmp(url1, url2)) ? 0 : 1;
52 cleanup:
53 free(url1);
54 free(url2);
55 return ret;
56 }