Browse Source

MbUnit Pad additions - Goto definition implemented, error list displayed after a test run with errors, and after a build the test tree auto-refreshes.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@512 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 20 years ago
parent
commit
e928f20176
  1. 32
      src/AddIns/Misc/MbUnitPad/Project/Src/MbUnitPad.cs
  2. 141
      src/AddIns/Misc/MbUnitPad/Project/Src/TestTreeView.cs
  3. 9
      src/Main/Base/Project/Src/Commands/BuildCommands.cs
  4. 5
      src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs

32
src/AddIns/Misc/MbUnitPad/Project/Src/MbUnitPad.cs

@ -50,6 +50,7 @@ namespace ICSharpCode.MbUnitPad
ctl = new Panel(); ctl = new Panel();
treeView = new TestTreeView(); treeView = new TestTreeView();
treeView.Dock = DockStyle.Fill; treeView.Dock = DockStyle.Fill;
treeView.TypeTree.KeyPress += TreeViewKeyPress;
ctl.Controls.Add(treeView); ctl.Controls.Add(treeView);
toolStrip = ToolbarService.CreateToolStrip(this, "/SharpDevelop/Pads/MbUnitPad/Toolbar"); toolStrip = ToolbarService.CreateToolStrip(this, "/SharpDevelop/Pads/MbUnitPad/Toolbar");
@ -58,6 +59,7 @@ namespace ICSharpCode.MbUnitPad
ProjectService.SolutionLoaded += OnSolutionLoaded; ProjectService.SolutionLoaded += OnSolutionLoaded;
ProjectService.SolutionClosed += OnSolutionClosed; ProjectService.SolutionClosed += OnSolutionClosed;
ProjectService.EndBuild += OnEndBuild;
} }
/// <summary> /// <summary>
@ -67,6 +69,7 @@ namespace ICSharpCode.MbUnitPad
{ {
ProjectService.SolutionLoaded -= OnSolutionLoaded; ProjectService.SolutionLoaded -= OnSolutionLoaded;
ProjectService.SolutionClosed -= OnSolutionClosed; ProjectService.SolutionClosed -= OnSolutionClosed;
ProjectService.EndBuild -= OnEndBuild;
ctl.Dispose(); ctl.Dispose();
} }
@ -89,6 +92,7 @@ namespace ICSharpCode.MbUnitPad
public void RunTests() public void RunTests()
{ {
TaskService.Clear();
if (treeView.TypeTree.Nodes.Count == 0) { if (treeView.TypeTree.Nodes.Count == 0) {
treeView.TreePopulated += StartTestsAfterTreePopulation; treeView.TreePopulated += StartTestsAfterTreePopulation;
treeView.FinishTests += FinishTests; treeView.FinishTests += FinishTests;
@ -106,6 +110,7 @@ namespace ICSharpCode.MbUnitPad
treeView.AbortWorkerThread(); treeView.AbortWorkerThread();
runningTests = false; runningTests = false;
UpdateToolbar(); UpdateToolbar();
ShowErrorList();
} }
void FinishTests(object sender, EventArgs e) void FinishTests(object sender, EventArgs e)
@ -113,6 +118,7 @@ namespace ICSharpCode.MbUnitPad
treeView.FinishTests -= FinishTests; treeView.FinishTests -= FinishTests;
runningTests = false; runningTests = false;
WorkbenchSingleton.SafeThreadAsyncCall(this, "UpdateToolbar"); WorkbenchSingleton.SafeThreadAsyncCall(this, "UpdateToolbar");
WorkbenchSingleton.SafeThreadAsyncCall(this, "ShowErrorList");
} }
void StartTestsAfterTreePopulation(object sender, EventArgs e) void StartTestsAfterTreePopulation(object sender, EventArgs e)
@ -126,6 +132,7 @@ namespace ICSharpCode.MbUnitPad
public void ReloadAssemblyList() public void ReloadAssemblyList()
{ {
LoggingService.Debug("ReloadAssemblyList");
treeView.TestDomains.Clear(); treeView.TestDomains.Clear();
foreach (IProject project in ProjectService.OpenSolution.Projects) { foreach (IProject project in ProjectService.OpenSolution.Projects) {
bool referenceFound = false; bool referenceFound = false;
@ -181,5 +188,30 @@ namespace ICSharpCode.MbUnitPad
{ {
ToolbarService.UpdateToolbar(toolStrip); ToolbarService.UpdateToolbar(toolStrip);
} }
void TreeViewKeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\r') {
treeView.GotoDefinition();
} else if (e.KeyChar == ' ') {
RunTests();
}
}
void ShowErrorList()
{
if (TaskService.TaskCount > 0) {
WorkbenchSingleton.Workbench.GetPad(typeof(ErrorList)).BringPadToFront();
}
}
void OnEndBuild(object sender, EventArgs e)
{
LoggingService.Info("OnEndBuild");
if (treeView.IsPopulated) {
LoggingService.Debug("treeView.IsPopulated == true");
WorkbenchSingleton.SafeThreadAsyncCall(this, "ReloadAssemblyList");
}
}
} }
} }

