• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

saitoha / libsixel / 21335896708

25 Jan 2026 04:33PM UTC coverage: 76.581% (-2.3%) from 78.904%
21335896708

push

github

saitoha
meson: set build type to plain

20012 of 44638 branches covered (44.83%)

36354 of 47471 relevant lines covered (76.58%)

13461842.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.31
/tests/cli/0031_cli_guard_missing_argument.c
1
/*
2
 * Test harness for cli_guard_missing_argument handling.
3
 */
4

5
#include <stdio.h>
6
#include <stdlib.h>
7
#include <string.h>
8

9
#include "config.h"
10
#include "converters/cli.h"
11

12
typedef struct guard_result {
13
    int code;
14
    int missing_calls;
15
    int rewound_optind;
16
} guard_result_t;
17

18
static int g_missing_calls;
19
static int g_rewound;
20

21
static int
22
allows_leading_dash(int short_opt, void *user_data)
13✔
23
{
24
    (void)user_data;
9✔
25
    return short_opt == 'i';
13✔
26
}
27

28
static void
29
report_missing(int short_opt, void *user_data)
26✔
30
{
31
    int *last_short;
14✔
32

33
    last_short = (int *)user_data;
26✔
34
    g_missing_calls += 1;
26✔
35
    *last_short = short_opt;
26✔
36
}
26✔
37

38
static guard_result_t
39
run_guard_case(char *const *argv,
39✔
40
               char *argument,
41
               int *optind_ptr,
42
               char const *optstring,
43
               cli_option_help_t const *table,
44
               size_t table_count,
45
               int allow_dash)
46
{
47
    int report_short;
21✔
48
    int result;
21✔
49
    int starting_optind;
21✔
50

51
    report_short = 0;
39✔
52
    g_missing_calls = 0;
39✔
53
    g_rewound = 0;
39✔
54

55
    starting_optind = 0;
39✔
56
    if (optind_ptr != NULL) {
39!
57
        starting_optind = *optind_ptr;
39✔
58
    }
9✔
59

60
    result = cli_guard_missing_argument(
51✔
61
        'i',
62
        argv,
9✔
63
        argument,
9✔
64
        optind_ptr,
9✔
65
        optstring,
9✔
66
        table,
9✔
67
        table_count,
9✔
68
        allow_dash ? allows_leading_dash : NULL,
9✔
69
        NULL,
70
        report_missing,
71
        &report_short);
72

73
    if (optind_ptr != NULL
41!
74
            && *optind_ptr == starting_optind - 1
39!
75
            && allow_dash == 0) {
19!
76
        g_rewound = 1;
13✔
77
    }
3✔
78

79
    return (guard_result_t){ result, g_missing_calls, g_rewound };
39✔
80
}
3✔
81

82
int
83
test_cli_0031_cli_guard_missing_argument(int argc, char **argv)
13✔
84
{
85
    cli_option_help_t const table[] = {
13✔
86
        { 'i', "input", "--input help\n" },
87
        { 'x', "extract", "--extract help\n" },
88
    };
89
    char argv0[] = "tool";
13✔
90
    char argv1[] = "-x";
13✔
91
    char dash_value[] = "-file.six";
13✔
92
    char *args[] = { argv0, argv1, NULL };
13✔
93
    size_t table_count;
7✔
94
    int optind_value;
7✔
95
    guard_result_t result;
7✔
96
    int status;
7✔
97

98
    (void) argc;
9✔
99
    (void) argv;
9✔
100

101
    table_count = sizeof(table) / sizeof(table[0]);
13✔
102

103
    optind_value = 1;
13✔
104
    result = run_guard_case(args,
16✔
105
                             NULL,
106
                             &optind_value,
107
                             "i:",
108
                             table,
3✔
109
                             table_count,
3✔
110
                             0);
111
    status = 0;
13✔
112
    if (result.code == -1 && result.missing_calls == 1) {
13!
113
    } else {
3✔
114
        fprintf(stderr, "case 1: missing argument not reported\n");
×
115
        status = 1;
×
116
    }
117

118
    optind_value = 0;
13✔
119
    result = run_guard_case(args,
16✔
120
                             dash_value,
3✔
121
                             &optind_value,
122
                             "i:",
123
                             table,
3✔
124
                             table_count,
3✔
125
                             1);
126
    if (result.code == 0 && result.missing_calls == 0) {
13!
127
    } else {
3✔
128
        fprintf(stderr, "case 2: leading dash rejected\n");
×
129
        status = 1;
×
130
    }
131

132
    optind_value = 2;
13✔
133
    result = run_guard_case(args,
16✔
134
                             args[1],
3✔
135
                             &optind_value,
136
                             "i:",
137
                             table,
3✔
138
                             table_count,
3✔
139
                             0);
140
    if (result.code == -1 && result.missing_calls == 1 &&
17!
141
            result.rewound_optind != 0) {
13!
142
    } else {
3✔
143
        fprintf(stderr, "case 3: did not rewind recognised option\n");
×
144
        status = 1;
×
145
    }
146

147
    return status == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
14✔
148
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc