X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=tests%2Ftest-argp.c;h=f00f563ed940ed2ad3738290882fb22b63a93ab4;hb=dcfa509347541cf4a44f7e5be5fc74398d8a8199;hp=f33cb7cd5ebf70017de7609c193c9803236a4162;hpb=a75a52bb4444c02d8dc70105d8c6865718a827a0;p=gnulib.git diff --git a/tests/test-argp.c b/tests/test-argp.c index f33cb7cd5..f00f563ed 100644 --- a/tests/test-argp.c +++ b/tests/test-argp.c @@ -2,23 +2,20 @@ Copyright (C) 2006-2007 Free Software Foundation, Inc. This file is part of the GNUlib Library. - This program is free software; you can redistribute it and/or modify + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ -#ifdef HAVE_CONFIG_H -# include -#endif +#include #include "argp.h" @@ -30,6 +27,7 @@ #if HAVE_STRINGS_H # include #endif +#include "progname.h" struct test_args { @@ -44,12 +42,12 @@ struct test_args int group_1_1_option; }; -static struct argp_option group1_option[] = +static struct argp_option group1_option[] = { { NULL, 0, NULL, 0, "Option Group 1", 0}, { "verbose", 'v', NULL, 0, "Simple option without arguments", 1 }, { "file", 'f', "FILE", 0, "Option with a mandatory argument", 1 }, - { "input", 0, NULL, OPTION_ALIAS, NULL, 1 }, + { "input", 0, NULL, OPTION_ALIAS, NULL, 1 }, { "hidden", 'H', "FILE", OPTION_HIDDEN, "Hidden option", 1 }, { NULL, 0, NULL, 0, NULL, 0 } }; @@ -64,15 +62,15 @@ group1_parser (int key, char *arg, struct argp_state *state) case 'v': args->verbose++; break; - + case 'f': args->file = arg; break; - + case 'H': args->hidden = arg; break; - + default: return ARGP_ERR_UNKNOWN; } @@ -92,7 +90,7 @@ struct argp_child group1_child = { }; -static struct argp_option group1_1_option[] = +static struct argp_option group1_1_option[] = { { NULL, 0, NULL, 0, "Option Group 1.1", 0}, { "cantiga", 'C', NULL, 0, "create a cantiga" }, @@ -129,7 +127,7 @@ struct argp_child group1_1_child = { }; -static struct argp_option group2_option[] = +static struct argp_option group2_option[] = { { NULL, 0, NULL, 0, "Option Group 2", 0}, { "option", 'O', NULL, 0, "An option", 1 }, @@ -151,12 +149,12 @@ group2_parser (int key, char *arg, struct argp_state *state) case 'O': args->opt = 1; break; - + case 'o': args->optional_set = 1; args->optional = arg; break; - + default: return ARGP_ERR_UNKNOWN; } @@ -176,7 +174,7 @@ struct argp_child group2_child = { }; -static struct argp_option group2_1_option[] = +static struct argp_option group2_1_option[] = { { NULL, 0, NULL, 0, "Option Group 2.1", 0}, { "poem", 'p', NULL, 0, "create a poem" }, @@ -211,12 +209,12 @@ struct argp_child group2_1_child = { "", 2 }; - + static struct argp_option main_options[] = { { NULL, 0, NULL, 0, "Main options", 0}, - { "test", 't', NULL, 0, NULL, 1 }, + { "test", 't', NULL, 0, NULL, 1 }, { NULL, 0, NULL, 0, NULL, 0 } }; @@ -225,18 +223,18 @@ parse_opt (int key, char *arg, struct argp_state *state) { struct test_args *args = state->input; int i; - + switch (key) { case ARGP_KEY_INIT: for (i = 0; state->root_argp->children[i].argp; i++) - state->child_inputs[i] = args; + state->child_inputs[i] = args; break; case 't': args->test = 1; break; - + default: return ARGP_ERR_UNKNOWN; } @@ -350,7 +348,7 @@ test6(struct argp *argp) void test_optional(struct argp *argp, int argc, char **argv, - struct test_args *args, char *val, char *a) + struct test_args *args, char *val, char *a) { int index; if (argp_parse (argp, argc, argv, 0, &index, args)) @@ -361,7 +359,7 @@ test_optional(struct argp *argp, int argc, char **argv, if (!val) { if (args->optional) - fail("option processed incorrectly"); + fail("option processed incorrectly"); } else if (strcmp (args->optional, val)) fail("option processed incorrectly"); @@ -369,9 +367,9 @@ test_optional(struct argp *argp, int argc, char **argv, if (a) { if (index == argc) - fail("expected command line argument not found"); + fail("expected command line argument not found"); else if (strcmp(argv[index], a)) - fail("expected command line argument does not match"); + fail("expected command line argument does not match"); } } @@ -402,7 +400,7 @@ test10(struct argp *argp) INIT_TEST2 (10, "--optional", "ARG"); test_optional(argp, argc, argv, &test_args, NULL, "ARG"); } - + void test11(struct argp *argp) { @@ -415,7 +413,7 @@ test12(struct argp *argp) { INIT_TEST3 (12, "--option", "--optional=OPT", "FILE"); test_optional(argp, argc, argv, &test_args, "OPT", "FILE"); -} +} void test13(struct argp *argp) @@ -464,7 +462,7 @@ main (int argc, char **argv) group2_children[0] = group2_1_child; group2_children[1].argp = NULL; group2_argp.children = group2_children; - + argp_children[0] = group1_child; argp_children[1] = group2_child; argp_children[2].argp = NULL; @@ -472,11 +470,11 @@ main (int argc, char **argv) if (argc > 0) { - struct test_args test_args; - init_args(test_args); + struct test_args test_args; + init_args(test_args); return argp_parse (&test_argp, argc, argv, 0, NULL, &test_args); } - + for (fun = test_fun; *fun; fun++) (*fun) (&test_argp);