diff options
Diffstat (limited to 'main/src/addins/NUnit/Gui')
-rw-r--r-- | main/src/addins/NUnit/Gui/AbstractUnitTestEditorExtension.cs | 245 | ||||
-rw-r--r-- | main/src/addins/NUnit/Gui/TestPad.cs | 1 | ||||
-rw-r--r-- | main/src/addins/NUnit/Gui/icons/unit-failed-16.png | bin | 649 -> 594 bytes | |||
-rw-r--r-- | main/src/addins/NUnit/Gui/icons/unit-failed-16@2x.png | bin | 1502 -> 1372 bytes | |||
-rw-r--r-- | main/src/addins/NUnit/Gui/icons/unit-mixed-results-16.png | bin | 776 -> 790 bytes | |||
-rw-r--r-- | main/src/addins/NUnit/Gui/icons/unit-mixed-results-16@2x.png | bin | 1847 -> 1857 bytes | |||
-rw-r--r-- | main/src/addins/NUnit/Gui/icons/unit-success-16.png | bin | 636 -> 596 bytes | |||
-rw-r--r-- | main/src/addins/NUnit/Gui/icons/unit-success-16@2x.png | bin | 1473 -> 1338 bytes |
8 files changed, 88 insertions, 158 deletions
diff --git a/main/src/addins/NUnit/Gui/AbstractUnitTestEditorExtension.cs b/main/src/addins/NUnit/Gui/AbstractUnitTestEditorExtension.cs index 3b3114af61..fa33c8b34e 100644 --- a/main/src/addins/NUnit/Gui/AbstractUnitTestEditorExtension.cs +++ b/main/src/addins/NUnit/Gui/AbstractUnitTestEditorExtension.cs @@ -25,24 +25,25 @@ // THE SOFTWARE. using System; -using MonoDevelop.Ide.Gui.Content; using System.Collections.Generic; using System.Threading; -using Mono.TextEditor; using MonoDevelop.NUnit; using MonoDevelop.Core; using MonoDevelop.Ide; using Gtk; using MonoDevelop.Components; +using System.Threading.Tasks; +using MonoDevelop.Ide.Editor.Extension; +using MonoDevelop.Ide.Editor; namespace MonoDevelop.NUnit { public abstract class AbstractUnitTestTextEditorExtension : TextEditorExtension { - public override void Initialize () + protected override void Initialize () { base.Initialize (); - Document.DocumentParsed += HandleDocumentParsed; + DocumentContext.DocumentParsed += HandleDocumentParsed; if (IdeApp.Workbench == null) return; NUnitService.Instance.TestSessionCompleted += HandleTestSessionCompleted; @@ -50,22 +51,21 @@ namespace MonoDevelop.NUnit void HandleTestSessionCompleted (object sender, EventArgs e) { - if (document.Editor == null) - return; - document.Editor.Parent.TextArea.RedrawMargin (document.Editor.Parent.TextArea.ActionMargin); + foreach (var marker in currentMarker) + marker.UpdateState (); } public override void Dispose () { NUnitService.Instance.TestSessionCompleted -= HandleTestSessionCompleted; RemoveHandler (); - Document.DocumentParsed -= HandleDocumentParsed; + DocumentContext.DocumentParsed -= HandleDocumentParsed; base.Dispose (); } CancellationTokenSource src = new CancellationTokenSource (); - public abstract IList<UnitTestLocation> GatherUnitTests (); + public abstract Task<IList<UnitTestLocation>> GatherUnitTests (CancellationToken token); readonly static PropertyWrapper<bool> EnableUnitTestEditorIntegration = new PropertyWrapper<bool> ("Testing.EnableUnitTestEditorIntegration", false); @@ -79,33 +79,31 @@ namespace MonoDevelop.NUnit ThreadPool.QueueUserWorkItem (delegate { if (token.IsCancellationRequested) return; - var foundTests = GatherUnitTests (); - if (foundTests == null) - return; - Application.Invoke (delegate { - var editor = document.Editor; - if (editor == null) - return; - var textEditor = editor.Parent; - if (textEditor == null) - return; - var actionMargin = textEditor.ActionMargin; - if (actionMargin == null) - return; - if (actionMargin.IsVisible ^ (foundTests.Count > 0)) - textEditor.QueueDraw (); - actionMargin.IsVisible |= foundTests.Count > 0; - foreach (var oldMarker in currentMarker) - editor.Document.RemoveMarker (oldMarker); - - foreach (var foundTest in foundTests) { - if (token.IsCancellationRequested) + try { + GatherUnitTests (token).ContinueWith (task => { + var foundTests = task.Result; + if (foundTests == null) return; - var unitTestMarker = new UnitTestMarker (foundTest, document); - currentMarker.Add (unitTestMarker); - editor.Document.AddMarker (foundTest.LineNumber, unitTestMarker); - } - }); + Application.Invoke (delegate { + foreach (var oldMarker in currentMarker) + Editor.RemoveMarker (oldMarker); + var newMarkers = new List<IUnitTestMarker> (); + foreach (var foundTest in foundTests) { + var unitTestMarker = TextMarkerFactory.CreateUnitTestMarker (Editor, new UnitTestMarkerHostImpl (this), foundTest); + newMarkers.Add (unitTestMarker); + var line = Editor.GetLineByOffset (foundTest.Offset); + if (line != null) { + Editor.AddMarker (line, unitTestMarker); + } + } + this.currentMarker = newMarkers; + }); + + }, TaskContinuationOptions.ExecuteSynchronously | + TaskContinuationOptions.NotOnCanceled | + TaskContinuationOptions.NotOnFaulted); + } catch (OperationCanceledException) { + } }); } @@ -119,69 +117,60 @@ namespace MonoDevelop.NUnit } } - List<UnitTestMarker> currentMarker = new List<UnitTestMarker>(); + List<IUnitTestMarker> currentMarker = new List<IUnitTestMarker>(); - class UnitTestMarker : MarginMarker + class UnitTestMarkerHostImpl : UnitTestMarkerHost { - readonly UnitTestLocation unitTest; - readonly MonoDevelop.Ide.Gui.Document doc; + static Menu menu; - public UnitTestMarker(UnitTestLocation unitTest, MonoDevelop.Ide.Gui.Document doc) + readonly AbstractUnitTestTextEditorExtension ext; + + public UnitTestMarkerHostImpl (AbstractUnitTestTextEditorExtension ext) { - this.unitTest = unitTest; - this.doc = doc; + if (ext == null) + throw new ArgumentNullException ("ext"); + this.ext = ext; } - public override bool CanDrawForeground (Margin margin) + #region implemented abstract members of UnitTestMarkerHost + + public override Xwt.Drawing.Image GetStatusIcon (string unitTestIdentifier, string caseId = null) { - return margin is ActionMargin; + var test = NUnitService.Instance.SearchTestById (unitTestIdentifier + caseId); + if (test != null) + return test.StatusIcon; + return TestStatusIcon.None; } - public override void InformMouseHover (TextEditor editor, Margin margin, MarginMouseEventArgs args) + public override bool IsFailure (string unitTestIdentifier, string caseId = null) { - if (!(margin is ActionMargin)) - return; - string toolTip; - if (unitTest.IsFixture) { - if (isFailed) { - toolTip = GettextCatalog.GetString ("NUnit Fixture failed (click to run)"); - if (!string.IsNullOrEmpty (failMessage)) - toolTip += Environment.NewLine + failMessage.TrimEnd (); - } else { - toolTip = GettextCatalog.GetString ("NUnit Fixture (click to run)"); - } - } else { - if (isFailed) { - toolTip = GettextCatalog.GetString ("NUnit Test failed (click to run)"); - if (!string.IsNullOrEmpty (failMessage)) - toolTip += Environment.NewLine + failMessage.TrimEnd (); - foreach (var id in unitTest.TestCases) { - var test = NUnitService.Instance.SearchTestById (unitTest.UnitTestIdentifier + id); - if (test != null) { - var result = test.GetLastResult (); - if (result != null && result.IsFailure) { - if (!string.IsNullOrEmpty (result.Message)) { - toolTip += Environment.NewLine + "Test" + id +":"; - toolTip += Environment.NewLine + result.Message.TrimEnd (); - } - } - } - - } - } else { - toolTip = GettextCatalog.GetString ("NUnit Test (click to run)"); - } + var test = NUnitService.Instance.SearchTestById (unitTestIdentifier + caseId); + if (test != null) { + var result = test.GetLastResult (); + if (result != null) + return result.IsFailure; + } + return false; + } + public override string GetMessage (string unitTestIdentifier, string caseId = null) + { + var test = NUnitService.Instance.SearchTestById (unitTestIdentifier + caseId); + if (test != null) { + var result = test.GetLastResult (); + if (result != null) + return result.Message; } - editor.TooltipText = toolTip; + return null; } - static Menu menu; + public override bool HasResult (string unitTestIdentifier, string caseId = null) + { + return NUnitService.Instance.SearchTestById (unitTestIdentifier + caseId) != null; + } - public override void InformMousePress (TextEditor editor, Margin margin, MarginMouseEventArgs args) + public override void PopupContextMenu (UnitTestLocation unitTest, int x, int y) { - if (!(margin is ActionMargin)) - return; if (menu != null) { menu.Destroy (); } @@ -190,47 +179,47 @@ namespace MonoDevelop.NUnit menu = new Menu (); if (unitTest.IsFixture) { var menuItem = new MenuItem ("_Run All"); - menuItem.Activated += new TestRunner (doc, unitTest.UnitTestIdentifier, false).Run; + menuItem.Activated += new TestRunner (unitTest.UnitTestIdentifier, false).Run; menu.Add (menuItem); if (debugModeSet != null) { menuItem = new MenuItem ("_Debug All"); - menuItem.Activated += new TestRunner (doc, unitTest.UnitTestIdentifier, true).Run; + menuItem.Activated += new TestRunner (unitTest.UnitTestIdentifier, true).Run; menu.Add (menuItem); } menuItem = new MenuItem ("_Select in Test Pad"); - menuItem.Activated += new TestRunner (doc, unitTest.UnitTestIdentifier, true).Select; + menuItem.Activated += new TestRunner (unitTest.UnitTestIdentifier, true).Select; menu.Add (menuItem); } else { if (unitTest.TestCases.Count == 0) { var menuItem = new MenuItem ("_Run"); - menuItem.Activated += new TestRunner (doc, unitTest.UnitTestIdentifier, false).Run; + menuItem.Activated += new TestRunner (unitTest.UnitTestIdentifier, false).Run; menu.Add (menuItem); if (debugModeSet != null) { menuItem = new MenuItem ("_Debug"); - menuItem.Activated += new TestRunner (doc, unitTest.UnitTestIdentifier, true).Run; + menuItem.Activated += new TestRunner (unitTest.UnitTestIdentifier, true).Run; menu.Add (menuItem); } menuItem = new MenuItem ("_Select in Test Pad"); - menuItem.Activated += new TestRunner (doc, unitTest.UnitTestIdentifier, true).Select; + menuItem.Activated += new TestRunner (unitTest.UnitTestIdentifier, true).Select; menu.Add (menuItem); } else { var menuItem = new MenuItem ("_Run All"); - menuItem.Activated += new TestRunner (doc, unitTest.UnitTestIdentifier, false).Run; + menuItem.Activated += new TestRunner (unitTest.UnitTestIdentifier, false).Run; menu.Add (menuItem); if (debugModeSet != null) { menuItem = new MenuItem ("_Debug All"); - menuItem.Activated += new TestRunner (doc, unitTest.UnitTestIdentifier, true).Run; + menuItem.Activated += new TestRunner (unitTest.UnitTestIdentifier, true).Run; menu.Add (menuItem); } menu.Add (new SeparatorMenuItem ()); foreach (var id in unitTest.TestCases) { var submenu = new Menu (); menuItem = new MenuItem ("_Run"); - menuItem.Activated += new TestRunner (doc, unitTest.UnitTestIdentifier + id, false).Run; + menuItem.Activated += new TestRunner (unitTest.UnitTestIdentifier + id, false).Run; submenu.Add (menuItem); if (debugModeSet != null) { menuItem = new MenuItem ("_Debug"); - menuItem.Activated += new TestRunner (doc, unitTest.UnitTestIdentifier + id, true).Run; + menuItem.Activated += new TestRunner (unitTest.UnitTestIdentifier + id, true).Run; submenu.Add (menuItem); } @@ -246,7 +235,7 @@ namespace MonoDevelop.NUnit } menuItem = new MenuItem ("_Select in Test Pad"); - menuItem.Activated += new TestRunner (doc, unitTest.UnitTestIdentifier + id, true).Select; + menuItem.Activated += new TestRunner (unitTest.UnitTestIdentifier + id, true).Select; submenu.Add (menuItem); @@ -259,19 +248,20 @@ namespace MonoDevelop.NUnit } } menu.ShowAll (); - editor.TextArea.ResetMouseState (); - GtkWorkarounds.ShowContextMenu (menu, editor, new Gdk.Rectangle ((int)args.X, (int)args.Y, 1, 1)); + + GtkWorkarounds.ShowContextMenu (menu, ext.Editor, new Gdk.Rectangle (x, y, 1, 1)); + } + #endregion + class TestRunner { - // readonly MonoDevelop.Ide.Gui.Document doc; readonly string testCase; readonly bool debug; - public TestRunner (MonoDevelop.Ide.Gui.Document doc, string testCase, bool debug) + public TestRunner (string testCase, bool debug) { - // this.doc = doc; this.testCase = testCase; this.debug = debug; } @@ -375,65 +365,6 @@ namespace MonoDevelop.NUnit content.RunTest (test, ctx); } } - - bool isFailed; - string failMessage; - public override void DrawForeground (TextEditor editor, Cairo.Context cr, MarginDrawMetrics metrics) - { - isFailed = false; - var test = NUnitService.Instance.SearchTestById (unitTest.UnitTestIdentifier); - bool searchCases = false; - - Xwt.Drawing.Image icon = null; - - if (test != null) { - icon = test.StatusIcon; - var result = test.GetLastResult (); - if (result == null) { - searchCases = true; - } else if (result.IsFailure) { - failMessage = result.Message; - isFailed = true; - } - } else { - searchCases = true; - } - - if (searchCases) { - foreach (var caseId in unitTest.TestCases) { - test = NUnitService.Instance.SearchTestById (unitTest.UnitTestIdentifier + caseId); - if (test != null) { - icon = test.StatusIcon; - var result = test.GetLastResult (); - if (result != null && result.IsFailure) { - failMessage = result.Message; - isFailed = true; - break; - } - } - } - } - - if (icon != null) { - if (icon.Width > metrics.Width || icon.Height > metrics.Height) - icon = icon.WithBoxSize (metrics.Width, metrics.Height); - cr.DrawImage (editor, icon, Math.Truncate (metrics.X + metrics.Width / 2 - icon.Width / 2), Math.Truncate (metrics.Y + metrics.Height / 2 - icon.Height / 2)); - } - } - } - public class UnitTestLocation - { - public int LineNumber { get; set; } - public bool IsFixture { get; set; } - public string UnitTestIdentifier { get; set; } - public bool IsIgnored { get; set; } - - public List<string> TestCases = new List<string> (); - - public UnitTestLocation (int lineNumber) - { - LineNumber = lineNumber; - } } } } diff --git a/main/src/addins/NUnit/Gui/TestPad.cs b/main/src/addins/NUnit/Gui/TestPad.cs index 96b5f929bb..5685fbc89d 100644 --- a/main/src/addins/NUnit/Gui/TestPad.cs +++ b/main/src/addins/NUnit/Gui/TestPad.cs @@ -41,7 +41,6 @@ using MonoDevelop.Ide.Execution; using MonoDevelop.Components.Docking; using MonoDevelop.Ide; using MonoDevelop.Projects; -using Mono.TextEditor; using System.Linq; using MonoDevelop.Components; using MonoDevelop.Ide.Commands; diff --git a/main/src/addins/NUnit/Gui/icons/unit-failed-16.png b/main/src/addins/NUnit/Gui/icons/unit-failed-16.png Binary files differindex ab1367642d..86e339b5f9 100644 --- a/main/src/addins/NUnit/Gui/icons/unit-failed-16.png +++ b/main/src/addins/NUnit/Gui/icons/unit-failed-16.png diff --git a/main/src/addins/NUnit/Gui/icons/unit-failed-16@2x.png b/main/src/addins/NUnit/Gui/icons/unit-failed-16@2x.png Binary files differindex fc9fa4445b..cbc92c6fce 100644 --- a/main/src/addins/NUnit/Gui/icons/unit-failed-16@2x.png +++ b/main/src/addins/NUnit/Gui/icons/unit-failed-16@2x.png diff --git a/main/src/addins/NUnit/Gui/icons/unit-mixed-results-16.png b/main/src/addins/NUnit/Gui/icons/unit-mixed-results-16.png Binary files differindex ef419bb561..aea522080b 100644 --- a/main/src/addins/NUnit/Gui/icons/unit-mixed-results-16.png +++ b/main/src/addins/NUnit/Gui/icons/unit-mixed-results-16.png diff --git a/main/src/addins/NUnit/Gui/icons/unit-mixed-results-16@2x.png b/main/src/addins/NUnit/Gui/icons/unit-mixed-results-16@2x.png Binary files differindex 03afb04a77..53eb836c07 100644 --- a/main/src/addins/NUnit/Gui/icons/unit-mixed-results-16@2x.png +++ b/main/src/addins/NUnit/Gui/icons/unit-mixed-results-16@2x.png diff --git a/main/src/addins/NUnit/Gui/icons/unit-success-16.png b/main/src/addins/NUnit/Gui/icons/unit-success-16.png Binary files differindex b167c97951..8d9f59c502 100644 --- a/main/src/addins/NUnit/Gui/icons/unit-success-16.png +++ b/main/src/addins/NUnit/Gui/icons/unit-success-16.png diff --git a/main/src/addins/NUnit/Gui/icons/unit-success-16@2x.png b/main/src/addins/NUnit/Gui/icons/unit-success-16@2x.png Binary files differindex 7abbc8ec46..12c2cd6515 100644 --- a/main/src/addins/NUnit/Gui/icons/unit-success-16@2x.png +++ b/main/src/addins/NUnit/Gui/icons/unit-success-16@2x.png |