Skip to content

Commit 2cd85c4

Browse files
j6tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ab2fdb3 commit 2cd85c4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

test-path-utils.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ int main(int argc, char **argv)
77
int rv = normalize_absolute_path(buf, argv[2]);
88
assert(strlen(buf) == rv);
99
puts(buf);
10+
return 0;
1011
}
1112

1213
if (argc >= 2 && !strcmp(argv[1], "make_absolute_path")) {
@@ -15,12 +16,16 @@ int main(int argc, char **argv)
1516
argc--;
1617
argv++;
1718
}
19+
return 0;
1820
}
1921

2022
if (argc == 4 && !strcmp(argv[1], "longest_ancestor_length")) {
2123
int len = longest_ancestor_length(argv[2], argv[3]);
2224
printf("%d\n", len);
25+
return 0;
2326
}
2427

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;
2631
}

0 commit comments

Comments
 (0)