diff options
author | Alan McGovern <alan@xamarin.com> | 2013-07-29 07:53:11 +0400 |
---|---|---|
committer | Alan McGovern <alan@xamarin.com> | 2013-07-29 07:53:11 +0400 |
commit | eed5c806ad2d52cc1c58cdf62ad0c6b22b0f7de8 (patch) | |
tree | 6b18a44f673628956c48628d7a4c867ec3bed794 | |
parent | afac4c0b0302b83622584aa18257e1adbc2ae07f (diff) |
Add the ability to run without explicit mainloop integration.
Sometimes someone will want to set up their own SyncronizationContext
and have the tests run without calling any special setup/shutdown
methods. This isn't fully tested but if there are bugs i can fix em.
-rw-r--r-- | src/framework/GuiUnit/TestRunner.cs | 19 | ||||
-rwxr-xr-x | src/framework/Internal/Reflect.cs | 34 |
2 files changed, 35 insertions, 18 deletions
diff --git a/src/framework/GuiUnit/TestRunner.cs b/src/framework/GuiUnit/TestRunner.cs index 7e39107..c66b9e2 100644 --- a/src/framework/GuiUnit/TestRunner.cs +++ b/src/framework/GuiUnit/TestRunner.cs @@ -37,9 +37,14 @@ namespace GuiUnit { public class TestRunner : ITestListener { + static bool initialized = false; static IMainLoopIntegration mainLoop; public static IMainLoopIntegration MainLoop { get { + if (initialized) + return mainLoop; + + initialized = true; try { mainLoop = mainLoop ?? new XwtMainLoopIntegration (); } catch { } try { mainLoop = mainLoop ?? new MonoMacMainLoopIntegration (); } catch { } try { mainLoop = mainLoop ?? new GtkMainLoopIntegration (); } catch { } @@ -193,12 +198,16 @@ namespace GuiUnit filter = new AndFilter(filter, excludeFilter); } - MainLoop.InitializeToolkit (); - System.Threading.ThreadPool.QueueUserWorkItem (d => { + if (MainLoop == null) { RunTests (filter); - Shutdown (); - }); - MainLoop.RunMainLoop (); + } else { + MainLoop.InitializeToolkit (); + System.Threading.ThreadPool.QueueUserWorkItem (d => { + RunTests (filter); + Shutdown (); + }); + MainLoop.RunMainLoop (); + } } } catch (FileNotFoundException ex) diff --git a/src/framework/Internal/Reflect.cs b/src/framework/Internal/Reflect.cs index 1e18409..da4d1d4 100755 --- a/src/framework/Internal/Reflect.cs +++ b/src/framework/Internal/Reflect.cs @@ -215,19 +215,27 @@ namespace NUnit.Framework.Internal try { Environment.CurrentDirectory = System.IO.Path.GetDirectoryName (method.DeclaringType.Assembly.Location); - var invokeHelper = new GuiUnit.InvokerHelper { - Context = TestExecutionContext.CurrentContext, - Func = () => method.Invoke( fixture, args ) - }; - - GuiUnit.TestRunner.MainLoop.InvokeOnMainLoop (invokeHelper); - invokeHelper.Waiter.WaitOne (); - - if (invokeHelper.Result is System.Threading.Tasks.Task) - ((System.Threading.Tasks.Task)invokeHelper.Result).Wait (); - else if (invokeHelper.ex != null) - Rethrow (invokeHelper.ex); - return invokeHelper.Result; + + object result = null; + if (GuiUnit.TestRunner.MainLoop == null) { + result = method.Invoke (fixture, args); + } else { + var invokeHelper = new GuiUnit.InvokerHelper { + Context = TestExecutionContext.CurrentContext, + Func = () => method.Invoke( fixture, args ) + }; + + GuiUnit.TestRunner.MainLoop.InvokeOnMainLoop (invokeHelper); + invokeHelper.Waiter.WaitOne (); + if (invokeHelper.ex != null) + Rethrow (invokeHelper.ex); + result = invokeHelper.Result; + } + + if (result is System.Threading.Tasks.Task) + ((System.Threading.Tasks.Task) result).Wait (); + else + return result; } catch(Exception e) { |