Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mcs / class / Mono.Options / Test / Mono.Options / OptionSetTest.cs
index 666bad54d5b8d90f021a32011c1b3c8f4eab3c0e..790d55dea2d44fe103ff237b95e6e8bbf9c46568 100644 (file)
@@ -46,7 +46,7 @@ using NUnit.Framework;
 #if NDESK_OPTIONS
 namespace Tests.NDesk.Options
 #else
-namespace Tests.Mono.Options
+namespace MonoTests.Mono.Options
 #endif
 {
        class FooConverter : TypeConverter {
@@ -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")); });
                }
 
@@ -269,6 +269,26 @@ namespace Tests.Mono.Options
                                        p, v => { v.Parse (_("-n=")); });
                }
 
+               [Test]
+               public void EnumValues ()
+               {
+                       DayOfWeek a = 0;
+                       OptionSet p = new OptionSet () {
+                               { "a=", (DayOfWeek v) => a = v },
+                       };
+                       p.Parse (_ ("-a=Monday"));
+                       Assert.AreEqual (a, DayOfWeek.Monday);
+                       p.Parse (_ ("-a=tuesday"));
+                       Assert.AreEqual (a, DayOfWeek.Tuesday);
+                       p.Parse (_ ("-a=3"));
+                       Assert.AreEqual (a, DayOfWeek.Wednesday);
+                       p.Parse (_ ("-a=Monday,Tuesday"));
+                       Assert.AreEqual (a, DayOfWeek.Monday | DayOfWeek.Tuesday);
+                       Utils.AssertException (typeof (OptionException),
+                                       "Could not convert string `Noday' to type DayOfWeek for option `-a'.",
+                                       p, v => { v.Parse (_ ("-a=Noday")); });
+               }
+
                [Test]
                public void BooleanValues ()
                {
@@ -354,10 +374,10 @@ namespace Tests.Mono.Options
                                        p, v => { v.Parse (_("-a", "-b")); });
                        Assert.AreEqual (a, "-b");
                        Utils.AssertException (typeof(ArgumentNullException),
-                                       "Argument cannot be null.\nParameter name: option",
+                                       $"Value cannot be null.{Environment.NewLine}Parameter name: option",
                                        p, v => { v.Add ((Option) null); });
                        Utils.AssertException (typeof(ArgumentNullException),
-                                       "Argument cannot be null.\nParameter name: header",
+                                       $"Value cannot be null.{Environment.NewLine}Parameter name: header",
                                        p, v => { v.Add ((string) null); });
 
                        // bad type
@@ -370,14 +390,14 @@ 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), 
-                                       "Argument cannot be null.\nParameter name: action",
+                                       $"Value cannot be null.{Environment.NewLine}Parameter name: action",
                                        p, v => { v.Add ("foo", (Action<string>) null); });
                        Utils.AssertException (typeof(ArgumentException), 
-                                       "Cannot provide maxValueCount of 2 for OptionValueType.None.\nParameter name: maxValueCount",
+                                       $"Cannot provide maxValueCount of 2 for OptionValueType.None.{Environment.NewLine}Parameter name: maxValueCount",
                                        p, v => { v.Add ("foo", (k, val) => {/* ignore */}); });
                }
 
@@ -752,7 +772,7 @@ namespace Tests.Mono.Options
                        Utils.AssertException (typeof(ArgumentException), "prototypes must be null!",
                                        p, v => { v.Add ("N|NUM=", (int n) => {}); });
                        Utils.AssertException (typeof(ArgumentNullException),
-                                       "Argument cannot be null.\nParameter name: option",
+                                       $"Value cannot be null.{Environment.NewLine}Parameter name: option",
                                        p, v => { v.GetOptionForName (null); });
                }
 
@@ -880,6 +900,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);
+                       }
+               }
        }
 }