diff options
Diffstat (limited to 'main/src/addins/NUnit')
25 files changed, 181 insertions, 227 deletions
diff --git a/main/src/addins/NUnit/Commands/NUnitCommands.cs b/main/src/addins/NUnit/Commands/NUnitCommands.cs index f0d9322df4..22f6ebb2d3 100644 --- a/main/src/addins/NUnit/Commands/NUnitCommands.cs +++ b/main/src/addins/NUnit/Commands/NUnitCommands.cs @@ -64,7 +64,7 @@ namespace MonoDevelop.NUnit.Commands { protected override void Run () { - IWorkspaceObject ob = IdeApp.ProjectOperations.CurrentSelectedBuildTarget; + WorkspaceObject ob = IdeApp.ProjectOperations.CurrentSelectedObject; if (ob != null) { UnitTest test = NUnitService.Instance.FindRootTest (ob); if (test != null) @@ -74,7 +74,7 @@ namespace MonoDevelop.NUnit.Commands protected override void Update (CommandInfo info) { - IWorkspaceObject ob = IdeApp.ProjectOperations.CurrentSelectedBuildTarget; + WorkspaceObject ob = IdeApp.ProjectOperations.CurrentSelectedObject; if (ob != null) { UnitTest test = NUnitService.Instance.FindRootTest (ob); info.Enabled = (test != null); diff --git a/main/src/addins/NUnit/Gui/NUnitAssemblyGroupConfigurationNodeBuilder.cs b/main/src/addins/NUnit/Gui/NUnitAssemblyGroupConfigurationNodeBuilder.cs index 1d7c6e5a4e..bea7c43faa 100644 --- a/main/src/addins/NUnit/Gui/NUnitAssemblyGroupConfigurationNodeBuilder.cs +++ b/main/src/addins/NUnit/Gui/NUnitAssemblyGroupConfigurationNodeBuilder.cs @@ -122,7 +122,7 @@ namespace MonoDevelop.NUnit foreach (string file in dlg.SelectedFiles) config.Assemblies.Add (new TestAssembly (file)); - IdeApp.Workspace.Save(); + IdeApp.Workspace.SaveAsync(); } } } diff --git a/main/src/addins/NUnit/Gui/NUnitAssemblyGroupNodeBuilder.cs b/main/src/addins/NUnit/Gui/NUnitAssemblyGroupNodeBuilder.cs index 490a355404..2cc8a48c5e 100644 --- a/main/src/addins/NUnit/Gui/NUnitAssemblyGroupNodeBuilder.cs +++ b/main/src/addins/NUnit/Gui/NUnitAssemblyGroupNodeBuilder.cs @@ -117,7 +117,7 @@ namespace MonoDevelop.NUnit NUnitAssemblyGroupProject project = CurrentNode.DataItem as NUnitAssemblyGroupProject; project.ParentFolder.Items.Remove (project); project.Dispose (); - IdeApp.Workspace.Save (); + IdeApp.Workspace.SaveAsync (); } } } diff --git a/main/src/addins/NUnit/Gui/TestPad.cs b/main/src/addins/NUnit/Gui/TestPad.cs index 9b2c1fc7c3..15ece94e07 100644 --- a/main/src/addins/NUnit/Gui/TestPad.cs +++ b/main/src/addins/NUnit/Gui/TestPad.cs @@ -44,6 +44,7 @@ using MonoDevelop.Projects; using Mono.TextEditor; using System.Linq; using MonoDevelop.Components; +using MonoDevelop.Ide.Commands; namespace MonoDevelop.NUnit { @@ -51,7 +52,7 @@ namespace MonoDevelop.NUnit { NUnitService testService = NUnitService.Instance; - IAsyncOperation runningTestOperation; + AsyncOperation runningTestOperation; VPaned paned; TreeView detailsTree; ListStore detailsStore; @@ -411,7 +412,7 @@ namespace MonoDevelop.NUnit { UnitTest test = GetSelectedTest (); if (test != null) { - SolutionEntityItem item = test.OwnerObject as SolutionEntityItem; + SolutionItem item = test.OwnerObject as SolutionItem; ExecutionModeCommandService.GenerateExecutionModeCommands ( item, test.CanRun, @@ -467,12 +468,12 @@ namespace MonoDevelop.NUnit return nav.DataItem as UnitTest; } - public IAsyncOperation RunTest (UnitTest test, IExecutionHandler mode) + public AsyncOperation RunTest (UnitTest test, IExecutionHandler mode) { return RunTest (FindTestNode (test), mode, false); } - IAsyncOperation RunTest (ITreeNavigator nav, IExecutionHandler mode, bool bringToFront = true) + AsyncOperation RunTest (ITreeNavigator nav, IExecutionHandler mode, bool bringToFront = true) { if (nav == null) return null; @@ -487,7 +488,7 @@ namespace MonoDevelop.NUnit if (bringToFront) IdeApp.Workbench.GetPad<TestPad> ().BringToFront (); runningTestOperation = testService.RunTest (test, mode); - runningTestOperation.Completed += (OperationHandler) DispatchService.GuiDispatch (new OperationHandler (OnTestSessionCompleted)); + runningTestOperation.Task.ContinueWith (t => OnTestSessionCompleted ()); return runningTestOperation; } @@ -501,10 +502,9 @@ namespace MonoDevelop.NUnit RunTest (TreeView.GetSelectedNode (), mode); } - void OnTestSessionCompleted (IAsyncOperation op) + void OnTestSessionCompleted () { - if (op.Success) - RefreshDetails (); + RefreshDetails (); runningTestOperation = null; this.buttonRunAll.Sensitive = true; this.buttonStop.Sensitive = false; diff --git a/main/src/addins/NUnit/Gui/TestResultsPad.cs b/main/src/addins/NUnit/Gui/TestResultsPad.cs index 1baf8b81e5..00c4fa75ea 100644 --- a/main/src/addins/NUnit/Gui/TestResultsPad.cs +++ b/main/src/addins/NUnit/Gui/TestResultsPad.cs @@ -42,6 +42,8 @@ using MonoDevelop.Components.Docking; using MonoDevelop.Ide; using System.Text.RegularExpressions; using MonoDevelop.Components; +using System.Threading; +using MonoDevelop.Ide.Commands; namespace MonoDevelop.NUnit { @@ -475,7 +477,34 @@ namespace MonoDevelop.NUnit } } } - + + [CommandHandler (EditCommands.Copy)] + protected void OnCopy () + { + UnitTest test = GetSelectedTest (); + if (test != null) { + var last = test.GetLastResult (); + if (last == null) + return; + var clipboard = Clipboard.Get (Gdk.Atom.Intern ("CLIPBOARD", false)); + clipboard.Text = last.StackTrace; + } + } + + [CommandUpdateHandler (EditCommands.Copy)] + protected void OnUpdateCopy (CommandInfo info) + { + UnitTest test = GetSelectedTest (); + if (test != null) { + var result = test.GetLastResult (); + if (result != null) { + info.Enabled = !string.IsNullOrEmpty (result.StackTrace); + return; + } + } + info.Enabled = false; + } + [CommandHandler (TestCommands.SelectTestInTree)] protected void OnSelectTestInTree () { @@ -704,11 +733,14 @@ namespace MonoDevelop.NUnit { ITestProgressMonitor monitor; TestResultsPad pad; + CancellationTokenSource cs; - public TestMonitor (TestResultsPad pad) + public TestMonitor (TestResultsPad pad, CancellationTokenSource cs) { this.pad = pad; this.monitor = pad; + this.cs = cs; + cs.Token.Register (Cancel); } public void InitializeTestRun (UnitTest test) { diff --git a/main/src/addins/NUnit/Makefile.am b/main/src/addins/NUnit/Makefile.am index 4b4491f083..3ae131ae68 100644 --- a/main/src/addins/NUnit/Makefile.am +++ b/main/src/addins/NUnit/Makefile.am @@ -1,4 +1,3 @@ SUBDIRS = NUnitRunner . include $(top_srcdir)/xbuild.include -EXTRA_DIST += lib/nunit.core.dll lib/nunit.core.interfaces.dll lib/nunit.framework.dll lib/nunit.util.dll diff --git a/main/src/addins/NUnit/MonoDevelop.NUnit.csproj b/main/src/addins/NUnit/MonoDevelop.NUnit.csproj index ae8af1922d..2a2aa548c8 100644 --- a/main/src/addins/NUnit/MonoDevelop.NUnit.csproj +++ b/main/src/addins/NUnit/MonoDevelop.NUnit.csproj @@ -39,12 +39,6 @@ <DocumentationFile>..\..\..\build\AddIns\NUnit\MonoDevelop.NUnit.xml</DocumentationFile> </PropertyGroup> <ItemGroup> - <Reference Include="nunit.core"> - <HintPath>lib\nunit.core.dll</HintPath> - </Reference> - <Reference Include="nunit.framework"> - <HintPath>lib\nunit.framework.dll</HintPath> - </Reference> <Reference Include="System" /> <Reference Include="System.Xml" /> <Reference Include="glade-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f"> @@ -67,14 +61,20 @@ </Reference> <Reference Include="Mono.Posix" /> <Reference Include="Mono.Cairo" /> + <Reference Include="System.Xml.Linq" /> + <Reference Include="System.Core" /> + <Reference Include="nunit.framework"> + <HintPath>..\..\..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath> + </Reference> + <Reference Include="nunit.core"> + <HintPath>..\..\..\packages\NUnit.Runners.2.6.3\tools\lib\nunit.core.dll</HintPath> + </Reference> <Reference Include="nunit.core.interfaces"> - <HintPath>lib\nunit.core.interfaces.dll</HintPath> + <HintPath>..\..\..\packages\NUnit.Runners.2.6.3\tools\lib\nunit.core.interfaces.dll</HintPath> </Reference> <Reference Include="nunit.util"> - <HintPath>lib\nunit.util.dll</HintPath> + <HintPath>..\..\..\packages\NUnit.Runners.2.6.3\tools\lib\nunit.util.dll</HintPath> </Reference> - <Reference Include="System.Xml.Linq" /> - <Reference Include="System.Core" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\..\core\MonoDevelop.Core\MonoDevelop.Core.csproj"> @@ -247,6 +247,14 @@ </ItemGroup> <ItemGroup> <None Include="Makefile.am" /> + <None Include="packages.config" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> + <Target Name="BeforeBuild"> + <PropertyGroup> + <NuGet>$(SolutionDir)\external\nuget-binary\NuGet.exe</NuGet> + <NuGet Condition="$(OS)=='Unix'">mono $(NuGet)</NuGet> + </PropertyGroup> + <Exec Condition="Exists('$(SolutionDir)\..\.git')" Command="$(NuGet) restore -SolutionDirectory $(SolutionDir)" /> + </Target> </Project> diff --git a/main/src/addins/NUnit/MonoDevelopNUnit.addin.xml b/main/src/addins/NUnit/MonoDevelopNUnit.addin.xml index f2af6ec39c..d0e267a3d7 100644 --- a/main/src/addins/NUnit/MonoDevelopNUnit.addin.xml +++ b/main/src/addins/NUnit/MonoDevelopNUnit.addin.xml @@ -50,16 +50,6 @@ <!-- Extensions --> - <Extension path="/MonoDevelop/Core/SupportPackages"> - <Condition id="PackageNotInstalled" name="mono-nunit" version="2.7"> - <Package name="nunit" version="2.4" clrVersion="Default"> - <Assembly file="nunit.core.dll" /> - <Assembly file="nunit.core.interfaces.dll" /> - <Assembly file="nunit.framework.dll" /> - </Package> - </Condition> - </Extension> - <Extension path = "/MonoDevelop/Ide/Pads"> <SolutionPad id = "MonoDevelop.NUnit.TestPad" defaultLayout="*" defaultPlacement = "Right" defaultStatus="AutoHide" _label = "Unit Tests" icon = "nunit-pad-icon" class = "MonoDevelop.NUnit.TestPad"> <PadOption id = "ShowTestTime" _label = "Show Test Time" defaultValue = "False" /> @@ -146,6 +136,8 @@ <CommandItem id = "MonoDevelop.NUnit.Commands.TestCommands.GoToFailure" /> <CommandItem id = "MonoDevelop.NUnit.Commands.TestCommands.ShowTestCode" /> <CommandItem id = "MonoDevelop.NUnit.Commands.TestCommands.SelectTestInTree" /> + <SeparatorItem id = "s1" /> + <CommandItem id = "MonoDevelop.Ide.Commands.EditCommands.Copy" /> </Extension> <Extension path = "/MonoDevelop/NUnit/ContextMenu/TestChart"> @@ -190,8 +182,8 @@ <StockIcon stockid = "nunit-run" resource = "unit-run-light-16.png" size="Menu" /> </Extension> - <Extension path = "/MonoDevelop/ProjectModel/ProjectServiceExtensions"> - <Class class = "MonoDevelop.NUnit.NUnitProjectServiceExtension" /> + <Extension path = "/MonoDevelop/ProjectModel/ProjectModelExtensions"> + <ProjectExtension class = "MonoDevelop.NUnit.NUnitProjectServiceExtension" /> </Extension> <Extension path = "/MonoDevelop/ProjectModel/SerializableClasses"> diff --git a/main/src/addins/NUnit/NUnitRunner/NUnitRunner.csproj b/main/src/addins/NUnit/NUnitRunner/NUnitRunner.csproj index 68153a46ba..2248340e29 100644 --- a/main/src/addins/NUnit/NUnitRunner/NUnitRunner.csproj +++ b/main/src/addins/NUnit/NUnitRunner/NUnitRunner.csproj @@ -37,18 +37,28 @@ <ItemGroup> <Reference Include="System" /> <Reference Include="System.Xml" /> - <Reference Include="nunit.core"> - <HintPath>..\lib\nunit.core.dll</HintPath> - </Reference> <Reference Include="nunit.framework"> - <HintPath>..\lib\nunit.framework.dll</HintPath> + <HintPath>..\..\..\..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath> + </Reference> + <Reference Include="nunit.core"> + <HintPath>..\..\..\..\packages\NUnit.Runners.2.6.3\tools\lib\nunit.core.dll</HintPath> </Reference> <Reference Include="nunit.core.interfaces"> - <HintPath>..\lib\nunit.core.interfaces.dll</HintPath> + <HintPath>..\..\..\..\packages\NUnit.Runners.2.6.3\tools\lib\nunit.core.interfaces.dll</HintPath> </Reference> </ItemGroup> <ItemGroup> <Compile Include="NUnitTestRunner.cs" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> -</Project>
\ No newline at end of file + <ItemGroup> + <None Include="packages.config" /> + </ItemGroup> + <Target Name="BeforeBuild"> + <PropertyGroup> + <NuGet>$(SolutionDir)\external\nuget-binary\NuGet.exe</NuGet> + <NuGet Condition="$(OS)=='Unix'">mono $(NuGet)</NuGet> + </PropertyGroup> + <Exec Condition="Exists('$(SolutionDir)\..\.git')" Command="$(NuGet) restore -SolutionDirectory $(SolutionDir)" /> + </Target> +</Project> diff --git a/main/src/addins/NUnit/NUnitRunner/packages.config b/main/src/addins/NUnit/NUnitRunner/packages.config new file mode 100644 index 0000000000..3ca92b52ea --- /dev/null +++ b/main/src/addins/NUnit/NUnitRunner/packages.config @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="NUnit" version="2.6.3" targetFramework="net40" />
+ <package id="NUnit.Runners" version="2.6.3" targetFramework="net40" />
+</packages>
\ No newline at end of file diff --git a/main/src/addins/NUnit/Project/NUnitAssemblyGroupProject.cs b/main/src/addins/NUnit/Project/NUnitAssemblyGroupProject.cs index 0a67aac29d..561ede1a8a 100644 --- a/main/src/addins/NUnit/Project/NUnitAssemblyGroupProject.cs +++ b/main/src/addins/NUnit/Project/NUnitAssemblyGroupProject.cs @@ -38,7 +38,7 @@ using MonoDevelop.Ide.TypeSystem; namespace MonoDevelop.NUnit { [DataInclude (typeof(NUnitAssemblyGroupProjectConfiguration))] - public class NUnitAssemblyGroupProject: SolutionEntityItem + public class NUnitAssemblyGroupProject: SolutionItem { RootTest rootTest; @@ -53,7 +53,7 @@ namespace MonoDevelop.NUnit Configurations.Add (CreateConfiguration ("Default")); } - public override void InitializeFromTemplate (XmlElement element) + protected override void OnInitializeFromTemplate (XmlElement element) { Configurations.Add (CreateConfiguration ("Default")); } @@ -73,28 +73,6 @@ namespace MonoDevelop.NUnit conf.Name = name; return conf; } - - protected override void OnClean (IProgressMonitor monitor, ConfigurationSelector configuration) - { - } - - protected override BuildResult OnBuild (IProgressMonitor monitor, ConfigurationSelector configuration) - { - return null; - } - - protected override void OnExecute (IProgressMonitor monitor, ExecutionContext context, ConfigurationSelector configuration) - { - } - - protected override bool OnGetNeedsBuilding (ConfigurationSelector configuration) - { - return false; - } - - protected override void OnSetNeedsBuilding (bool value, ConfigurationSelector configuration) - { - } } public class NUnitAssemblyGroupProjectConfiguration: SolutionItemConfiguration 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) diff --git a/main/src/addins/NUnit/lib/nunit.core.dll b/main/src/addins/NUnit/lib/nunit.core.dll Binary files differdeleted file mode 100644 index 5f748becd1..0000000000 --- a/main/src/addins/NUnit/lib/nunit.core.dll +++ /dev/null diff --git a/main/src/addins/NUnit/lib/nunit.core.interfaces.dll b/main/src/addins/NUnit/lib/nunit.core.interfaces.dll Binary files differdeleted file mode 100644 index 72b9486d74..0000000000 --- a/main/src/addins/NUnit/lib/nunit.core.interfaces.dll +++ /dev/null diff --git a/main/src/addins/NUnit/lib/nunit.framework.dll b/main/src/addins/NUnit/lib/nunit.framework.dll Binary files differdeleted file mode 100644 index eaea9eedf7..0000000000 --- a/main/src/addins/NUnit/lib/nunit.framework.dll +++ /dev/null diff --git a/main/src/addins/NUnit/lib/nunit.util.dll b/main/src/addins/NUnit/lib/nunit.util.dll Binary files differdeleted file mode 100644 index 28d603c662..0000000000 --- a/main/src/addins/NUnit/lib/nunit.util.dll +++ /dev/null diff --git a/main/src/addins/NUnit/packages.config b/main/src/addins/NUnit/packages.config new file mode 100644 index 0000000000..3ca92b52ea --- /dev/null +++ b/main/src/addins/NUnit/packages.config @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="NUnit" version="2.6.3" targetFramework="net40" />
+ <package id="NUnit.Runners" version="2.6.3" targetFramework="net40" />
+</packages>
\ No newline at end of file diff --git a/main/src/addins/NUnit/templates/NUnitProject.xpt.xml b/main/src/addins/NUnit/templates/NUnitProject.xpt.xml index 9a83ac6b23..4a42bb84fb 100644 --- a/main/src/addins/NUnit/templates/NUnitProject.xpt.xml +++ b/main/src/addins/NUnit/templates/NUnitProject.xpt.xml @@ -27,9 +27,12 @@ <References> <Reference type="Package" refto="System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> - <Reference type="Package" refto="nunit.framework" SpecificVersion = "false" LocalCopy = "false" /> </References> - + + <Packages> + <Package ID="NUnit" Version="2.6.3" /> + </Packages> + <Files> <CodeDomFile name="Test"> <CompileUnit> |