diff options
author | Jonathan Pryor <jonpryor@vt.edu> | 2013-12-06 00:39:05 +0400 |
---|---|---|
committer | Jonathan Pryor <jonpryor@vt.edu> | 2013-12-06 00:43:35 +0400 |
commit | a699e7444e8ff4426197d4bd3a9607d204ee7b0f (patch) | |
tree | b0f8b98417ce4c130bd8acc9b60459a13cd13545 /mcs/class/Mono.Options | |
parent | 37e3c51b13ccfc964103ae2bcfe7a5aeb7008bd7 (diff) |
[Mono.Options] Improve error message for badly bundled args.
mono(1) supports a "joined" verbose flag, `mono -v-v-v-v`, which
Mono.Options doesn't support. Attempting to use it, however, resulted
in a "weird" error message:
$ csharp -r:Mono.Options.dll
csharp> using Mono.Options;
csharp> var p = new OptionSet { { "v", v => {} } };
csharp> p.Parse (new[]{"-v-v-v"});
Mono.Options.OptionException: Cannot bundle unregistered option '--'.
...
This looks very weird to users because they never used a "--" option,
and if they had then `--` would have disabled further option
processing (as documented and implemented in OptionSet.Parse()).
Confusion all around.
Improve the error message so that it instead generates:
Mono.Options.OptionException: Cannot use unregistered option '-' in bundle '-v-v-v'.
That way the user gets the full context of where this "unregistered
option" came from.
Diffstat (limited to 'mcs/class/Mono.Options')
-rw-r--r-- | mcs/class/Mono.Options/Mono.Options/Options.cs | 2 | ||||
-rw-r--r-- | mcs/class/Mono.Options/Test/Mono.Options/OptionSetTest.cs | 20 |
2 files changed, 19 insertions, 3 deletions
diff --git a/mcs/class/Mono.Options/Mono.Options/Options.cs b/mcs/class/Mono.Options/Mono.Options/Options.cs index 5af7fe0f387..0fd21ab5a93 100644 --- a/mcs/class/Mono.Options/Mono.Options/Options.cs +++ b/mcs/class/Mono.Options/Mono.Options/Options.cs @@ -1135,7 +1135,7 @@ namespace Mono.Options if (i == 0) return false; throw new OptionException (string.Format (localizer ( - "Cannot bundle unregistered option '{0}'."), opt), opt); + "Cannot use unregistered option '{0}' in bundle '{1}'."), rn, f + n), null); } p = this [rn]; switch (p.OptionValueType) { diff --git a/mcs/class/Mono.Options/Test/Mono.Options/OptionSetTest.cs b/mcs/class/Mono.Options/Test/Mono.Options/OptionSetTest.cs index 666bad54d5b..086c6d9c8c2 100644 --- a/mcs/class/Mono.Options/Test/Mono.Options/OptionSetTest.cs +++ b/mcs/class/Mono.Options/Test/Mono.Options/OptionSetTest.cs @@ -193,7 +193,7 @@ namespace Tests.Mono.Options Assert.AreEqual (libs [1], null); Utils.AssertException (typeof(OptionException), - "Cannot bundle unregistered option '-V'.", + "Cannot use unregistered option 'V' in bundle '-EVALUENOTSUP'.", p, v => { v.Parse (_("-EVALUENOTSUP")); }); } @@ -370,7 +370,7 @@ namespace Tests.Mono.Options // try to bundle with an option requiring a value Utils.AssertException (typeof(OptionException), - "Cannot bundle unregistered option '-z'.", + "Cannot use unregistered option 'z' in bundle '-cz'.", p, v => { v.Parse (_("-cz", "extra")); }); Utils.AssertException (typeof(ArgumentNullException), @@ -880,6 +880,22 @@ namespace Tests.Mono.Options Assert.AreEqual (formats ["baz"][0], "e"); Assert.AreEqual (formats ["baz"][1], "f"); } + + [Test] + public void ReportInvalidDuplication () + { + int verbosity = 0; + var p = new OptionSet () { + { "v", v => verbosity = v != null ? verbosity + 1 : verbosity }, + }; + try { + p.Parse (new []{"-v-v-v"}); + Assert.Fail ("Should not be reached."); + } catch (OptionException e) { + Assert.AreEqual (null, e.OptionName); + Assert.AreEqual ("Cannot use unregistered option '-' in bundle '-v-v-v'.", e.Message); + } + } } } |