diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/etc/t-argparse.conf | 36 | ||||
-rw-r--r-- | tests/t-argparse.c | 42 | ||||
-rw-r--r-- | tests/t-argparse.conf | 8 |
4 files changed, 80 insertions, 8 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 39ca241..2d199da 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -25,6 +25,8 @@ else extra_includes = endif +EXTRA_DIST = t-argparse.conf etc/t-argparse.conf + gpg_error_lib = ../src/libgpg-error.la TESTS = t-version t-strerror t-syserror t-lock t-printf t-poll t-b64 \ diff --git a/tests/etc/t-argparse.conf b/tests/etc/t-argparse.conf new file mode 100644 index 0000000..87bff72 --- /dev/null +++ b/tests/etc/t-argparse.conf @@ -0,0 +1,36 @@ +# Global test config file for t-argparse + +# Options applied to all user's config files +#verbose + +#[user :staff] +# These option are applied to all users the group staff up until the +# next [user statement] + +#[+force] + +#[ignore] + +# The compliance is set immutable for these users +verbose + +#no-verbose + + +# (parsing does not stop for a group) +#[user wk] +# Options for user wk + +# Change the immutable flag back to mutable. +#[] compliance gnupg + +# Default key for wk +my-option 42 + +# Parsing stops for user WK here. + +#[user *] +# Options for all users which have no specific user sections above + +# The default algorithm for new keys is set to this. +a-long-option diff --git a/tests/t-argparse.c b/tests/t-argparse.c index 277d860..b2b6e51 100644 --- a/tests/t-argparse.c +++ b/tests/t-argparse.c @@ -1,5 +1,5 @@ /* t-argparse.c - Check the argparse API - * Copyright (C) 2018 g10 Code GmbH + * Copyright (C) 2018, 2020 g10 Code GmbH * * This file is part of Libgpg-error. * @@ -27,7 +27,8 @@ #include <string.h> #include <assert.h> -#include "../src/gpg-error.h" +#define PGM "t-argparse" +#include "t-common.h" static struct { @@ -49,7 +50,7 @@ my_strusage (int level) switch (level) { - case 9: p = "GPL-2.0-or-later"; break; + case 9: p = "LGPL-2.1-or-later"; break; case 11: p = "t-argparse"; break; @@ -74,26 +75,47 @@ main (int argc, char **argv) ARGPARSE_s_n('s', "street","|Straße|set the name of the street to Straße"), ARGPARSE_o_i('m', "my-option", 0), ARGPARSE_s_n(500, "a-long-option", 0 ), + ARGPARSE_conffile(501, "options", "|FILE|read options from FILE"), + ARGPARSE_noconffile(502, "no-options", "Ignore conf files"), ARGPARSE_end() }; gpgrt_argparse_t pargs = { &argc, &argv, (ARGPARSE_FLAG_ALL | ARGPARSE_FLAG_MIXED - | ARGPARSE_FLAG_ONEDASH) }; + | ARGPARSE_FLAG_ONEDASH + | ARGPARSE_FLAG_SYS + | ARGPARSE_FLAG_USER + /* | ARGPARSE_FLAG_VERBOSE */ + ) }; int i; + const char *srcdir; gpgrt_set_strusage (my_strusage); - - - while (gpgrt_argparse (NULL, &pargs, opts)) + srcdir = getenv ("srcdir"); + if (!srcdir) + srcdir = "."; + gpgrt_set_confdir (GPGRT_CONFDIR_USER, srcdir); + { + char *p = gpgrt_fnameconcat (srcdir, "etc", NULL); + gpgrt_set_confdir (GPGRT_CONFDIR_SYS, p); + xfree (p); + } + + while (gpgrt_argparser (&pargs, opts, PGM".conf")) { + /* printf ("got option %d\n", pargs.r_opt); */ switch (pargs.r_opt) { + case ARGPARSE_CONFFILE: + printf ("current conffile='%s'\n", + pargs.r.ret_str? pargs.r.ret_str: "[cmdline]"); + break; case ARGPARSE_IS_ARG : printf ("arg='%s'\n", pargs.r.ret_str); break; + case 'v': opt.verbose++; break; case 'e': opt.echo++; break; - case 'd': opt.debug++; break; + case 'd': opt.debug++; debug=1;break; case 'o': opt.outfile = pargs.r.ret_str; break; case 'c': opt.crf = pargs.r_type? pargs.r.ret_str:"a.crf"; break; case 'm': opt.myopt = pargs.r_type? pargs.r.ret_int : 1; break; @@ -122,5 +144,9 @@ main (int argc, char **argv) gpgrt_argparse (NULL, &pargs, NULL); + (void)show; + (void)fail; + (void)die; + return 0; } diff --git a/tests/t-argparse.conf b/tests/t-argparse.conf new file mode 100644 index 0000000..0bbdd3e --- /dev/null +++ b/tests/t-argparse.conf @@ -0,0 +1,8 @@ +# User test config file for t-argparse + +# Options applied to all user's config files +echo + +my-option 4711 + +verbose |