is_{hfs,ntfs}_dotgitmodules: add tests

This tests primarily for NTFS issues, but also adds one example of an HFS+ issue. Thanks go to Congyi Wu for coming up with the list of examples where NTFS would possibly equate the filename with `.gitmodules`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Jeff King <peff@peff.net>

Johannes Schindelin committed May 12, 2018 at 22:16 UTC dc2d9ba3187fcd0ca8eeab9aa9ddef70cf8627a6
2 files changed +106
t/helper/test-path-utils.c
+20
@@ -1,5 +1,6 @@
1 #include "cache.h"
2 #include "string-list.h"
3 +#include "utf8.h"
4
5 /*
6 * A "string_list_each_func_t" function that normalizes an entry from
@@ -156,6 +157,11 @@ static struct test_data dirname_data[] = {
157 { NULL, NULL }
158 };
159
160 +static int is_dotgitmodules(const char *path)
161 +{
162 + return is_hfs_dotgitmodules(path) || is_ntfs_dotgitmodules(path);
163 +}
164 +
165 int cmd_main(int argc, const char **argv)
166 {
167 if (argc == 3 && !strcmp(argv[1], "normalize_path_copy")) {
@@ -256,6 +262,20 @@ int cmd_main(int argc, const char **argv)
262 if (argc == 2 && !strcmp(argv[1], "dirname"))
263 return test_function(dirname_data, dirname, argv[1]);
264
265 + if (argc > 2 && !strcmp(argv[1], "is_dotgitmodules")) {
266 + int res = 0, expect = 1, i;
267 + for (i = 2; i < argc; i++)
268 + if (!strcmp("--not", argv[i]))
269 + expect = !expect;
270 + else if (expect != is_dotgitmodules(argv[i]))
271 + res = error("'%s' is %s.gitmodules", argv[i],
272 + expect ? "not " : "");
273 + else
274 + fprintf(stderr, "ok: '%s' is %s.gitmodules\n",
275 + argv[i], expect ? "" : "not ");
276 + return !!res;
277 + }
278 +
279 fprintf(stderr, "%s: unknown function name: %s\n", argv[0],
280 argv[1] ? argv[1] : "(there was none)");
281 return 1;
t/t0060-path-utils.sh
+86
@@ -349,4 +349,90 @@ test_submodule_relative_url "(null)" "ssh://hostname:22/repo" "../subrepo" "ssh:
349 test_submodule_relative_url "(null)" "user@host:path/to/repo" "../subrepo" "user@host:path/to/subrepo"
350 test_submodule_relative_url "(null)" "user@host:repo" "../subrepo" "user@host:subrepo"
351
352 +test_expect_success 'match .gitmodules' '
353 + test-path-utils is_dotgitmodules \
354 + .gitmodules \
355 + \
356 + .git${u200c}modules \
357 + \
358 + .Gitmodules \
359 + .gitmoduleS \
360 + \
361 + ".gitmodules " \
362 + ".gitmodules." \
363 + ".gitmodules " \
364 + ".gitmodules. " \
365 + ".gitmodules ." \
366 + ".gitmodules.." \
367 + ".gitmodules " \
368 + ".gitmodules. " \
369 + ".gitmodules . " \
370 + ".gitmodules ." \
371 + \
372 + ".Gitmodules " \
373 + ".Gitmodules." \
374 + ".Gitmodules " \
375 + ".Gitmodules. " \
376 + ".Gitmodules ." \
377 + ".Gitmodules.." \
378 + ".Gitmodules " \
379 + ".Gitmodules. " \
380 + ".Gitmodules . " \
381 + ".Gitmodules ." \
382 + \
383 + GITMOD~1 \
384 + gitmod~1 \
385 + GITMOD~2 \
386 + gitmod~3 \
387 + GITMOD~4 \
388 + \
389 + "GITMOD~1 " \
390 + "gitmod~2." \
391 + "GITMOD~3 " \
392 + "gitmod~4. " \
393 + "GITMOD~1 ." \
394 + "gitmod~2 " \
395 + "GITMOD~3. " \
396 + "gitmod~4 . " \
397 + \
398 + GI7EBA~1 \
399 + gi7eba~9 \
400 + \
401 + GI7EB~10 \
402 + GI7EB~11 \
403 + GI7EB~99 \
404 + GI7EB~10 \
405 + GI7E~100 \
406 + GI7E~101 \
407 + GI7E~999 \
408 + ~1000000 \
409 + ~9999999 \
410 + \
411 + --not \
412 + ".gitmodules x" \
413 + ".gitmodules .x" \
414 + \
415 + " .gitmodules" \
416 + \
417 + ..gitmodules \
418 + \
419 + gitmodules \
420 + \
421 + .gitmodule \
422 + \
423 + ".gitmodules x " \
424 + ".gitmodules .x" \
425 + \
426 + GI7EBA~ \
427 + GI7EBA~0 \
428 + GI7EBA~~1 \
429 + GI7EBA~X \
430 + Gx7EBA~1 \
431 + GI7EBX~1 \
432 + \
433 + GI7EB~1 \
434 + GI7EB~01 \
435 + GI7EB~1X
436 +'
437 +
438 test_done