Merge pull request #2802 from BrzVlad/feature-evacuation-opt2
[mono.git] / mcs / class / corlib / Test / System.Runtime.ExceptionServices / ExceptionDispatchInfoTest.cs
index fb7d0e57f7c3d3a3801b30f20fe4df8787cf1ada..900ffec6e7c4e570d6954ebb45176ad648e7912a 100644 (file)
@@ -30,10 +30,12 @@ using System;
 using NUnit.Framework;
 using System.Runtime.ExceptionServices;
 using System.Threading.Tasks;
+using System.Diagnostics;
 
 namespace MonoTests.System.Runtime.ExceptionServices
 {
        [TestFixture]
+       [Category ("BitcodeNotWorking")]
        public class ExceptionDispatchInfoTest
        {
                [Test]
@@ -123,6 +125,52 @@ namespace MonoTests.System.Runtime.ExceptionServices
                                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");
+                       }
+               }
+
+               [Test]
+               public void StackTraceUserCopy ()
+               {
+                       try {
+                               try {
+                                       throw new NotImplementedException ();
+                               } catch (Exception e) {
+                                       var edi = ExceptionDispatchInfo.Capture (e);
+                                       edi.Throw();
+                               }
+                       } catch (Exception ex) {
+                               var st = new StackTrace (ex, true);
+                               var split = st.ToString ().Split (new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
+                               Assert.AreEqual (4, split.Length, "#1");
+                               Assert.IsTrue (split [1].Contains ("---"), "#2");
+                       }
+               }
        }
 }