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:
authorLluis Sanchez <lluis@xamarin.com>2016-05-23 12:59:39 +0300
committerLluis Sanchez <lluis@xamarin.com>2016-05-23 12:59:39 +0300
commit8fd098416cb4817b947ba5548758ba3c03577e02 (patch)
tree2db1cf1cd82c302217c0f450164c5f7139d5ae0f /main/src/addins/MonoDevelop.UnitTesting
parent3c1d718cea071790f93d6a3da143c450fb2ecbac (diff)
[Unit tests] Introduce a new unit test run configuration
When a project contains unit tests, create a run configuration which can be used to run them.
Diffstat (limited to 'main/src/addins/MonoDevelop.UnitTesting')
-rw-r--r--main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.csproj1
-rw-r--r--main/src/addins/MonoDevelop.UnitTesting/Services/UnitTestProjectServiceExtension.cs67
-rw-r--r--main/src/addins/MonoDevelop.UnitTesting/Services/UnitTestingRunConfiguration.cs39
3 files changed, 67 insertions, 40 deletions
diff --git a/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.csproj b/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.csproj
index d6236f6466..893a687f69 100644
--- a/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.csproj
+++ b/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.csproj
@@ -281,6 +281,7 @@
<Compile Include="Services\RemoteUnhandledException.cs" />
<Compile Include="Services\AbstractUnitTestEditorExtension.cs" />
<Compile Include="Services\UnitTestMarkersExtension.cs" />
+ <Compile Include="Services\UnitTestingRunConfiguration.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Makefile.am" />
diff --git a/main/src/addins/MonoDevelop.UnitTesting/Services/UnitTestProjectServiceExtension.cs b/main/src/addins/MonoDevelop.UnitTesting/Services/UnitTestProjectServiceExtension.cs
index 77b62b02aa..2a03719ec3 100644
--- a/main/src/addins/MonoDevelop.UnitTesting/Services/UnitTestProjectServiceExtension.cs
+++ b/main/src/addins/MonoDevelop.UnitTesting/Services/UnitTestProjectServiceExtension.cs
@@ -25,12 +25,15 @@
//
//
+using System;
using MonoDevelop.Core;
using MonoDevelop.Projects;
using MonoDevelop.Ide;
using System.Threading.Tasks;
using System.Threading;
using System.Runtime.InteropServices;
+using System.Linq;
+using System.Collections.Generic;
namespace MonoDevelop.UnitTesting
{
@@ -76,56 +79,40 @@ namespace MonoDevelop.UnitTesting
return unitTestFound;
}
- protected override async Task OnExecute (MonoDevelop.Core.ProgressMonitor monitor, MonoDevelop.Projects.ExecutionContext context, ConfigurationSelector configuration, RunConfiguration runConfiguration)
+ static UnitTestingRunConfiguration unitTestingRunConfigurationInstance = new UnitTestingRunConfiguration ();
+
+ protected override IEnumerable<RunConfiguration> OnGetRunConfigurations (OperationContext ctx)
{
- bool defaultCanExecute;
+ var configs = base.OnGetRunConfigurations (ctx);
- lock (canExecuteCheckLock) {
- try {
- checkingCanExecute = true;
- defaultCanExecute = Project.CanExecute (context, configuration);
- } finally {
- checkingCanExecute = false;
- }
- }
- if (defaultCanExecute) {
- // It is executable by default
- await base.OnExecute (monitor, context, configuration, runConfiguration);
- return;
- }
- UnitTest test = FindRootTest ();
- if (test != null) {
- var cs = new CancellationTokenSource ();
- using (monitor.CancellationToken.Register (cs.Cancel))
- await UnitTestService.RunTest (test, context, false, false, cs);
- }
+ // If the project has unit tests, add a configuration for running the tests
+ if (FindRootTest () != null)
+ configs = configs.Concat (unitTestingRunConfigurationInstance);
+
+ return configs;
}
- protected override ProjectFeatures OnGetSupportedFeatures ()
+ protected override async Task OnExecute (MonoDevelop.Core.ProgressMonitor monitor, MonoDevelop.Projects.ExecutionContext context, ConfigurationSelector configuration, RunConfiguration runConfiguration)
{
- var sf = base.OnGetSupportedFeatures ();
- if (!sf.HasFlag (ProjectFeatures.Execute)) {
- // Unit test projects support execution
+ if (runConfiguration == unitTestingRunConfigurationInstance) {
+ // The user selected to run the tests
UnitTest test = FindRootTest ();
- if (test != null)
- sf |= ProjectFeatures.Execute;
- }
- return sf;
+ if (test != null) {
+ var cs = new CancellationTokenSource ();
+ using (monitor.CancellationToken.Register (cs.Cancel))
+ await UnitTestService.RunTest (test, context, false, false, cs);
+ }
+ } else
+ await base.OnExecute (monitor, context, configuration, runConfiguration);
}
-
+
protected override bool OnGetCanExecute (MonoDevelop.Projects.ExecutionContext context, ConfigurationSelector configuration, RunConfiguration runConfiguration)
{
- // We check for DefaultExecutionHandlerFactory because the tests can't run using any other execution mode
-
- var res = base.OnGetCanExecute (context, configuration, runConfiguration);
- lock (canExecuteCheckLock) {
- if (checkingCanExecute)
- return res;
+ if (runConfiguration == unitTestingRunConfigurationInstance) {
+ UnitTest test = FindRootTest ();
+ return (test != null) && test.CanRun (context.ExecutionHandler);
}
- if (res)
- return true;
- UnitTest test = FindRootTest ();
- return (test != null) && test.CanRun (context.ExecutionHandler);
+ return base.OnGetCanExecute (context, configuration, runConfiguration);
}
}
}
diff --git a/main/src/addins/MonoDevelop.UnitTesting/Services/UnitTestingRunConfiguration.cs b/main/src/addins/MonoDevelop.UnitTesting/Services/UnitTestingRunConfiguration.cs
new file mode 100644
index 0000000000..fed7f3724d
--- /dev/null
+++ b/main/src/addins/MonoDevelop.UnitTesting/Services/UnitTestingRunConfiguration.cs
@@ -0,0 +1,39 @@
+//
+// UnitTestingRunConfiguration.cs
+//
+// Author:
+// Lluis Sanchez Gual <lluis@xamarin.com>
+//
+// Copyright (c) 2016 Xamarin, Inc (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+using MonoDevelop.Projects;
+using MonoDevelop.Core;
+
+namespace MonoDevelop.UnitTesting
+{
+ public class UnitTestingRunConfiguration: RunConfiguration
+ {
+ public UnitTestingRunConfiguration (): base (GettextCatalog.GetString ("Unit Tests"))
+ {
+ }
+ }
+}
+