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

Commit c4a1cd1

Browse files
authored
[TouchRunner] The mac runner must run tests inside NSApplication.Run. (#84)
Otherwise the MonoTouchFixtures.GameKit.NotificationBannerTest test fails.
1 parent f620668 commit c4a1cd1

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

NUnitLite/TouchRunner/MacRunner.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,31 @@
99

1010
namespace MonoTouch.NUnit.UI {
1111
public class MacRunner : BaseTouchRunner {
12-
public static async Task<int> MainAsync (IList<string> arguments, params Assembly[] assemblies)
12+
// The exitProcess callback must not return. The boolean parameter specifies whether the test run succeeded or not.
13+
public static async Task<int> MainAsync (IList<string> arguments, bool requiresNSApplicationRun, Action<int> exitProcess, params Assembly[] assemblies)
1314
{
15+
var success = false;
16+
1417
NSApplication.Init ();
1518

1619
var options = new TouchOptions (arguments);
1720
TouchOptions.Current = options;
18-
return await RunTestsAsync (options, assemblies) ? 0 : 1;
21+
22+
if (requiresNSApplicationRun) {
23+
var app = NSApplication.SharedApplication;
24+
app.InvokeOnMainThread (async () => {
25+
success = await RunTestsAsync (options, assemblies);
26+
// The only reliable way to stop NSApplication.Run is to call NSApplication.Terminate, which will
27+
// terminate the app, but won't allow us to specify the exit code. So we need an callback that will
28+
// exit the process
29+
exitProcess (success ? 0 : 1);
30+
});
31+
app.Run ();
32+
} else {
33+
success = await RunTestsAsync (options, assemblies);
34+
}
35+
36+
return success ? 0 : 1;
1937
}
2038

2139
static async Task<bool> RunTestsAsync (TouchOptions options, Assembly[] assemblies)

0 commit comments

Comments
 (0)