Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/addins/NUnit/Services')
-rw-r--r--main/src/addins/NUnit/Services/ITestProvider.cs2
-rw-r--r--main/src/addins/NUnit/Services/NUnitAssemblyTestSuite.cs11
-rw-r--r--main/src/addins/NUnit/Services/NUnitProjectServiceExtension.cs40
-rw-r--r--main/src/addins/NUnit/Services/NUnitService.cs141
-rw-r--r--main/src/addins/NUnit/Services/SolutionFolderTestGroup.cs2
-rw-r--r--main/src/addins/NUnit/Services/SystemTestProvider.cs2
-rw-r--r--main/src/addins/NUnit/Services/UnitTest.cs29
-rw-r--r--main/src/addins/NUnit/Services/UnitTestGroup.cs11
8 files changed, 80 insertions, 158 deletions
diff --git a/main/src/addins/NUnit/Services/ITestProvider.cs b/main/src/addins/NUnit/Services/ITestProvider.cs
index b9cd72530d..c2bea5f998 100644
--- a/main/src/addins/NUnit/Services/ITestProvider.cs
+++ b/main/src/addins/NUnit/Services/ITestProvider.cs
@@ -35,7 +35,7 @@ namespace MonoDevelop.NUnit
{
public interface ITestProvider
{
- UnitTest CreateUnitTest (IWorkspaceObject entry);
+ UnitTest CreateUnitTest (WorkspaceObject entry);
Type[] GetOptionTypes ();
}
}
diff --git a/main/src/addins/NUnit/Services/NUnitAssemblyTestSuite.cs b/main/src/addins/NUnit/Services/NUnitAssemblyTestSuite.cs
index 3e55a824be..895b07674d 100644
--- a/main/src/addins/NUnit/Services/NUnitAssemblyTestSuite.cs
+++ b/main/src/addins/NUnit/Services/NUnitAssemblyTestSuite.cs
@@ -45,6 +45,7 @@ using MonoDevelop.Ide;
using System.Xml.Linq;
using System.Linq;
using System.Globalization;
+using System.Threading.Tasks;
namespace MonoDevelop.NUnit
{
@@ -69,7 +70,7 @@ namespace MonoDevelop.NUnit
{
}
- public NUnitAssemblyTestSuite (string name, SolutionItem ownerSolutionItem): base (name, ownerSolutionItem)
+ public NUnitAssemblyTestSuite (string name, WorkspaceObject ownerSolutionItem): base (name, ownerSolutionItem)
{
}
@@ -145,10 +146,9 @@ namespace MonoDevelop.NUnit
}
}
- public override IAsyncOperation Refresh ()
+ public override Task Refresh (CancellationToken ct)
{
- AsyncOperation oper = new AsyncOperation ();
- System.Threading.ThreadPool.QueueUserWorkItem (delegate {
+ return Task.Factory.StartNew (delegate {
lock (locker) {
try {
while (Status == TestStatus.Loading) {
@@ -162,13 +162,10 @@ namespace MonoDevelop.NUnit
Monitor.Wait (locker);
}
}
- oper.SetCompleted (true);
} catch {
- oper.SetCompleted (false);
}
}
});
- return oper;
}
DateTime GetAssemblyTime ()
diff --git a/main/src/addins/NUnit/Services/NUnitProjectServiceExtension.cs b/main/src/addins/NUnit/Services/NUnitProjectServiceExtension.cs
index 0ecd719fd8..ff59f13226 100644
--- a/main/src/addins/NUnit/Services/NUnitProjectServiceExtension.cs
+++ b/main/src/addins/NUnit/Services/NUnitProjectServiceExtension.cs
@@ -28,44 +28,32 @@
using MonoDevelop.Core;
using MonoDevelop.Projects;
using MonoDevelop.Ide;
+using System.Threading.Tasks;
namespace MonoDevelop.NUnit
{
- public class NUnitProjectServiceExtension: ProjectServiceExtension
+ public class NUnitProjectServiceExtension: ProjectExtension
{
- public override void Execute (MonoDevelop.Core.IProgressMonitor monitor, IBuildTarget item, ExecutionContext context, ConfigurationSelector configuration)
+ protected override Task OnExecute (MonoDevelop.Core.ProgressMonitor monitor, ExecutionContext context, ConfigurationSelector configuration)
{
- if (base.CanExecute (item, context, configuration)) {
+ if (base.OnGetCanExecute (context, configuration)) {
// It is executable by default
- base.Execute(monitor, item, context, configuration);
- return;
- } else if (item is IWorkspaceObject) {
- UnitTest test = NUnitService.Instance.FindRootTest ((IWorkspaceObject)item);
- if (test != null) {
- IAsyncOperation oper = null;
- DispatchService.GuiSyncDispatch (delegate {
- oper = NUnitService.Instance.RunTest (test, context.ExecutionHandler, false);
- });
-// if (oper != null) {
-// monitor.CancelRequested += delegate {
-// oper.Cancel ();
-// };
-// oper.WaitForCompleted ();
-// }
- }
+ return base.OnExecute (monitor, context, configuration);
}
+ UnitTest test = NUnitService.Instance.FindRootTest (Project);
+ if (test != null)
+ return NUnitService.Instance.RunTest (test, context.ExecutionHandler, false).Task;
+ else
+ return Task.FromResult (0);
}
- public override bool CanExecute (IBuildTarget item, ExecutionContext context, ConfigurationSelector configuration)
+ protected override bool OnGetCanExecute (ExecutionContext context, ConfigurationSelector configuration)
{
// We check for DefaultExecutionHandlerFactory because the tests can't run using any other execution mode
- bool res = base.CanExecute (item, context, configuration);
- if (!res && (item is IWorkspaceObject)) {
- UnitTest test = NUnitService.Instance.FindRootTest ((IWorkspaceObject)item);
- return (test != null) && test.CanRun (context.ExecutionHandler);
- } else
- return res;
+ bool res = base.OnGetCanExecute (context, configuration);
+ UnitTest test = NUnitService.Instance.FindRootTest (Project);
+ return (test != null) && test.CanRun (context.ExecutionHandler);
}
}
}
diff --git a/main/src/addins/NUnit/Services/NUnitService.cs b/main/src/addins/NUnit/Services/NUnitService.cs
index c5a2407532..79877e0fc4 100644
--- a/main/src/addins/NUnit/Services/NUnitService.cs
+++ b/main/src/addins/NUnit/Services/NUnitService.cs
@@ -38,6 +38,8 @@ using MonoDevelop.Projects;
using NUnit.Core;
using MonoDevelop.Ide.Gui;
using MonoDevelop.Ide;
+using System.Threading.Tasks;
+using System.Linq;
namespace MonoDevelop.NUnit
{
@@ -99,14 +101,20 @@ namespace MonoDevelop.NUnit
}
}
- public IAsyncOperation RunTest (UnitTest test, IExecutionHandler context)
+ public AsyncOperation RunTest (UnitTest test, IExecutionHandler context)
{
var result = RunTest (test, context, IdeApp.Preferences.BuildBeforeRunningTests);
- result.Completed += (OperationHandler) DispatchService.GuiDispatch (new OperationHandler (OnTestSessionCompleted));
+ result.Task.ContinueWith (t => OnTestSessionCompleted ());
return result;
}
- public IAsyncOperation RunTest (UnitTest test, IExecutionHandler context, bool buildOwnerObject)
+ public AsyncOperation RunTest (UnitTest test, IExecutionHandler context, bool buildOwnerObject)
+ {
+ var cs = new CancellationTokenSource ();
+ return new AsyncOperation (RunTestAsync (test, context, buildOwnerObject, cs), cs);
+ }
+
+ async Task RunTestAsync (UnitTest test, IExecutionHandler context, bool buildOwnerObject, CancellationTokenSource cs)
{
string testName = test.FullName;
@@ -115,39 +123,23 @@ namespace MonoDevelop.NUnit
if (bt != null && bt.NeedsBuilding (IdeApp.Workspace.ActiveConfiguration)) {
if (!IdeApp.ProjectOperations.CurrentRunOperation.IsCompleted) {
MonoDevelop.Ide.Commands.StopHandler.StopBuildOperations ();
- IdeApp.ProjectOperations.CurrentRunOperation.WaitForCompleted ();
+ await IdeApp.ProjectOperations.CurrentRunOperation.Task;
}
- AsyncOperation retOper = new AsyncOperation ();
-
- IAsyncOperation op = IdeApp.ProjectOperations.Build (bt);
- retOper.TrackOperation (op, false);
-
- op.Completed += delegate {
- // The completed event of the build operation is run in the gui thread,
- // so we need a new thread, because refreshing must be async
- System.Threading.ThreadPool.QueueUserWorkItem (delegate {
- if (op.Success) {
- RefreshTests ();
- test = SearchTest (testName);
- if (test != null) {
- Gtk.Application.Invoke (delegate {
- // RunTest must run in the gui thread
- retOper.TrackOperation (RunTest (test, context, false), true);
- });
- }
- else
- retOper.SetCompleted (false);
- }
- });
- };
-
- return retOper;
+ var res = await IdeApp.ProjectOperations.Build (bt, cs.Token).Task;
+ if (res.HasErrors)
+ return;
+
+ await RefreshTests (cs.Token);
+ test = SearchTest (testName);
+ if (test != null)
+ await RunTestAsync (test, context, false, cs);
+ return;
}
}
if (!IdeApp.ProjectOperations.ConfirmExecutionOperation ())
- return NullProcessAsyncOperation.Failure;
+ return;
Pad resultsPad = IdeApp.Workbench.GetPad <TestResultsPad>();
if (resultsPad == null) {
@@ -160,25 +152,17 @@ namespace MonoDevelop.NUnit
resultsPad.Sticky = true;
resultsPad.BringToFront ();
- TestSession session = new TestSession (test, context, (TestResultsPad) resultsPad.Content);
-
- session.Completed += delegate {
- Gtk.Application.Invoke (delegate {
- resultsPad.Sticky = false;
- });
- };
-
- session.Start ();
-
+ TestSession session = new TestSession (test, context, (TestResultsPad) resultsPad.Content, cs);
IdeApp.ProjectOperations.CurrentRunOperation = session;
-
- return session;
+
+ await session.Start ();
+
+ resultsPad.Sticky = false;
}
- public void RefreshTests ()
+ public Task RefreshTests (CancellationToken ct)
{
- foreach (UnitTest t in RootTests)
- t.Refresh ().WaitForCompleted ();
+ return Task.WhenAll (RootTests.Select (t => t.Refresh (ct)));
}
public UnitTest SearchTest (string fullName)
@@ -238,12 +222,12 @@ namespace MonoDevelop.NUnit
return null;
}
- public UnitTest FindRootTest (IWorkspaceObject item)
+ public UnitTest FindRootTest (WorkspaceObject item)
{
return FindRootTest (RootTests, item);
}
- public UnitTest FindRootTest (IEnumerable<UnitTest> tests, IWorkspaceObject item)
+ public UnitTest FindRootTest (IEnumerable<UnitTest> tests, WorkspaceObject item)
{
foreach (UnitTest t in tests) {
if (t.OwnerObject == item)
@@ -281,7 +265,7 @@ namespace MonoDevelop.NUnit
NotifyTestSuiteChanged ();
}
- public UnitTest BuildTest (IWorkspaceObject entry)
+ public UnitTest BuildTest (WorkspaceObject entry)
{
foreach (ITestProvider p in providers) {
try {
@@ -325,7 +309,7 @@ namespace MonoDevelop.NUnit
public event EventHandler TestSuiteChanged;
- void OnTestSessionCompleted (IAsyncOperation op)
+ void OnTestSessionCompleted ()
{
var handler = TestSessionCompleted;
if (handler != null)
@@ -337,31 +321,28 @@ namespace MonoDevelop.NUnit
- class TestSession: IAsyncOperation, ITestProgressMonitor
+ class TestSession: AsyncOperation, ITestProgressMonitor
{
UnitTest test;
TestMonitor monitor;
Thread runThread;
bool success;
- ManualResetEvent waitEvent;
IExecutionHandler context;
TestResultsPad resultsPad;
- public TestSession (UnitTest test, IExecutionHandler context, TestResultsPad resultsPad)
+ public TestSession (UnitTest test, IExecutionHandler context, TestResultsPad resultsPad, CancellationTokenSource cs)
{
this.test = test;
this.context = context;
- this.monitor = new TestMonitor (resultsPad);
+ CancellationTokenSource = cs;
+ this.monitor = new TestMonitor (resultsPad, CancellationTokenSource);
this.resultsPad = resultsPad;
resultsPad.InitializeTestRun (test);
}
- public void Start ()
+ public Task Start ()
{
- runThread = new Thread (new ThreadStart (RunTests));
- runThread.Name = "NUnit test runner";
- runThread.IsBackground = true;
- runThread.Start ();
+ return Task = Task.Factory.StartNew (RunTests);
}
void RunTests ()
@@ -381,12 +362,6 @@ namespace MonoDevelop.NUnit
monitor.FinishTestRun ();
runThread = null;
}
- lock (this) {
- if (waitEvent != null)
- waitEvent.Set ();
- }
- if (Completed != null)
- Completed (this);
}
void ITestProgressMonitor.BeginTest (UnitTest test)
@@ -412,45 +387,7 @@ namespace MonoDevelop.NUnit
bool ITestProgressMonitor.IsCancelRequested {
get { return monitor.IsCancelRequested; }
}
-
- void IAsyncOperation.Cancel ()
- {
- monitor.Cancel ();
- }
-
- public void WaitForCompleted ()
- {
- if (IsCompleted) return;
-
- if (DispatchService.IsGuiThread) {
- while (!IsCompleted) {
- while (Gtk.Application.EventsPending ())
- Gtk.Application.RunIteration ();
- Thread.Sleep (100);
- }
- } else {
- lock (this) {
- if (waitEvent == null)
- waitEvent = new ManualResetEvent (false);
- }
- waitEvent.WaitOne ();
- }
- }
-
- public bool IsCompleted {
- get { return runThread == null; }
- }
-
- public bool Success {
- get { return success; }
- }
- public bool SuccessWithWarnings {
- get { return false; }
- }
-
- public event OperationHandler Completed;
-
public event TestHandler CancelRequested {
add { monitor.CancelRequested += value; }
remove { monitor.CancelRequested -= value; }
diff --git a/main/src/addins/NUnit/Services/SolutionFolderTestGroup.cs b/main/src/addins/NUnit/Services/SolutionFolderTestGroup.cs
index c961b9c7e8..384598bc45 100644
--- a/main/src/addins/NUnit/Services/SolutionFolderTestGroup.cs
+++ b/main/src/addins/NUnit/Services/SolutionFolderTestGroup.cs
@@ -81,7 +81,7 @@ namespace MonoDevelop.NUnit
protected override void OnCreateTests ()
{
NUnitService testService = NUnitService.Instance;
- foreach (SolutionItem e in combine.Items) {
+ foreach (SolutionFolderItem e in combine.Items) {
UnitTest t = testService.BuildTest (e);
if (t != null)
Tests.Add (t);
diff --git a/main/src/addins/NUnit/Services/SystemTestProvider.cs b/main/src/addins/NUnit/Services/SystemTestProvider.cs
index 9e60f7767a..4090e3fff2 100644
--- a/main/src/addins/NUnit/Services/SystemTestProvider.cs
+++ b/main/src/addins/NUnit/Services/SystemTestProvider.cs
@@ -34,7 +34,7 @@ namespace MonoDevelop.NUnit
{
public class SystemTestProvider: ITestProvider
{
- public UnitTest CreateUnitTest (IWorkspaceObject entry)
+ public UnitTest CreateUnitTest (WorkspaceObject entry)
{
UnitTest test = null;
diff --git a/main/src/addins/NUnit/Services/UnitTest.cs b/main/src/addins/NUnit/Services/UnitTest.cs
index f8e9816015..a0044ac0c7 100644
--- a/main/src/addins/NUnit/Services/UnitTest.cs
+++ b/main/src/addins/NUnit/Services/UnitTest.cs
@@ -34,6 +34,9 @@ using MonoDevelop.Core.ProgressMonitoring;
using MonoDevelop.Projects;
using MonoDevelop.Core.Serialization;
using MonoDevelop.Core.Execution;
+using MonoDevelop.Ide;
+using System.Threading.Tasks;
+using System.Threading;
namespace MonoDevelop.NUnit
{
@@ -45,8 +48,8 @@ namespace MonoDevelop.NUnit
UnitTest parent;
TestStatus status;
Hashtable options;
- IWorkspaceObject ownerSolutionItem;
- SolutionEntityItem ownerSolutionEntityItem;
+ WorkspaceObject ownerSolutionItem;
+ SolutionItem ownerSolutionEntityItem;
UnitTestResultsStore results;
bool historicResult;
bool resultLoaded;
@@ -71,11 +74,11 @@ namespace MonoDevelop.NUnit
this.name = name;
}
- protected UnitTest (string name, IWorkspaceObject ownerSolutionItem)
+ protected UnitTest (string name, WorkspaceObject ownerSolutionItem)
{
this.name = name;
this.ownerSolutionItem = ownerSolutionItem;
- ownerSolutionEntityItem = ownerSolutionItem as SolutionEntityItem;
+ ownerSolutionEntityItem = ownerSolutionItem as SolutionItem;
if (ownerSolutionEntityItem != null)
ownerSolutionEntityItem.DefaultConfigurationChanged += OnConfugurationChanged;
}
@@ -363,11 +366,11 @@ namespace MonoDevelop.NUnit
}
}
- protected IWorkspaceObject OwnerSolutionItem {
+ protected WorkspaceObject OwnerSolutionItem {
get { return ownerSolutionItem; }
}
- public IWorkspaceObject OwnerObject {
+ public WorkspaceObject OwnerObject {
get {
if (ownerSolutionItem != null)
return ownerSolutionItem;
@@ -390,11 +393,9 @@ namespace MonoDevelop.NUnit
}
// Forces the reloading of tests, if they have changed
- public virtual IAsyncOperation Refresh ()
+ public virtual Task Refresh (CancellationToken ct)
{
- AsyncOperation op = new AsyncOperation ();
- op.SetCompleted (true);
- return op;
+ return Task.FromResult (0);
}
public UnitTestResult Run (TestContext testContext)
@@ -521,8 +522,8 @@ namespace MonoDevelop.NUnit
oset.Tests.Remove (te);
}
}
-
- ce.Save (new NullProgressMonitor ());
+
+ IdeApp.ProjectOperations.SaveAsync ((WorkspaceObject)ce);
}
protected virtual ICollection OnLoadOptions (string configuration)
@@ -552,8 +553,8 @@ namespace MonoDevelop.NUnit
void GetOwnerSolutionItem (UnitTest t, out IConfigurationTarget c, out string path)
{
- if (OwnerSolutionItem is SolutionEntityItem) {
- c = OwnerSolutionItem as SolutionEntityItem;
+ if (OwnerSolutionItem is SolutionItem) {
+ c = OwnerSolutionItem as SolutionItem;
path = "";
} else if (parent != null) {
parent.GetOwnerSolutionItem (t, out c, out path);
diff --git a/main/src/addins/NUnit/Services/UnitTestGroup.cs b/main/src/addins/NUnit/Services/UnitTestGroup.cs
index f478e1f00b..eaa541f83a 100644
--- a/main/src/addins/NUnit/Services/UnitTestGroup.cs
+++ b/main/src/addins/NUnit/Services/UnitTestGroup.cs
@@ -31,6 +31,8 @@ using MonoDevelop.Core;
using MonoDevelop.Core.ProgressMonitoring;
using System.Collections;
using MonoDevelop.Projects;
+using System.Threading.Tasks;
+using System.Threading;
namespace MonoDevelop.NUnit
{
@@ -42,7 +44,7 @@ namespace MonoDevelop.NUnit
{
}
- protected UnitTestGroup (string name, IWorkspaceObject ownerSolutionItem): base (name, ownerSolutionItem)
+ protected UnitTestGroup (string name, WorkspaceObject ownerSolutionItem): base (name, ownerSolutionItem)
{
}
@@ -121,13 +123,10 @@ namespace MonoDevelop.NUnit
{
}
- public override IAsyncOperation Refresh ()
+ public async override Task Refresh (CancellationToken ct)
{
- AggregatedAsyncOperation oper = new AggregatedAsyncOperation ();
foreach (UnitTest t in Tests)
- oper.Add (t.Refresh ());
- oper.StartMonitoring ();
- return oper;
+ await t.Refresh (ct);
}
protected override UnitTestResult OnRun (TestContext testContext)