Compress-Zstd
view release on metacpan or search on metacpan
ext/zstd/tests/regression/test.c view on Meta::CPAN
}
/** Print the help for the program. */
static void print_help(void) {
fprintf(stderr, "regression test runner\n");
size_t const nargs = sizeof(long_options) / sizeof(long_options[0]);
for (size_t i = 0; i < nargs; ++i) {
if (long_options[i].val < 128) {
/* Long / short - help [option type] */
fprintf(
stderr,
"--%s / -%c \t- %s %s\n",
long_options[i].name,
long_options[i].val,
long_extras[i].help,
required_message(long_extras[i].opt_type));
} else {
/* Short / long - help [option type] */
fprintf(
stderr,
"--%s \t- %s %s\n",
long_options[i].name,
long_extras[i].help,
required_message(long_extras[i].opt_type));
}
}
}
/** Parse the arguments. Return 0 on success. Print help on failure. */
static int parse_args(int argc, char** argv) {
int option_index = 0;
int c;
while (1) {
c = getopt_long(argc, argv, short_options, long_options, &option_index);
if (c == -1)
break;
int found = 0;
for (size_t i = 0; i < nargs; ++i) {
if (c == long_extras[i].id && long_extras[i].value != NULL) {
*long_extras[i].value = optarg;
found = 1;
break;
}
}
if (found)
continue;
switch (c) {
case 'h':
case '?':
default:
print_help();
return 1;
}
}
int bad = 0;
for (size_t i = 0; i < nargs; ++i) {
if (long_extras[i].opt_type != required_option)
continue;
if (long_extras[i].value == NULL)
continue;
if (*long_extras[i].value != NULL)
continue;
fprintf(
stderr,
"--%s is a required argument but is not set\n",
long_options[i].name);
bad = 1;
}
if (bad) {
fprintf(stderr, "\n");
print_help();
return 1;
}
return 0;
}
/** Helper macro to print to stderr and a file. */
#define tprintf(file, ...) \
do { \
fprintf(file, __VA_ARGS__); \
fprintf(stderr, __VA_ARGS__); \
} while (0)
/** Helper macro to flush stderr and a file. */
#define tflush(file) \
do { \
fflush(file); \
fflush(stderr); \
} while (0)
void tprint_names(
FILE* results,
char const* data_name,
char const* config_name,
char const* method_name) {
int const data_padding = g_max_name_len - strlen(data_name);
int const config_padding = g_max_name_len - strlen(config_name);
int const method_padding = g_max_name_len - strlen(method_name);
tprintf(
results,
"%s, %*s%s, %*s%s, %*s",
data_name,
data_padding,
"",
config_name,
config_padding,
"",
method_name,
method_padding,
"");
}
/**
* Run all the regression tests and record the results table to results and
* stderr progressively.
*/
( run in 0.857 second using v1.01-cache-2.11-cpan-995e09ba956 )