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 <llsan@microsoft.com>2019-02-19 15:24:10 +0300
committerLluis Sanchez <llsan@microsoft.com>2019-02-19 15:24:10 +0300
commitf803f4f8ae5f1df72134d2a3d4e0e157e19b1507 (patch)
tree96926c8f7dcc47894ed29922a2b66e49318c0906 /main/src/addins/MonoDevelop.UnitTesting
parent729406c24383ca545324d76905c21e8a22d4e2e7 (diff)
parent5040c83aaebd09556e8e9b75d602ec5d48fe3803 (diff)
Merge remote-tracking branch 'origin/master' into new-service-model
Diffstat (limited to 'main/src/addins/MonoDevelop.UnitTesting')
-rw-r--r--main/src/addins/MonoDevelop.UnitTesting/Commands/UnitTestCommands.cs15
-rw-r--r--main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.addin.xml3
-rw-r--r--main/src/addins/MonoDevelop.UnitTesting/Services/AbstractUnitTestEditorExtension.cs150
-rw-r--r--main/src/addins/MonoDevelop.UnitTesting/Services/SolutionFolderTestGroup.cs2
4 files changed, 100 insertions, 70 deletions
diff --git a/main/src/addins/MonoDevelop.UnitTesting/Commands/UnitTestCommands.cs b/main/src/addins/MonoDevelop.UnitTesting/Commands/UnitTestCommands.cs
index 5f776ccc60..6d0a84150d 100644
--- a/main/src/addins/MonoDevelop.UnitTesting/Commands/UnitTestCommands.cs
+++ b/main/src/addins/MonoDevelop.UnitTesting/Commands/UnitTestCommands.cs
@@ -44,7 +44,7 @@ namespace MonoDevelop.UnitTesting.Commands
GoToFailure,
RerunTest,
}
-
+
public enum TestChartCommands
{
ShowResults,
@@ -55,13 +55,20 @@ namespace MonoDevelop.UnitTesting.Commands
ShowFailedTests,
ShowIgnoredTests
}
-
+
public enum NUnitProjectCommands
{
AddAssembly
}
-
- class RunAllTestsHandler: CommandHandler
+
+ public enum TextEditorCommands
+ {
+ RunTestAtCaret,
+ DebugTestAtCaret,
+ SelectTestAtCaret
+ }
+
+ class RunAllTestsHandler : CommandHandler
{
protected override void Run ()
{
diff --git a/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.addin.xml b/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.addin.xml
index c2158343b2..4fd591a678 100644
--- a/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.addin.xml
+++ b/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.addin.xml
@@ -75,6 +75,9 @@
<Command id = "MonoDevelop.UnitTesting.Commands.TestChartCommands.ShowSuccessfulTests" _label = "Show successful tests" type="check"/>
<Command id = "MonoDevelop.UnitTesting.Commands.TestChartCommands.ShowFailedTests" _label = "Show failed tests" type="check"/>
<Command id = "MonoDevelop.UnitTesting.Commands.TestChartCommands.ShowIgnoredTests" _label = "Show ignored tests" type="check"/>
+ <Command id = "MonoDevelop.UnitTesting.Commands.TextEditorCommands.RunTestAtCaret" _label = "Run Test at Caret"/>
+ <Command id = "MonoDevelop.UnitTesting.Commands.TextEditorCommands.DebugTestAtCaret" _label = "Debug Test at Caret"/>
+ <Command id = "MonoDevelop.UnitTesting.Commands.TextEditorCommands.SelectTestAtCaret" _label = "Select Test at Caret"/>
</Category>
</Extension>
diff --git a/main/src/addins/MonoDevelop.UnitTesting/Services/AbstractUnitTestEditorExtension.cs b/main/src/addins/MonoDevelop.UnitTesting/Services/AbstractUnitTestEditorExtension.cs
index 58449a06a8..27464ad5b2 100644
--- a/main/src/addins/MonoDevelop.UnitTesting/Services/AbstractUnitTestEditorExtension.cs
+++ b/main/src/addins/MonoDevelop.UnitTesting/Services/AbstractUnitTestEditorExtension.cs
@@ -37,6 +37,8 @@ using MonoDevelop.Ide.Editor.Extension;
using MonoDevelop.Ide.Editor;
using MonoDevelop.Projects;
using Mono.Addins;
+using MonoDevelop.Components.Commands;
+using MonoDevelop.UnitTesting.Commands;
namespace MonoDevelop.UnitTesting
{
@@ -137,6 +139,36 @@ namespace MonoDevelop.UnitTesting
List<IUnitTestMarker> currentMarker = new List<IUnitTestMarker>();
+ TestRunner GetTestRunnerAtCaret (bool debug)
+ {
+ var line = Editor.GetLine (Editor.CaretLine);
+ if (line == null)
+ return null;
+ foreach (var marker in Editor.GetLineMarkers (line)) {
+ if (marker is IUnitTestMarker result)
+ return new TestRunner (result.UnitTest.UnitTestIdentifier, DocumentContext.Project, debug);
+ }
+ return null;
+ }
+
+ [CommandHandler (TextEditorCommands.RunTestAtCaret)]
+ protected void OnRunTestAtCaret ()
+ {
+ GetTestRunnerAtCaret (false)?.Run (this, EventArgs.Empty);
+ }
+
+ [CommandHandler (TextEditorCommands.DebugTestAtCaret)]
+ protected void OnDebugTestAtCaret ()
+ {
+ GetTestRunnerAtCaret (true)?.Run (this, EventArgs.Empty);
+ }
+
+ [CommandHandler (TextEditorCommands.SelectTestAtCaret)]
+ protected void OnSelectTestAtCaret ()
+ {
+ GetTestRunnerAtCaret (false)?.Select (this, EventArgs.Empty);
+ }
+
class UnitTestMarkerHostImpl : UnitTestMarkerHost
{
readonly AbstractUnitTestTextEditorExtension ext;
@@ -277,82 +309,70 @@ namespace MonoDevelop.UnitTesting
#endregion
- class TestRunner
- {
- readonly string testCase;
- readonly bool debug;
- IBuildTarget project;
-
- public TestRunner (string testCase, IBuildTarget project, bool debug)
- {
- this.testCase = testCase;
- this.debug = debug;
- this.project = project;
- }
-
- bool TimeoutHandler ()
- {
- var test = UnitTestService.SearchTestByDocumentId (testCase);
- if (test != null) {
- RunTest (test);
- timeoutHandler = 0;
- } else {
- return true;
- }
- return false;
- }
+ }
+ class TestRunner
+ {
+ readonly string testCase;
+ readonly bool debug;
+ IBuildTarget project;
- internal async void Run (object sender, EventArgs e)
- {
- if (IdeApp.ProjectOperations.IsBuilding (IdeApp.ProjectOperations.CurrentSelectedSolution) ||
- IdeApp.ProjectOperations.IsRunning (IdeApp.ProjectOperations.CurrentSelectedSolution))
- return;
+ public TestRunner (string testCase, IBuildTarget project, bool debug)
+ {
+ this.testCase = testCase;
+ this.debug = debug;
+ this.project = project;
+ }
- var foundTest = UnitTestService.SearchTestByDocumentId (testCase);
- if (foundTest != null) {
- RunTest (foundTest);
- return;
- }
+ internal async void Run (object sender, EventArgs e)
+ {
+ if (IdeApp.ProjectOperations.IsBuilding (IdeApp.ProjectOperations.CurrentSelectedSolution) ||
+ IdeApp.ProjectOperations.IsRunning (IdeApp.ProjectOperations.CurrentSelectedSolution))
+ return;
- bool buildBeforeExecuting = IdeApp.Preferences.BuildBeforeRunningTests;
+ var foundTest = UnitTestService.SearchTestByDocumentId (testCase);
+ if (foundTest != null) {
+ RunTest (foundTest);
+ return;
+ }
- if (buildBeforeExecuting) {
- await IdeApp.ProjectOperations.Build (project).Task;
- await UnitTestService.RefreshTests (CancellationToken.None);
- }
+ bool buildBeforeExecuting = IdeApp.Preferences.BuildBeforeRunningTests;
- foundTest = UnitTestService.SearchTestByDocumentId (testCase);
- if (foundTest != null)
- RunTest (foundTest);
- else
- UnitTestService.ReportExecutionError (GettextCatalog.GetString ("Unit test '{0}' could not be loaded.", testCase));
+ if (buildBeforeExecuting) {
+ await IdeApp.ProjectOperations.Build (project).Task;
+ await UnitTestService.RefreshTests (CancellationToken.None);
}
- internal void Select (object sender, EventArgs e)
- {
- var test = UnitTestService.SearchTestByDocumentId (testCase);
- if (test == null)
- return;
- UnitTestService.CurrentSelectedTest = test;
- }
+ foundTest = UnitTestService.SearchTestByDocumentId (testCase);
+ if (foundTest != null)
+ RunTest (foundTest);
+ else
+ UnitTestService.ReportExecutionError (GettextCatalog.GetString ("Unit test '{0}' could not be loaded.", testCase));
+ }
- void RunTest (UnitTest test)
- {
- var debugModeSet = Runtime.ProcessService.GetDebugExecutionMode ();
- Core.Execution.IExecutionHandler ctx = null;
- if (debug && debugModeSet != null) {
- foreach (var executionMode in debugModeSet.ExecutionModes) {
- if (test.CanRun (executionMode.ExecutionHandler)) {
- ctx = executionMode.ExecutionHandler;
- break;
- }
+ internal void Select (object sender, EventArgs e)
+ {
+ var test = UnitTestService.SearchTestByDocumentId (testCase);
+ if (test == null)
+ return;
+ UnitTestService.CurrentSelectedTest = test;
+ }
+
+ void RunTest (UnitTest test)
+ {
+ var debugModeSet = Runtime.ProcessService.GetDebugExecutionMode ();
+ Core.Execution.IExecutionHandler ctx = null;
+ if (debug && debugModeSet != null) {
+ foreach (var executionMode in debugModeSet.ExecutionModes) {
+ if (test.CanRun (executionMode.ExecutionHandler)) {
+ ctx = executionMode.ExecutionHandler;
+ break;
}
}
- // NUnitService.Instance.RunTest (test, ctx);
- var pad = IdeApp.Workbench.GetPad<TestPad> ();
- var content = (TestPad)pad.Content;
- content.RunTest (test, ctx);
}
+ // NUnitService.Instance.RunTest (test, ctx);
+ var pad = IdeApp.Workbench.GetPad<TestPad> ();
+ var content = (TestPad)pad.Content;
+ content.RunTest (test, ctx);
}
}
}
diff --git a/main/src/addins/MonoDevelop.UnitTesting/Services/SolutionFolderTestGroup.cs b/main/src/addins/MonoDevelop.UnitTesting/Services/SolutionFolderTestGroup.cs
index 5346301540..bcf3ebbe39 100644
--- a/main/src/addins/MonoDevelop.UnitTesting/Services/SolutionFolderTestGroup.cs
+++ b/main/src/addins/MonoDevelop.UnitTesting/Services/SolutionFolderTestGroup.cs
@@ -64,7 +64,7 @@ namespace MonoDevelop.UnitTesting
public override void Dispose ()
{
folder.NameChanged -= OnCombineRenamed;
- if (folder.IsRoot) {
+ if (folder.IsRoot && folder.ParentSolution != null) {
folder.ParentSolution.SolutionItemAdded -= OnEntryChanged;
folder.ParentSolution.SolutionItemRemoved -= OnEntryChanged;
}