Merge pull request #1857 from slluis/fix-assembly-resolver
[mono.git] / mcs / class / corlib / Test / System.Runtime.ExceptionServices / ExceptionDispatchInfoTest.cs
index 8936dc9cde95e21eb171e9f4ca948c0932a1e5be..bef832b90c424aabe9d76f11943edbe7947d6671 100644 (file)
@@ -26,8 +26,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if NET_4_5
-
 using System;
 using NUnit.Framework;
 using System.Runtime.ExceptionServices;
@@ -73,6 +71,7 @@ namespace MonoTests.System.Runtime.ExceptionServices
                        var orig_stack = orig.StackTrace;
                        try {
                                ed.Throw ();
+                               Assert.Fail ("#0");
                        } catch (Exception e) {
                                var s = e.StackTrace.Split ('\n');
                                Assert.AreEqual (4, s.Length, "#1");
@@ -81,7 +80,77 @@ namespace MonoTests.System.Runtime.ExceptionServices
                        }
                }
 
+               [Test]
+               public void ThrowWithEmptyFrames ()
+               {
+                       var edi = ExceptionDispatchInfo.Capture (new OperationCanceledException ());
+                       try {
+                               edi.Throw ();
+                               Assert.Fail ("#0");
+                       } catch (OperationCanceledException e) {
+                               Assert.IsFalse (e.StackTrace.Contains ("---"));
+                               Assert.AreEqual (2, e.StackTrace.Split (new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Length);
+                       }
+               }
+
+               [Test]
+               public void LastThrowWins ()
+               {
+                       Exception e;
+                       try {
+                               throw new Exception ("test");
+                       } catch (Exception e2) {
+                               e = e2;
+                       }
+
+                       var edi = ExceptionDispatchInfo.Capture (e);
+
+                       try {
+                               edi.Throw ();
+                       } catch {
+                       }
+
+                       try {
+                               edi.Throw ();
+                       } catch (Exception ex) {
+                       }
+
+                       try {
+                               edi.Throw ();
+                       } catch (Exception ex) {
+                               var split = ex.StackTrace.Split (new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
+                               Assert.AreEqual (4, split.Length, "#1");
+                               Assert.IsTrue (split [1].Contains ("---"), "#2");
+                       }
+               }
+
+               [Test]
+               public void ThrowMultipleCaptures ()
+               {
+                       Exception e;
+                       try {
+                               throw new Exception ("test");
+                       } catch (Exception e2) {
+                               e = e2;
+                       }
+
+                       var edi = ExceptionDispatchInfo.Capture (e);
+
+                       try {
+                               edi.Throw ();
+                       } catch (Exception e3) {
+                               edi = ExceptionDispatchInfo.Capture (e3);
+                       }
+
+                       try {
+                               edi.Throw ();
+                       } catch (Exception ex) {
+                               var split = ex.StackTrace.Split (new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
+                               Assert.AreEqual (7, split.Length, "#1");
+                               Assert.IsTrue (split [1].Contains ("---"), "#2");
+                               Assert.IsTrue (split [4].Contains ("---"), "#3");
+                       }
+               }               
        }
 }
 
-#endif
\ No newline at end of file