141
src/AddIns/Misc/MbUnitPad/Project/Src/TestTreeView.cs

@ -7,11 +7,14 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using System.Windows.Forms; using System.Windows.Forms;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
using MbUnit.Forms; using MbUnit.Forms;
using MbUnit.Core; using MbUnit.Core;
using MbUnit.Core.Graph; using MbUnit.Core.Graph;
@ -58,6 +61,12 @@ namespace ICSharpCode.MbUnitPad
} }
} }
public bool IsPopulated {
get {
return TypeTree.Nodes.Count > 0;
}
}
public void ExpandChildNode(TreeNode node) public void ExpandChildNode(TreeNode node)
{ {
TypeTree.BeginUpdate(); TypeTree.BeginUpdate();
@ -94,38 +103,42 @@ namespace ICSharpCode.MbUnitPad
public void GotoDefinition() public void GotoDefinition()
{ {
MessageBox.Show("Not implemented."); UnitTreeNode node = SelectedNode as UnitTreeNode;
// UnitTreeNode node = SelectedNode as UnitTreeNode; if (node != null) {
// if (node != null) { string methodName = null;
// string fullMemberName = null; string fixtureName = null;
// Fixture fixture = null; switch (node.TestNodeType) {
// switch (node.TestNodeType) { case TestNodeType.Test:
// case TestNodeType.Test: methodName = node.Text;
// fixture = FindFixture(node.DomainIdentifier, node.Parent.Text); fixtureName = node.Parent.Text;
// if (fixture != null) break;
// fullMemberName = String.Concat(fixture.Type.FullName, ".", node.Text);
// break; case TestNodeType.Fixture:
// fixtureName = node.Text;
// case TestNodeType.Fixture: break;
// fixture = FindFixture(node.DomainIdentifier, node.Text); }
// if (fixture != null)
// fullMemberName = fixture.Type.FullName; if (fixtureName != null) {
// break; List<IClass> fixtures = FindTestFixtures(fixtureName);
// } if (fixtures.Count > 0) {
// if (methodName == null) {
// LoggingService.Debug("MemberName=" + fullMemberName); // Go to fixture definition.
// if (fullMemberName != null) { IClass c = fixtures[0];
// foreach (IProjectContent projectContent in ParserService.AllProjectContents) { if (c.CompilationUnit != null) {
// LoggingService.Debug("Checking project content..."); FileService.JumpToFilePosition(c.CompilationUnit.FileName, c.Region.BeginLine - 1, c.Region.BeginColumn - 1);
// Position pos = projectContent.GetPosition(fullMemberName); }
// if (pos != null && pos.Cu != null) { } else {
// LoggingService.Debug("Pos=" + pos.Line + ", " + pos.Column); foreach (IClass c in fixtures) {
// FileService.JumpToFilePosition(pos.Cu.FileName, Math.Max(0, pos.Line - 1), Math.Max(0, pos.Column - 1)); IMethod method = FindTestMethod(c, methodName);
// break; if (method != null) {
// } FileService.JumpToFilePosition(c.CompilationUnit.FileName, method.Region.BeginLine - 1, method.Region.BeginColumn - 1);
// } break;
// } }
// } }
}
}
}
}
} }
static MessageViewCategory testRunnerCategory; static MessageViewCategory testRunnerCategory;
@ -251,28 +264,46 @@ namespace ICSharpCode.MbUnitPad
} }
} }
// TreeTestDomain FindTestDomain(Guid id) List<IClass> FindTestFixtures(string name)
// { {
// foreach (TreeTestDomain d in TestDomains) { List<IClass> fixtures = new List<IClass>();
// if (d.Identifier == id) { if (ProjectService.OpenSolution != null) {
// return d; foreach (IProject project in ProjectService.OpenSolution.Projects) {
// } IProjectContent projectContent = ParserService.GetProjectContent(project);
// } if (projectContent != null) {
// return null; foreach (IClass c in projectContent.Classes) {
// } if (c.Name == name) {
// if (HasAttribute(c.Attributes, "TestFixture")) {
// Fixture FindFixture(Guid testDomainId, string name) fixtures.Add(c);
// { }
// TestDomain testDomain = FindTestDomain(testDomainId); }
// if (testDomain != null) { }
// FixtureDependencyGraph graph = testDomain.TestEngine.Explorer.FixtureGraph; }
// foreach (Fixture fixture in graph.Fixtures) { }
// if (fixture.Name == name) { }
// return fixture; return fixtures;
// } }
// }
// } IMethod FindTestMethod(IClass c, string name)
// return null; {
// } foreach (IMethod method in c.Methods) {
if (method.Name == name) {
if (HasAttribute(method.Attributes, "Test")) {
return method;
}
}
}
return null;
}
bool HasAttribute(IList<IAttribute> attributes, string name)
{
foreach (IAttribute attr in attributes) {
if (attr.Name == name) {
return true;
}
}
return false;
}
} }
} }

