Skip to content
This repository was archived by the owner on Jan 14, 2021. It is now read-only.

Commit 70bb70b

Browse files
authored
[FinallyDelegate] rely on PlatformNotSupportedException in order to determine remoting support (#10)
1 parent 09ad9cf commit 70bb70b

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

NUnitLite-1.0.0/src/framework/FinallyDelegate.cs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2525
// ***********************************************************************
2626

27-
#if __IOS__ || __WATCHOS__ || __TVOS__
28-
#define NO_REMOTING
29-
#endif
30-
3127
using System;
3228
using System.Diagnostics;
3329
using System.Threading;
@@ -76,14 +72,12 @@ public class FinallyDelegate
7672
// Thread_1 creates Thread_2, it needs to have the same "thread local" values.
7773
// that is achieved with `CallContext`.
7874
//
79-
// Unfortunately, remoting isn't available on every platform, thus we can't
80-
// support this scenario. Luckily, this scenario is very rare.
75+
// Unfortunately, remoting isn't available on every platform (it will
76+
// throw PlatformNotSupportedexception), thus we can't support this
77+
// scenario. Luckily, this scenario is very rare.
8178

82-
#if NO_REMOTING
83-
static Container container;
84-
#else
79+
Container container = null;
8580
private static readonly string CONTEXT_KEY = "TestResultName";
86-
#endif
8781

8882
public FinallyDelegate () {
8983
this.testStack = new Stack<Tuple<TestExecutionContext, long, TestResult>>();
@@ -96,22 +90,18 @@ public void Set (TestExecutionContext context, long startTicks, TestResult resul
9690
/* keep name in LogicalCallContext, because this will be inherited by
9791
* Threads spawned by the test case */
9892
var guid = Guid.NewGuid();
99-
#if NO_REMOTING
100-
container = new Container (guid);
101-
#else
102-
CallContext.SetData(CONTEXT_KEY, new Container(guid));
103-
#endif
93+
try {
94+
CallContext.SetData(CONTEXT_KEY, new Container(guid));
95+
} catch {
96+
container = new Container (guid);
97+
}
10498

10599
this.lookupTable.Add(guid, result);
106100
this.testStack.Push(frame);
107101
}
108102

109103
public void HandleUnhandledExc (Exception ex) {
110-
#if NO_REMOTING
111-
Container c = container;
112-
#else
113-
Container c = (Container) CallContext.GetData(CONTEXT_KEY);
114-
#endif
104+
Container c = container ?? (Container) CallContext.GetData(CONTEXT_KEY);
115105
TestResult result = this.lookupTable [c.guid];
116106
result.RecordException(ex);
117107
result.ThreadCrashFail = true;

0 commit comments

Comments
 (0)