X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-argp.c;h=7da426f066167835de9d75a298b97dbd3e13d50c;hb=88418d5fd24c99aac393d3e2f564f6939e4e2fe3;hp=7f58ae0df634d1a3b812312304b8bbadd2764cc1;hpb=6b2ebc2a29a08c189e688179b04345e35d95af4f;p=gnulib.git diff --git a/tests/test-argp.c b/tests/test-argp.c index 7f58ae0df..7da426f06 100644 --- a/tests/test-argp.c +++ b/tests/test-argp.c @@ -1,5 +1,5 @@ /* Test suite for argp. - Copyright (C) 2006-2007, 2009-2010 Free Software Foundation, Inc. + Copyright (C) 2006-2007, 2009-2011 Free Software Foundation, Inc. This file is part of the GNUlib Library. This program is free software: you can redistribute it and/or modify @@ -34,6 +34,7 @@ struct test_args int test; int verbose; char *file; + int read; char *hidden; int opt; char *optional; @@ -47,6 +48,7 @@ static struct argp_option group1_option[] = { { "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 }, + { "read", 'r', NULL, OPTION_ALIAS, NULL, 1 }, { "hidden", 'H', "FILE", OPTION_HIDDEN, "Hidden option", 1 }, { NULL, 0, NULL, 0, NULL, 0 } }; @@ -62,6 +64,9 @@ group1_parser (int key, char *arg, struct argp_state *state) args->verbose++; break; + case 'r': + args->read = 1; + /* fall through */ case 'f': args->file = arg; break; @@ -257,20 +262,20 @@ struct argp test_argp = { #define INIT_TEST_COMMON(n) \ int argc = NARGS (argv); \ struct test_args test_args; \ - init_args(test_args); \ + init_args (test_args); \ test_number = n; #define INIT_TEST1(n, arg1) \ char *argv[] = { ARGV0, arg1, NULL }; \ - INIT_TEST_COMMON(n) + INIT_TEST_COMMON (n) #define INIT_TEST2(n, arg1, arg2) \ char *argv[] = { ARGV0, arg1, arg2, NULL }; \ - INIT_TEST_COMMON(n) + INIT_TEST_COMMON (n) #define INIT_TEST3(n, arg1, arg2, arg3) \ char *argv[] = { ARGV0, arg1, arg2, arg3, NULL }; \ - INIT_TEST_COMMON(n) + INIT_TEST_COMMON (n) int test_number; unsigned failure_count = 0; @@ -343,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, const char *val, const char *a) { int index; if (argp_parse (argp, argc, argv, 0, &index, args)) @@ -430,6 +435,14 @@ test14 (struct argp *argp) fail ("option not processed"); } +void +test15 (struct argp *argp) +{ + INIT_TEST2 (1, "-r", "FILE"); + test_file (argp, argc, argv, &test_args); + if (!test_args.read) + fail ("short alias not recognized properly"); +} typedef void (*test_fp) (struct argp *argp); @@ -438,7 +451,7 @@ test_fp test_fun[] = { test1, test2, test3, test4, test5, test6, test7, test8, test9, test10, test11, test12, - test13, test14, + test13, test14, test15, NULL };