summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorYoney <alper_yoney@hotmail.com>2017-11-11 15:38:27 +0000
committerYoney <alper_yoney@hotmail.com>2017-11-11 18:49:08 +0000
commit3275863134122892e2f8a8aa4ad0ce1c123a48ec (patch)
tree3f4520968ad7aeb18bd5f3a4ac93edced177c20e /tests
parent46e1dabb8037a284eba491c34b27a257768e416c (diff)
downloadlibgit2-3275863134122892e2f8a8aa4ad0ce1c123a48ec.tar.gz
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/clar.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/tests/clar.c b/tests/clar.c
index 905d67db7..d5212d1ca 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!");
}
}
}