diff options
| author | Junio C Hamano <gitster@pobox.com> | 2016-04-29 12:59:06 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2016-04-29 12:59:06 -0700 |
| commit | e0b5851907c4feb32af3b1f96200cdd6c68b524d (patch) | |
| tree | 110fd45b6aefaa59feda8e53ca090ca288d7940a /t/helper/test-urlmatch-normalization.c | |
| parent | e7e68265147f6aa08391b4724d862e58424b29df (diff) | |
| parent | e6e7530d10b74d763b4311ea93e0a831b810d6c2 (diff) | |
Merge branch 'nd/test-helpers'
Sources to many test helper binaries (and the generated helpers)
have been moved to t/helper/ subdirectory to reduce clutter at the
top level of the tree.
* nd/test-helpers:
test helpers: move test-* to t/helper/ subdirectory
Makefile: clean *.o files we create
Diffstat (limited to 't/helper/test-urlmatch-normalization.c')
| -rw-r--r-- | t/helper/test-urlmatch-normalization.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/t/helper/test-urlmatch-normalization.c b/t/helper/test-urlmatch-normalization.c new file mode 100644 index 0000000000..090bf219a7 --- /dev/null +++ b/t/helper/test-urlmatch-normalization.c @@ -0,0 +1,50 @@ +#include "git-compat-util.h" +#include "urlmatch.h" + +int main(int argc, char **argv) +{ + const char usage[] = "test-urlmatch-normalization [-p | -l] <url1> | <url1> <url2>"; + char *url1, *url2; + int opt_p = 0, opt_l = 0; + + /* + * For one url, succeed if url_normalize succeeds on it, fail otherwise. + * For two urls, succeed only if url_normalize succeeds on both and + * the results compare equal with strcmp. If -p is given (one url only) + * and url_normalize succeeds, print the result followed by "\n". If + * -l is given (one url only) and url_normalize succeeds, print the + * returned length in decimal followed by "\n". + */ + + if (argc > 1 && !strcmp(argv[1], "-p")) { + opt_p = 1; + argc--; + argv++; + } else if (argc > 1 && !strcmp(argv[1], "-l")) { + opt_l = 1; + argc--; + argv++; + } + + if (argc < 2 || argc > 3) + die("%s", usage); + + if (argc == 2) { + struct url_info info; + url1 = url_normalize(argv[1], &info); + if (!url1) + return 1; + if (opt_p) + printf("%s\n", url1); + if (opt_l) + printf("%u\n", (unsigned)info.url_len); + return 0; + } + + if (opt_p || opt_l) + die("%s", usage); + + url1 = url_normalize(argv[1], NULL); + url2 = url_normalize(argv[2], NULL); + return (url1 && url2 && !strcmp(url1, url2)) ? 0 : 1; +} |
