From 07750e4004e657ef6b6cdd11e8e0228673d94f5a Mon Sep 17 00:00:00 2001 From: Stefan Andres Charsley Date: Mon, 4 Jan 2016 21:37:49 +1300 Subject: [PATCH] Updated Exceptions test runner - Updated test runner to include exception filtering tests --- .../Kernel.cs | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/Tests/Cosmos.Compiler.Tests.Exceptions/Kernel.cs b/Tests/Cosmos.Compiler.Tests.Exceptions/Kernel.cs index 70f01a540..80d2423da 100644 --- a/Tests/Cosmos.Compiler.Tests.Exceptions/Kernel.cs +++ b/Tests/Cosmos.Compiler.Tests.Exceptions/Kernel.cs @@ -21,7 +21,9 @@ namespace Cosmos.Compiler.Tests.Exceptions mDebugger.Send("Run"); TestSimpleException(); - + + var xFilter = false; + var xShouldCatch = false; var xCaught = false; var xInFinally = false; mDebugger.Send("START: Test throw Exception() in method and catch in caller."); @@ -92,6 +94,63 @@ namespace Cosmos.Compiler.Tests.Exceptions Assert.IsTrue(xCaught, "Did not reach catch block (3)"); //Assert.IsTrue(xInFinally, "Did not reach finally block (3)"); + + xFilter = false; + xShouldCatch = false; + xCaught = false; + xInFinally = false; + mDebugger.Send("START: Test throw Exception() in method and catch in caller without filter."); + try + { + TestReturnSimpleException(); + } + catch (Exception ex) where (xShouldCatch == true) + { + Console.WriteLine("Caught filtered exception."); + mDebugger.Send("EXCEPTION: " + ex.Message); + xFilter = true; + } + catch (Exception ex) + { + Console.WriteLine("Caught exception."); + mDebugger.Send("EXCEPTION: " + ex.Message); + xCaught = true; + } + finally + { + Console.WriteLine("Finally"); + mDebugger.Send("EXCEPTION: Finally"); + xInFinally = true; + } + mDebugger.Send("END"); + Assert.IsFalse(xFilter, "Should not reach filter block (4)"); + Assert.IsTrue(xCaught, "Did not reach catch block (4)"); + Assert.IsTrue(xInFinally, "Did not reach finally block (4)"); + + xFilter = false; + xShouldCatch = true; + xCaught = false; + xInFinally = false; + mDebugger.Send("START: Test throw Exception() in method and catch in caller with filter."); + try + { + TestReturnSimpleException(); + } + catch (Exception ex) where (xShouldCatch == true) + { + Console.WriteLine("Caught filtered exception."); + mDebugger.Send("EXCEPTION: " + ex.Message); + xFilter = true; + } + finally + { + Console.WriteLine("Finally"); + mDebugger.Send("EXCEPTION: Finally"); + xInFinally = true; + } + mDebugger.Send("END"); + Assert.IsTrue(xFilter, "Did not reach filter block (5)"); + Assert.IsTrue(xInFinally, "Did not reach finally block (5)"); TestController.Completed(); }