aboutsummaryrefslogtreecommitdiffstats
path: root/tests/t-argparse.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/t-argparse.c')
-rw-r--r--tests/t-argparse.c42
1 files changed, 34 insertions, 8 deletions
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;
}