9
src/Main/Base/Project/Src/Commands/BuildCommands.cs

@ -50,8 +50,14 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
if (ProjectService.OpenSolution != null) { if (ProjectService.OpenSolution != null) {
Build.BeforeBuild(); Build.BeforeBuild();
Build.ShowResults(ProjectService.OpenSolution.Build()); Build.ShowResults(ProjectService.OpenSolution.Build());
Build.AfterBuild();
} }
} }
public static void AfterBuild()
{
ProjectService.OnEndBuild();
}
} }
public class Rebuild : AbstractMenuCommand public class Rebuild : AbstractMenuCommand
@ -61,6 +67,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
if (ProjectService.OpenSolution != null) { if (ProjectService.OpenSolution != null) {
Build.BeforeBuild(); Build.BeforeBuild();
Build.ShowResults(ProjectService.OpenSolution.Rebuild()); Build.ShowResults(ProjectService.OpenSolution.Rebuild());
Build.AfterBuild();
} }
} }
} }
@ -107,6 +114,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
if (ProjectService.CurrentProject != null) { if (ProjectService.CurrentProject != null) {
Build.BeforeBuild(); Build.BeforeBuild();
BuildProject.ShowResults(ProjectService.CurrentProject.Build()); BuildProject.ShowResults(ProjectService.CurrentProject.Build());
Build.AfterBuild();
} }
} }
} }
@ -118,6 +126,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
if (ProjectService.CurrentProject != null) { if (ProjectService.CurrentProject != null) {
Build.BeforeBuild(); Build.BeforeBuild();
BuildProject.ShowResults(ProjectService.CurrentProject.Rebuild()); BuildProject.ShowResults(ProjectService.CurrentProject.Rebuild());
Build.AfterBuild();
} }
} }
} }

5
src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs

@ -385,6 +385,11 @@ namespace ICSharpCode.SharpDevelop.Project
} }
} }
public static void OnEndBuild()
{
OnEndBuild(new EventArgs());
}
static void OnEndBuild(EventArgs e) static void OnEndBuild(EventArgs e)
{ {
if (EndBuild != null) { if (EndBuild != null) {

Loading…
Cancel
Save