Really fail if we have a test failure
[openssl.git] / test / testutil / options.c
1 /*
2  * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #include "../testutil.h"
11 #include "internal/nelem.h"
12 #include "tu_local.h"
13 #include "output.h"
14
15
16 static int used[100] = { 0 };
17
18
19 size_t test_get_argument_count(void)
20 {
21     return opt_num_rest();
22 }
23
24 char *test_get_argument(size_t n)
25 {
26     char **argv = opt_rest();
27
28     OPENSSL_assert(n < sizeof(used));
29     if ((int)n >= opt_num_rest() || argv == NULL)
30         return NULL;
31     used[n] = 1;
32     return argv[n];
33 }
34
35 void opt_check_usage(void)
36 {
37     int i;
38     char **argv = opt_rest();
39     int n, arg_count = opt_num_rest();
40
41     if (arg_count > (int)OSSL_NELEM(used))
42         n = (int)OSSL_NELEM(used);
43     else
44         n = arg_count;
45     for (i = 0; i < n; i++) {
46         if (used[i] == 0)
47             test_printf_stderr("Warning ignored command-line argument %d: %s\n",
48                                i, argv[i]);
49     }
50     if (i < arg_count)
51         test_printf_stderr("Warning arguments %d and later unchecked\n", i);
52 }
53
54 int opt_printf_stderr(const char *fmt, ...)
55 {
56     va_list ap;
57     int ret;
58
59     va_start(ap, fmt);
60     ret = test_vprintf_stderr(fmt, ap);
61     va_end(ap);
62     return ret;
63 }
64