From 70bb70b0ffd0109aadaa6e4ea178972d4fb63ea3 Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Mon, 26 Feb 2018 16:47:11 +0100 Subject: [FinallyDelegate] rely on PlatformNotSupportedException in order to determine remoting support (#10) --- NUnitLite-1.0.0/src/framework/FinallyDelegate.cs | 30 ++++++++---------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/NUnitLite-1.0.0/src/framework/FinallyDelegate.cs b/NUnitLite-1.0.0/src/framework/FinallyDelegate.cs index dfa94b6..d94cf79 100644 --- a/NUnitLite-1.0.0/src/framework/FinallyDelegate.cs +++ b/NUnitLite-1.0.0/src/framework/FinallyDelegate.cs @@ -24,10 +24,6 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // *********************************************************************** -#if __IOS__ || __WATCHOS__ || __TVOS__ -#define NO_REMOTING -#endif - using System; using System.Diagnostics; using System.Threading; @@ -76,14 +72,12 @@ namespace NUnit.Framework.Internal // Thread_1 creates Thread_2, it needs to have the same "thread local" values. // that is achieved with `CallContext`. // - // Unfortunately, remoting isn't available on every platform, thus we can't - // support this scenario. Luckily, this scenario is very rare. + // Unfortunately, remoting isn't available on every platform (it will + // throw PlatformNotSupportedexception), thus we can't support this + // scenario. Luckily, this scenario is very rare. -#if NO_REMOTING - static Container container; -#else + Container container = null; private static readonly string CONTEXT_KEY = "TestResultName"; -#endif public FinallyDelegate () { this.testStack = new Stack>(); @@ -96,22 +90,18 @@ namespace NUnit.Framework.Internal /* keep name in LogicalCallContext, because this will be inherited by * Threads spawned by the test case */ var guid = Guid.NewGuid(); -#if NO_REMOTING - container = new Container (guid); -#else - CallContext.SetData(CONTEXT_KEY, new Container(guid)); -#endif + try { + CallContext.SetData(CONTEXT_KEY, new Container(guid)); + } catch { + container = new Container (guid); + } this.lookupTable.Add(guid, result); this.testStack.Push(frame); } public void HandleUnhandledExc (Exception ex) { -#if NO_REMOTING - Container c = container; -#else - Container c = (Container) CallContext.GetData(CONTEXT_KEY); -#endif + Container c = container ?? (Container) CallContext.GetData(CONTEXT_KEY); TestResult result = this.lookupTable [c.guid]; result.RecordException(ex); result.ThreadCrashFail = true; -- cgit v1.2.3