@matheusbsbs / matheus-bagliano / commits / 2cd85c40a9
Fork 0

Make test-path-utils more robust against incorrect use

Previously, this test utility happily returned with exit code 0 if garbage was thrown at it. Now it reports failure if an unknown function name was given on the command line. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Sixt committed Feb 7, 2009 at 16:08 UTC 2cd85c40a9f396bb24f7861c832acd52e61c4780
1 file changed +6 -1
test-path-utils.c
+6 -1
@@ -7,6 +7,7 @@ int main(int argc, char **argv)
7 int rv = normalize_absolute_path(buf, argv[2]);
8 assert(strlen(buf) == rv);
9 puts(buf);
10 + return 0;
11 }
12
13 if (argc >= 2 && !strcmp(argv[1], "make_absolute_path")) {
@@ -15,12 +16,16 @@ int main(int argc, char **argv)
16 argc--;
17 argv++;
18 }
19 + return 0;
20 }
21
22 if (argc == 4 && !strcmp(argv[1], "longest_ancestor_length")) {
23 int len = longest_ancestor_length(argv[2], argv[3]);
24 printf("%d\n", len);
25 + return 0;
26 }
27
25 - return 0;
28 + fprintf(stderr, "%s: unknown function name: %s\n", argv[0],
29 + argv[1] ? argv[1] : "(there was none)");
30 + return 1;
31 }