Permalink
Browse files

tests for latest changes

  • Loading branch information...
adrianaisemberg committed Mar 15, 2012
1 parent a3ee505 commit 7dc06f1a7c7e9f64e2afd708ebcf3ab0d4b9ce72
Showing with 51 additions and 9 deletions.
  1. +9 −9 CLAP/MultiParser.cs
  2. +15 −0 Tests/Samples.cs
  3. +27 −0 Tests/Tests.cs
View
@@ -143,7 +143,7 @@ private ParserRunner GetSingleTypeParser(string[] args, object obj, ParserRegist
{
var parts = verb.Split(s_delimiters, StringSplitOptions.RemoveEmptyEntries);
- if (parts.Length > 2)
+ if (parts.Length != 2)
{
throw new InvalidVerbException();
}
@@ -185,17 +185,17 @@ public void RunTargets(string[] args, params object[] targets)
{
ParserRunner parser = null;
- try
+ // no args
+ //
+ if (args.None() || args.All(a => string.IsNullOrEmpty(a)))
{
- // no args
- //
- if (args.None() || args.All(a => string.IsNullOrEmpty(a)))
- {
- HandleEmptyArguments(targets);
+ HandleEmptyArguments(targets);
- return;
- }
+ return;
+ }
+ try
+ {
if (m_types.Length == 1)
{
parser = GetSingleTypeParser(args, targets, Register);
View
@@ -1324,4 +1324,19 @@ public static void Global2()
{
}
}
+
+ public class Sample_64
+ {
+ public bool Handled { get; set; }
+
+ [Error]
+ void Error(ExceptionContext c)
+ {
+ Handled = true;
+ }
+ }
+
+ public class Sample_65
+ {
+ }
}
View
@@ -2369,5 +2369,32 @@ public void DuplicateGlobalName_Exception()
"foo"
});
}
+
+ [Test]
+ public void HandlePreMatureError_DefinedHandler()
+ {
+ var s = new Sample_64();
+
+ Assert.IsFalse(s.Handled);
+
+ Parser.Run(new[] { "." }, s);
+
+ Assert.IsTrue(s.Handled);
+ }
+
+ [Test]
+ public void HandlePreMatureError_RegisteredHandler()
+ {
+ var s = new Sample_65();
+ var p = new Parser<Sample_65>();
+
+ var handled = false;
+
+ p.Register.ErrorHandler(c => handled = true);
+
+ p.RunTargets(new[] { "." }, s);
+
+ Assert.IsTrue(handled);
+ }
}
}

0 comments on commit 7dc06f1

Please sign in to comment.