Skip to content
Browse files

more coverage

  • Loading branch information...
1 parent 8eebdb2 commit fe6a62e48ff0bfcc61779d667a91157d41751957 @adrianaisemberg adrianaisemberg committed Oct 30, 2011
View
1 CLAP/CLAP.csproj
@@ -73,6 +73,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CollectionValidationAttribute.cs" />
+ <Compile Include="CoverageExcludeAttribute.cs" />
<Compile Include="ErrorAttribute.cs" />
<Compile Include="FileSystemHelper.cs" />
<Compile Include="FW2Stuff.cs" />
View
1 CLAP/CoverageExcludeAttribute.cs
@@ -0,0 +1 @@
+internal class CoverageExcludeAttribute : System.Attribute { }
View
45 CLAP/Exceptions.cs
@@ -77,6 +77,51 @@ public MissingVerbException()
}
[Serializable]
+ public class MultiParserMissingClassNameException : CommandLineException
+ {
+ public MultiParserMissingClassNameException()
+ : this("Arguments contain no class name", null)
+ {
+ }
+
+ public MultiParserMissingClassNameException(string message, Exception inner) : base(message, inner) { }
+ protected MultiParserMissingClassNameException(
+ System.Runtime.Serialization.SerializationInfo info,
+ System.Runtime.Serialization.StreamingContext context)
+ : base(info, context) { }
+ }
+
+ [Serializable]
+ public class InvalidVerbException : CommandLineException
+ {
+ public InvalidVerbException()
+ : this("Invalid verb: Contains more than two parts.", null)
+ {
+ }
+
+ public InvalidVerbException(string message, Exception inner) : base(message, inner) { }
+ protected InvalidVerbException(
+ System.Runtime.Serialization.SerializationInfo info,
+ System.Runtime.Serialization.StreamingContext context)
+ : base(info, context) { }
+ }
+
+ [Serializable]
+ public class UnknownParserTypeException : CommandLineException
+ {
+ public UnknownParserTypeException(string typeName)
+ : this("Parser type '{0}' not found".FormatWith(typeName), null)
+ {
+ }
+
+ public UnknownParserTypeException(string message, Exception inner) : base(message, inner) { }
+ protected UnknownParserTypeException(
+ System.Runtime.Serialization.SerializationInfo info,
+ System.Runtime.Serialization.StreamingContext context)
+ : base(info, context) { }
+ }
+
+ [Serializable]
public class MissingRequiredArgumentException : CommandLineException
{
public string ParameterName { get; private set; }
View
1 CLAP/FileSystemHelper.cs
@@ -21,6 +21,7 @@ public interface IFileSystem
string ReadAllText(string path);
}
+ [CoverageExclude]
private class FileSystem : IFileSystem
{
public string ReadAllText(string path)
View
25 CLAP/MultiParser.cs
@@ -51,12 +51,12 @@ private void Init()
Register = new ParserRegistration(GetHelpString, ValuesFactory.GetValueForParameter);
}
- public void StaticRun(string[] args)
+ public void RunStatic(string[] args)
{
RunTargets(args, null);
}
- internal void RunTargets(string[] args, params object[] targets)
+ public void RunTargets(string[] args, params object[] targets)
{
// no args
//
@@ -82,7 +82,7 @@ internal void RunTargets(string[] args, params object[] targets)
Debug.Assert(parser != null);
- var index = m_types.IndexOf(parser.Type);
+ var index = m_types.ToList().IndexOf(parser.Type);
Debug.Assert(index >= 0);
@@ -127,17 +127,16 @@ private ParserRunner GetMultiTypesParser(string[] args, object obj, ParserRegist
throw new MissingVerbException();
}
- if (!s_delimiters.Any(d => verb.Contains(d)))
+ if (!verb.Contains(s_delimiters))
{
-#warning TODO:
- throw new Exception("requires dot");
+ throw new MultiParserMissingClassNameException();
}
var parts = verb.Split(s_delimiters, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length > 2)
{
- throw new Exception("parts length != 2");
+ throw new InvalidVerbException();
}
var typeName = parts[0];
@@ -148,7 +147,7 @@ private ParserRunner GetMultiTypesParser(string[] args, object obj, ParserRegist
if (type == null)
{
- throw new Exception("no type");
+ throw new UnknownParserTypeException(typeName);
}
return new ParserRunner(type, registration);
@@ -173,20 +172,24 @@ private ParserRunner GetSingleTypeParser(string[] args, object obj, ParserRegist
// if the verb contains a delimiter - remove the type name from the arg
//
- if (s_delimiters.Any(d => verb.Contains(d)))
+ if (verb.Contains(s_delimiters))
{
var parts = verb.Split(s_delimiters, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length > 2)
{
-#warning TODO:
- throw new Exception("parts length != 2");
+ throw new InvalidVerbException();
}
Debug.Assert(parts.Length == 2);
var typeName = parts[0];
+ if (!type.Name.Equals(typeName, StringComparison.InvariantCultureIgnoreCase))
+ {
+ throw new UnknownParserTypeException(typeName);
+ }
+
args[0] = args[0].Substring(typeName.Length + 1);
}
View
43 CLAP/Parser.cs
@@ -14,12 +14,7 @@ public Parser(params Type[] types)
{
}
- public void Run(string[] args, params object[] targets)
- {
- RunTargets(args, targets);
- }
-
- public static void DynamicRun(string[] args, params object[] targets)
+ public static void Run(string[] args, params object[] targets)
{
Debug.Assert(targets.Any());
Debug.Assert(targets.All(t => t != null));
@@ -30,49 +25,49 @@ public static void DynamicRun(string[] args, params object[] targets)
}
public static void Run<T>(string[] args)
- { new Parser<T>().RunTargets(args); }
+ { new Parser<T>().RunStatic(args); }
public static void Run<T>(string[] args, T t)
- { new Parser<T>().Run(args, t); }
+ { new Parser<T>().RunTargets(args, t); }
public static void Run<T1, T2>(string[] args)
- { new Parser<T1, T2>().RunTargets(args); }
+ { new Parser<T1, T2>().RunStatic(args); }
public static void Run<T1, T2>(string[] args, T1 t1, T2 t2)
- { new Parser<T1, T2>().Run(args, t1, t2); }
+ { new Parser<T1, T2>().RunTargets(args, t1, t2); }
public static void Run<T1, T2, T3>(string[] args)
- { new Parser<T1, T2, T3>().RunTargets(args); }
+ { new Parser<T1, T2, T3>().RunStatic(args); }
public static void Run<T1, T2, T3>(string[] args, T1 t1, T2 t2, T3 t3)
- { new Parser<T1, T2, T3>().Run(args, t1, t2, t3); }
+ { new Parser<T1, T2, T3>().RunTargets(args, t1, t2, t3); }
public static void Run<T1, T2, T3, T4>(string[] args)
- { new Parser<T1, T2, T3, T4>().RunTargets(args); }
+ { new Parser<T1, T2, T3, T4>().RunStatic(args); }
public static void Run<T1, T2, T3, T4>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4)
- { new Parser<T1, T2, T3, T4>().Run(args, t1, t2, t3, t4); }
+ { new Parser<T1, T2, T3, T4>().RunTargets(args, t1, t2, t3, t4); }
public static void Run<T1, T2, T3, T4, T5>(string[] args)
- { new Parser<T1, T2, T3, T4, T5>().RunTargets(args); }
+ { new Parser<T1, T2, T3, T4, T5>().RunStatic(args); }
public static void Run<T1, T2, T3, T4, T5>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
- { new Parser<T1, T2, T3, T4, T5>().Run(args, t1, t2, t3, t4, t5); }
+ { new Parser<T1, T2, T3, T4, T5>().RunTargets(args, t1, t2, t3, t4, t5); }
public static void Run<T1, T2, T3, T4, T5, T6>(string[] args)
- { new Parser<T1, T2, T3, T4, T5, T6>().RunTargets(args); }
+ { new Parser<T1, T2, T3, T4, T5, T6>().RunStatic(args); }
public static void Run<T1, T2, T3, T4, T5, T6>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
- { new Parser<T1, T2, T3, T4, T5, T6>().Run(args, t1, t2, t3, t4, t5, t6); }
+ { new Parser<T1, T2, T3, T4, T5, T6>().RunTargets(args, t1, t2, t3, t4, t5, t6); }
public static void Run<T1, T2, T3, T4, T5, T6, T7>(string[] args)
- { new Parser<T1, T2, T3, T4, T5, T6, T7>().RunTargets(args); }
+ { new Parser<T1, T2, T3, T4, T5, T6, T7>().RunStatic(args); }
public static void Run<T1, T2, T3, T4, T5, T6, T7>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
- { new Parser<T1, T2, T3, T4, T5, T6, T7>().Run(args, t1, t2, t3, t4, t5, t6, t7); }
+ { new Parser<T1, T2, T3, T4, T5, T6, T7>().RunTargets(args, t1, t2, t3, t4, t5, t6, t7); }
public static void Run<T1, T2, T3, T4, T5, T6, T7, T8>(string[] args)
- { new Parser<T1, T2, T3, T4, T5, T6, T7, T8>().RunTargets(args); }
+ { new Parser<T1, T2, T3, T4, T5, T6, T7, T8>().RunStatic(args); }
public static void Run<T1, T2, T3, T4, T5, T6, T7, T8>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
- { new Parser<T1, T2, T3, T4, T5, T6, T7, T8>().Run(args, t1, t2, t3, t4, t5, t6, t7, t8); }
+ { new Parser<T1, T2, T3, T4, T5, T6, T7, T8>().RunTargets(args, t1, t2, t3, t4, t5, t6, t7, t8); }
public static void Run<T1, T2, T3, T4, T5, T6, T7, T8, T9>(string[] args)
- { new Parser<T1, T2, T3, T4, T5, T6, T7, T8, T9>().RunTargets(args); }
+ { new Parser<T1, T2, T3, T4, T5, T6, T7, T8, T9>().RunStatic(args); }
public static void Run<T1, T2, T3, T4, T5, T6, T7, T8, T9>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9)
- { new Parser<T1, T2, T3, T4, T5, T6, T7, T8, T9>().Run(args, t1, t2, t3, t4, t5, t6, t7, t8, t9); }
+ { new Parser<T1, T2, T3, T4, T5, T6, T7, T8, T9>().RunTargets(args, t1, t2, t3, t4, t5, t6, t7, t8, t9); }
}
public class Parser<T> : MultiParser
View
20 CLAP/Utils.cs
@@ -131,26 +131,14 @@ public static string ToSafeString(this object obj, string nullValue)
return obj == null ? nullValue : obj.ToString();
}
- public static int IndexOf<T>(this IEnumerable<T> collection, T item) where T : class
+ public static bool StartsWith(this string str, IEnumerable<string> values)
{
- var index = -1;
-
- foreach (var i in collection)
- {
- index++;
-
- if (i == item)
- {
- return index;
- }
- }
-
- return -1;
+ return values.Any(v => str.StartsWith(v));
}
- public static bool StartsWith(this string str, IEnumerable<string> values)
+ public static bool Contains(this string str, IEnumerable<string> values)
{
- return values.Any(v => str.StartsWith(v));
+ return values.Any(v => str.Contains(v));
}
}
}
View
516 Tests/MultiParserTests.cs
@@ -24,7 +24,7 @@ public void TearDown()
}
[Test]
- public void MultiParser_Run_HappyFlow()
+ public void MultiParser_Run_HappyFlow_1()
{
var mock = new MethodInvokerMock();
@@ -55,6 +55,37 @@ public void MultiParser_Run_HappyFlow()
}
[Test]
+ public void MultiParser_Run_HappyFlow_2()
+ {
+ var mock = new MethodInvokerMock();
+
+ var called = false;
+
+ mock.Action = (method, obj, parameters) =>
+ {
+ called = true;
+
+ Assert.IsTrue(method.Name == "Print");
+ Assert.IsTrue(method.DeclaringType == typeof(Sample_02));
+ Assert.IsTrue(parameters.Contains(10));
+ Assert.IsTrue(parameters.Contains("aaa"));
+ };
+
+ MethodInvoker.Invoker = mock;
+
+ var p = new Parser(typeof(Sample_02), typeof(Sample_03));
+
+ p.RunTargets(new[]
+ {
+ "sample_02.print",
+ "-c=10",
+ "-prefix=aaa",
+ }, new Sample_02(), new Sample_03());
+
+ Assert.IsTrue(called);
+ }
+
+ [Test]
public void MultiParser_Run_OneParser()
{
var mock = new MethodInvokerMock();
@@ -97,6 +128,489 @@ public void MultiParser_Run_NoVerb_Exception()
"-prefix=aaa",
}, new Sample_03(), new Sample_02());
}
+
+ [Test]
+ [ExpectedException(typeof(MultiParserMissingClassNameException))]
+ public void MultiParser_Run_NoDelimiter_Exception_1()
+ {
+ var p = new Parser<Sample_03, Sample_02>();
+
+ p.Run(new[]
+ {
+ "sample02print",
+ "-c=10",
+ "-prefix=aaa",
+ }, new Sample_03(), new Sample_02());
+ }
+
+ [Test]
+ [ExpectedException(typeof(MultiParserMissingClassNameException))]
+ public void MultiParser_Run_NoDelimiter_Exception_2()
+ {
+ var p = new Parser<Sample_03, Sample_02>();
+
+ p.Run(new[]
+ {
+ "print",
+ "-c=10",
+ "-prefix=aaa",
+ }, new Sample_03(), new Sample_02());
+ }
+
+ [Test]
+ [ExpectedException(typeof(InvalidVerbException))]
+ public void MultiParser_Run_TooMuchDelimiters_Exception_1()
+ {
+ var p = new Parser<Sample_03>();
+
+ p.Run(new[]
+ {
+ "sample_03.print.foo",
+ "-c=10",
+ "-prefix=aaa",
+ }, new Sample_03());
+ }
+
+ [Test]
+ [ExpectedException(typeof(InvalidVerbException))]
+ public void MultiParser_Run_TooMuchDelimiters_Exception_2()
+ {
+ var p = new Parser<Sample_03, Sample_02>();
+
+ p.Run(new[]
+ {
+ "sample_03.print.foo",
+ "-c=10",
+ "-prefix=aaa",
+ }, new Sample_03(), new Sample_02());
+ }
+
+ [Test]
+ [ExpectedException(typeof(UnknownParserTypeException))]
+ public void MultiParser_Run_MissingType_Exception_1()
+ {
+ var p = new Parser<Sample_03>();
+
+ p.Run(new[]
+ {
+ "sample_03foo.print",
+ "-c=10",
+ "-prefix=aaa",
+ }, new Sample_03());
+ }
+
+ [Test]
+ [ExpectedException(typeof(UnknownParserTypeException))]
+ public void MultiParser_Run_MissingType_Exception_2()
+ {
+ var p = new Parser<Sample_03, Sample_02>();
+
+ p.Run(new[]
+ {
+ "sample_03foo.print",
+ "-c=10",
+ "-prefix=aaa",
+ }, new Sample_03(), new Sample_02());
+ }
+
+ [Test]
+ [ExpectedException(typeof(MissingRequiredArgumentException))]
+ public void MultiParser_Run_MissingRequiredArgument()
+ {
+ var mock = new MethodInvokerMock();
+
+ var called = false;
+
+ mock.Action = (method, obj, parameters) =>
+ {
+ called = true;
+
+ Assert.IsTrue(method.Name == "Print");
+ Assert.IsTrue(method.DeclaringType == typeof(Sample_07));
+ Assert.IsTrue(parameters.Contains(10));
+ };
+
+ MethodInvoker.Invoker = mock;
+
+ var p = new Parser<Sample_02, Sample_03, Sample_04, Sample_06, Sample_07>();
+
+ p.Run(new[]
+ {
+ "sample_07.print",
+ "-count=10",
+ },
+ new Sample_02(),
+ new Sample_03(),
+ new Sample_04(),
+ new Sample_06(),
+ new Sample_07());
+
+ Assert.IsTrue(called);
+ }
+
+ [Test]
+ public void MultiParser_Run_HappyFlow_1_Type()
+ {
+ var mock = new MethodInvokerMock();
+
+ var called = false;
+
+ mock.Action = (method, obj, parameters) =>
+ {
+ called = true;
+
+ Assert.IsTrue(method.Name == "Print");
+ Assert.IsTrue(method.DeclaringType == typeof(Sample_02));
+ Assert.IsTrue(parameters.Contains(10));
+ Assert.IsTrue(parameters.Contains("aaa"));
+ };
+
+ MethodInvoker.Invoker = mock;
+
+ var p = new Parser<Sample_02>();
+
+ p.Run(new[]
+ {
+ "sample_02.print",
+ "-c=10",
+ "-prefix=aaa",
+ }, new Sample_02());
+
+ Assert.IsTrue(called);
+ }
+
+ [Test]
+ public void MultiParser_Run_HappyFlow_2_Types()
+ {
+ var mock = new MethodInvokerMock();
+
+ var called = false;
+
+ mock.Action = (method, obj, parameters) =>
+ {
+ called = true;
+
+ Assert.IsTrue(method.Name == "Print");
+ Assert.IsTrue(method.DeclaringType == typeof(Sample_02));
+ Assert.IsTrue(parameters.Contains(10));
+ Assert.IsTrue(parameters.Contains("aaa"));
+ };
+
+ MethodInvoker.Invoker = mock;
+
+ var p = new Parser<Sample_02, Sample_03>();
+
+ p.Run(new[]
+ {
+ "sample_02.print",
+ "-c=10",
+ "-prefix=aaa",
+ }, new Sample_02(), new Sample_03());
+
+ Assert.IsTrue(called);
+ }
+
+ [Test]
+ public void MultiParser_Run_HappyFlow_3_Types()
+ {
+ var mock = new MethodInvokerMock();
+
+ var called = false;
+
+ mock.Action = (method, obj, parameters) =>
+ {
+ called = true;
+
+ Assert.IsTrue(method.Name == "Print");
+ Assert.IsTrue(method.DeclaringType == typeof(Sample_04));
+ Assert.IsTrue(parameters.Contains(Case.Upper));
+ Assert.IsTrue(parameters.Contains("aaa"));
+ };
+
+ MethodInvoker.Invoker = mock;
+
+ var p = new Parser<Sample_02, Sample_03, Sample_04>();
+
+ p.Run(new[]
+ {
+ "sample_04.print",
+ "-c=Upper",
+ "-prefix=aaa",
+ },
+ new Sample_02(),
+ new Sample_03(),
+ new Sample_04());
+
+ Assert.IsTrue(called);
+ }
+
+ [Test]
+ public void MultiParser_Run_HappyFlow_4_Types()
+ {
+ var mock = new MethodInvokerMock();
+
+ var called = false;
+
+ mock.Action = (method, obj, parameters) =>
+ {
+ called = true;
+
+ Assert.IsTrue(method.Name == "Print");
+ Assert.IsTrue(method.DeclaringType == typeof(Sample_06));
+ Assert.IsTrue(parameters.Contains(10));
+ Assert.IsTrue(parameters.Contains(Case.Lower));
+ };
+
+ MethodInvoker.Invoker = mock;
+
+ var p = new Parser<Sample_02, Sample_03, Sample_04, Sample_06>();
+
+ p.Run(new[]
+ {
+ "sample_06.print",
+ "-count=10",
+ },
+ new Sample_02(),
+ new Sample_03(),
+ new Sample_04(),
+ new Sample_06());
+
+ Assert.IsTrue(called);
+ }
+
+ [Test]
+ public void MultiParser_Run_HappyFlow_5_Types()
+ {
+ var mock = new MethodInvokerMock();
+
+ var called = false;
+
+ mock.Action = (method, obj, parameters) =>
+ {
+ called = true;
+
+ Assert.IsTrue(method.Name == "Print");
+ Assert.IsTrue(method.DeclaringType == typeof(Sample_07));
+ Assert.IsTrue(parameters.Contains(10));
+ Assert.IsTrue(parameters.Contains("a"));
+ };
+
+ MethodInvoker.Invoker = mock;
+
+ var p = new Parser<Sample_02, Sample_03, Sample_04, Sample_06, Sample_07>();
+
+ p.Run(new[]
+ {
+ "sample_07.print",
+ "-count=10",
+ "-prefix=a",
+ },
+ new Sample_02(),
+ new Sample_03(),
+ new Sample_04(),
+ new Sample_06(),
+ new Sample_07());
+
+ Assert.IsTrue(called);
+ }
+
+ [Test]
+ public void MultiParser_Run_HappyFlow_6_Types()
+ {
+ var mock = new MethodInvokerMock();
+
+ var called = false;
+
+ mock.Action = (method, obj, parameters) =>
+ {
+ called = true;
+
+ Assert.IsTrue(method.Name == "PrintEnums");
+ Assert.IsTrue(method.DeclaringType == typeof(Sample_08));
+ Assert.IsTrue(parameters.Contains("abc"));
+ Assert.IsTrue(parameters.Any(param =>
+ {
+ return param.GetType() == typeof(Case[]) &&
+ ((Case[])param).Length == 2 &&
+ ((Case[])param)[0] == Case.Upper &&
+ ((Case[])param)[1] == Case.Lower;
+ }));
+ };
+
+ MethodInvoker.Invoker = mock;
+
+ var p = new Parser<Sample_02, Sample_03, Sample_04, Sample_06, Sample_07, Sample_08>();
+
+ p.Run(new[]
+ {
+ "sample_08.PrintEnums",
+ "-enums=Upper,Lower",
+ "-prefix=abc",
+ },
+ new Sample_02(),
+ new Sample_03(),
+ new Sample_04(),
+ new Sample_06(),
+ new Sample_07(),
+ new Sample_08());
+
+ Assert.IsTrue(called);
+ }
+
+ [Test]
+ public void MultiParser_Run_HappyFlow_7_Types()
+ {
+ var mock = new MethodInvokerMock();
+
+ var called = false;
+
+ mock.Action = (method, obj, parameters) =>
+ {
+ called = true;
+
+ Assert.IsTrue(method.Name == "Print");
+ Assert.IsTrue(method.DeclaringType == typeof(Sample_07));
+ Assert.IsTrue(parameters.Contains(10));
+ Assert.IsTrue(parameters.Contains("a"));
+ };
+
+ MethodInvoker.Invoker = mock;
+
+ var p = new Parser<Sample_02, Sample_03, Sample_04, Sample_06, Sample_07, Sample_08, Sample_10>();
+
+ p.Run(new[]
+ {
+ "sample_07.print",
+ "-count=10",
+ "-prefix=a",
+ },
+ new Sample_02(),
+ new Sample_03(),
+ new Sample_04(),
+ new Sample_06(),
+ new Sample_07(),
+ new Sample_08(),
+ new Sample_10());
+
+ Assert.IsTrue(called);
+ }
+
+ [Test]
+ public void MultiParser_Run_HappyFlow_8_Types()
+ {
+ var mock = new MethodInvokerMock();
+
+ var called = false;
+
+ mock.Action = (method, obj, parameters) =>
+ {
+ if (called)
+ {
+ Assert.IsTrue(method.Name == "Print2");
+ Assert.IsTrue(method.DeclaringType == typeof(Sample_10));
+ Assert.IsTrue(parameters.Contains("fooblah"));
+ }
+ else
+ {
+ Assert.IsTrue(method.Name == "Bar");
+ Assert.IsTrue(method.DeclaringType == typeof(Sample_10));
+ }
+
+ called = true;
+ };
+
+ MethodInvoker.Invoker = mock;
+
+ var p = new Parser<Sample_02, Sample_03, Sample_04, Sample_06, Sample_07, Sample_08, Sample_10, Sample_12>();
+
+ p.Run(new[]
+ {
+ "sample_10.print2",
+ "-bar",
+ "-str=fooblah",
+ },
+ new Sample_02(),
+ new Sample_03(),
+ new Sample_04(),
+ new Sample_06(),
+ new Sample_07(),
+ new Sample_08(),
+ new Sample_10(),
+ new Sample_12());
+
+ Assert.IsTrue(called);
+ }
+
+ [Test]
+ public void MultiParser_Run_HappyFlow_9_Types()
+ {
+ var mock = new MethodInvokerMock();
+
+ var called = false;
+
+ mock.Action = (method, obj, parameters) =>
+ {
+ Assert.IsTrue(method.Name == "Zoo");
+ Assert.IsTrue(method.DeclaringType == typeof(Sample_28));
+ Assert.IsTrue(parameters.Contains(98));
+
+ called = true;
+ };
+
+ MethodInvoker.Invoker = mock;
+
+ var p = new Parser<Sample_02, Sample_03, Sample_04, Sample_06, Sample_07, Sample_08, Sample_10, Sample_12, Sample_28>();
+
+ p.Run(new[]
+ {
+ "sample_28.zoo",
+ "-n=98",
+ },
+ new Sample_02(),
+ new Sample_03(),
+ new Sample_04(),
+ new Sample_06(),
+ new Sample_07(),
+ new Sample_08(),
+ new Sample_10(),
+ new Sample_12(),
+ new Sample_28());
+
+ Assert.IsTrue(called);
+ }
+
+ [Test]
+ public void _Coverage_StaticRun()
+ {
+ Parser.Run(new[] { "StaticSample_09.Foo" }, new StaticSample_01(), new StaticSample_02(), new StaticSample_03(), new StaticSample_04(), new StaticSample_05(), new StaticSample_06(), new StaticSample_07(), new StaticSample_08(), new StaticSample_09(), new StaticSample_10());
+
+ Parser.Run<StaticSample_09>(new[] { "StaticSample_09.Foo" });
+ Parser.Run(new[] { "StaticSample_09.Foo" }, new StaticSample_09());
+
+ Parser.Run<StaticSample_08, StaticSample_09>(new[] { "StaticSample_09.Foo" });
+ Parser.Run(new[] { "StaticSample_09.Foo" }, new StaticSample_08(), new StaticSample_09());
+
+ Parser.Run<StaticSample_07, StaticSample_08, StaticSample_09>(new[] { "StaticSample_09.Foo" });
+ Parser.Run(new[] { "StaticSample_09.Foo" }, new StaticSample_07(), new StaticSample_08(), new StaticSample_09());
+
+ Parser.Run<StaticSample_06, StaticSample_07, StaticSample_08, StaticSample_09>(new[] { "StaticSample_09.Foo" });
+ Parser.Run(new[] { "StaticSample_09.Foo" }, new StaticSample_06(), new StaticSample_07(), new StaticSample_08(), new StaticSample_09());
+
+ Parser.Run<StaticSample_05, StaticSample_06, StaticSample_07, StaticSample_08, StaticSample_09>(new[] { "StaticSample_09.Foo" });
+ Parser.Run(new[] { "StaticSample_09.Foo" }, new StaticSample_05(), new StaticSample_06(), new StaticSample_07(), new StaticSample_08(), new StaticSample_09());
+
+ Parser.Run<StaticSample_04, StaticSample_05, StaticSample_06, StaticSample_07, StaticSample_08, StaticSample_09>(new[] { "StaticSample_09.Foo" });
+ Parser.Run(new[] { "StaticSample_09.Foo" }, new StaticSample_04(), new StaticSample_05(), new StaticSample_06(), new StaticSample_07(), new StaticSample_08(), new StaticSample_09());
+
+ Parser.Run<StaticSample_03, StaticSample_04, StaticSample_05, StaticSample_06, StaticSample_07, StaticSample_08, StaticSample_09>(new[] { "StaticSample_09.Foo" });
+ Parser.Run(new[] { "StaticSample_09.Foo" }, new StaticSample_03(), new StaticSample_04(), new StaticSample_05(), new StaticSample_06(), new StaticSample_07(), new StaticSample_08(), new StaticSample_09());
+
+ Parser.Run<StaticSample_02, StaticSample_03, StaticSample_04, StaticSample_05, StaticSample_06, StaticSample_07, StaticSample_08, StaticSample_09>(new[] { "StaticSample_09.Foo" });
+ Parser.Run(new[] { "StaticSample_09.Foo" }, new StaticSample_02(), new StaticSample_03(), new StaticSample_04(), new StaticSample_05(), new StaticSample_06(), new StaticSample_07(), new StaticSample_08(), new StaticSample_09());
+
+ Parser.Run<StaticSample_01, StaticSample_02, StaticSample_03, StaticSample_04, StaticSample_05, StaticSample_06, StaticSample_07, StaticSample_08, StaticSample_09>(new[] { "StaticSample_09.Foo" });
+ Parser.Run(new[] { "StaticSample_09.Foo" }, new StaticSample_01(), new StaticSample_02(), new StaticSample_03(), new StaticSample_04(), new StaticSample_05(), new StaticSample_06(), new StaticSample_07(), new StaticSample_08(), new StaticSample_09());
+ }
}
public class MethodInvokerMock : IMethodInvoker
View
15 Tests/StaticSamples.cs
@@ -0,0 +1,15 @@
+using CLAP;
+
+namespace Tests
+{
+ public class StaticSample_01 { [Verb] public static void Foo() { } [Verb] public void Bar() { } }
+ public class StaticSample_02 { [Verb] public static void Foo() { } [Verb] public void Bar() { } }
+ public class StaticSample_03 { [Verb] public static void Foo() { } [Verb] public void Bar() { } }
+ public class StaticSample_04 { [Verb] public static void Foo() { } [Verb] public void Bar() { } }
+ public class StaticSample_05 { [Verb] public static void Foo() { } [Verb] public void Bar() { } }
+ public class StaticSample_06 { [Verb] public static void Foo() { } [Verb] public void Bar() { } }
+ public class StaticSample_07 { [Verb] public static void Foo() { } [Verb] public void Bar() { } }
+ public class StaticSample_08 { [Verb] public static void Foo() { } [Verb] public void Bar() { } }
+ public class StaticSample_09 { [Verb] public static void Foo() { } [Verb] public void Bar() { } }
+ public class StaticSample_10 { [Verb] public static void Foo() { } [Verb] public void Bar() { } }
+}
View
20 Tests/Tests.cs
@@ -622,7 +622,7 @@ public void EmptyHandler_Static_CalledWhenNoArgs()
var p = new Parser<Sample_16>();
- p.StaticRun(new string[] { });
+ p.RunStatic(new string[] { });
mock.Verify(o => o.Print("a"));
@@ -686,7 +686,7 @@ public void Empty_Defined_NotStatic_TargetNull_Exception()
{
var p = new Parser<Sample_15>();
- p.StaticRun(new string[] { });
+ p.RunStatic(new string[] { });
}
[Test]
@@ -772,7 +772,7 @@ public void Help_NonStatic_CalledWithNull_Exception()
{
var p = new Parser<Sample_23>();
- p.StaticRun(new[] { "-?" });
+ p.RunStatic(new[] { "-?" });
}
[Test]
@@ -784,7 +784,7 @@ public void Help_Static()
var p = new Parser<Sample_22>();
- p.StaticRun(new[] { "-?" });
+ p.RunStatic(new[] { "-?" });
Sample_22.StaticPrinter = null;
}
@@ -863,7 +863,7 @@ public void RegisterEmptyHelpHandler_Called()
Assert.IsNull(help);
- p.StaticRun(new string[] { });
+ p.RunStatic(new string[] { });
Assert.IsNotNull(help);
}
@@ -895,7 +895,7 @@ public void Run_Verb_NoMatchingMethod_Exception()
{
var p = new Parser<Sample_25>();
- p.StaticRun(new[] { "boo!" });
+ p.RunStatic(new[] { "boo!" });
}
[Test]
@@ -904,7 +904,7 @@ public void Run_NoVerb_NoDefaultVerb_Exception()
{
var p = new Parser<Sample_25>();
- p.StaticRun(new string[] { "-x" });
+ p.RunStatic(new string[] { "-x" });
}
[Test]
@@ -1273,7 +1273,7 @@ public void Execute_HandleError_Registered_NoRethrow()
return false;
});
- p.StaticRun(new string[] { });
+ p.RunStatic(new string[] { });
Assert.IsTrue(handled);
}
@@ -1289,7 +1289,7 @@ public void Execute_HandleError_Registered_DefaultNoRethrow()
handled = true;
});
- p.StaticRun(new string[] { });
+ p.RunStatic(new string[] { });
Assert.IsTrue(handled);
}
@@ -1309,7 +1309,7 @@ public void Execute_HandleError_Registered_Rethrow()
try
{
- p.StaticRun(new string[] { });
+ p.RunStatic(new string[] { });
Assert.Fail();
}
View
1 Tests/Tests.csproj
@@ -93,6 +93,7 @@
<Compile Include="MultiParserTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Samples.cs" />
+ <Compile Include="StaticSamples.cs" />
<Compile Include="Tests.cs" />
</ItemGroup>
<ItemGroup>

0 comments on commit fe6a62e

Please sign in to comment.
Something went wrong with that request. Please try again.