clar: verify command line arguments before execute When executing `libgit2_clar -smerge -invalid_option`, it will first execute the merge test suite and afterwards output help because of the invalid option. With this changa, it verifies all options before execute. If there are any invalid options, it will output help and exit without actually executing the test suites.
diff --git a/tests/clar.c b/tests/clar.c
index 905d67d..d5212d1 100644
--- a/tests/clar.c
+++ b/tests/clar.c
@@ -313,11 +313,18 @@ clar_parse_args(int argc, char **argv)
{
int i;
+ /* Verify options before execute */
for (i = 1; i < argc; ++i) {
char *argument = argv[i];
- if (argument[0] != '-')
+ if (argument[0] != '-' || argument[1] == '\0'
+ || strchr("sixvqQl", argument[1]) == NULL) {
clar_usage(argv[0]);
+ }
+ }
+
+ for (i = 1; i < argc; ++i) {
+ char *argument = argv[i];
switch (argument[1]) {
case 's':
@@ -391,7 +398,7 @@ clar_parse_args(int argc, char **argv)
break;
default:
- clar_usage(argv[0]);
+ assert(!"Unexpected commandline argument!");
}
}
}