summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2020-02-25 21:03:32 +0100
committerWerner Koch <wk@gnupg.org>2020-02-25 21:03:32 +0100
commit6fc2d7cb8ce9e08cb189608466803ee7c8eb6930 (patch)
treeda5d16a40f913feb018dc626504aff86b676b945 /tests
parentca79d5edee8c6d93575708643ec825f81107e624 (diff)
downloadlibgpg-error-6fc2d7cb8ce9e08cb189608466803ee7c8eb6930.tar.gz
core: Add parser for meta commands to gpgrt_argparser.
* src/gpg-error.h.in (ARGPARSE_INVALID_META): New (ARGPARSE_UNKNOWN_META, ARGPARSE_UNEXPECTED_META): New. * src/argparse.c (struct _gpgrt_argparse_internal_s): Add flag insysconfig. (initialize): Init flag. Add error strings. (_gpgrt_argparser): Set that flag. (_gpgrt_argparse): Add parsing of meta commands. * tests/etc/t-argparse.conf: Add some test cases. * tests/t-argparse.conf: Ditto. * tests/t-argparse.c (main): Die only after printing all warnings. -- Noe that this is just the framework to add meta commands to the global config file. We also need to get away from fixes test config files and create them on the fly to that we are able to test also errors. GnuPG-bug-id: 4788
Diffstat (limited to 'tests')
-rw-r--r--tests/etc/t-argparse.conf42
-rw-r--r--tests/t-argparse.c5
-rw-r--r--tests/t-argparse.conf3
3 files changed, 36 insertions, 14 deletions
diff --git a/tests/etc/t-argparse.conf b/tests/etc/t-argparse.conf
index 87bff72..0852e71 100644
--- a/tests/etc/t-argparse.conf
+++ b/tests/etc/t-argparse.conf
@@ -3,33 +3,51 @@
# 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]
+[group :staff]
+# These option are applied to all users of the group staff up until
+# the next [group] or [user] statement.
-#[+force]
+[+force]
+# All following option are forced and thus ignored when set in user
+# config files. Valid until the next [user] statement. Take care
+# that there are often "no-", "disable-", or "enable-" versions of
+# options; these should be explictly marked as ignored so that they
+# can't be used to override the force attribute.
-#[ignore]
+[ignore]
# The compliance is set immutable for these users
verbose
+# The next shall raise an error due to the garpage at the end.
+#<off>[+ignore] fooo
+
+
+#[+ignore-all]
+# All options are ignored.
+
+
+[-ignore] # Comment at line end
+# Options wich shall not be ignored. */
#no-verbose
-# (parsing does not stop for a group)
-#[user wk]
-# Options for user wk
+[user john ]
+# Options for user john
-# Change the immutable flag back to mutable.
-#[] compliance gnupg
+# Change the immutable attribute back to mutable.
+[-force]
+#compliance gnupg
-# Default key for wk
+# Default key for user john
my-option 42
# Parsing stops for user WK here.
-#[user *]
+[group * ]
+# Options for all group which have no specific group sections above
+
+[user *]
# Options for all users which have no specific user sections above
# The default algorithm for new keys is set to this.
diff --git a/tests/t-argparse.c b/tests/t-argparse.c
index b2b6e51..4719819 100644
--- a/tests/t-argparse.c
+++ b/tests/t-argparse.c
@@ -88,6 +88,7 @@ main (int argc, char **argv)
) };
int i;
const char *srcdir;
+ int any_warn = 0;
gpgrt_set_strusage (my_strusage);
srcdir = getenv ("srcdir");
@@ -120,7 +121,7 @@ main (int argc, char **argv)
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;
case 500: opt.a_long_one++; break;
- default : pargs.err = ARGPARSE_PRINT_ERROR; break;
+ default : pargs.err = ARGPARSE_PRINT_WARNING; any_warn = 1; break;
}
}
for (i=0; i < argc; i++ )
@@ -148,5 +149,5 @@ main (int argc, char **argv)
(void)fail;
(void)die;
- return 0;
+ return !!any_warn;
}
diff --git a/tests/t-argparse.conf b/tests/t-argparse.conf
index 0bbdd3e..e2c96e2 100644
--- a/tests/t-argparse.conf
+++ b/tests/t-argparse.conf
@@ -3,6 +3,9 @@
# Options applied to all user's config files
echo
+# The next should be flagged as unexpected meta command.
+#<off>[ignore]
+
my-option 4711
verbose