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 @@ -50,6 +50,7 @@ namespace ICSharpCode.MbUnitPad
ctl = new Panel();
treeView = new TestTreeView();
treeView.Dock = DockStyle.Fill;
treeView.TypeTree.KeyPress += TreeViewKeyPress;
ctl.Controls.Add(treeView);
toolStrip = ToolbarService.CreateToolStrip(this, "/SharpDevelop/Pads/MbUnitPad/Toolbar");
@ -58,6 +59,7 @@ namespace ICSharpCode.MbUnitPad @@ -58,6 +59,7 @@ namespace ICSharpCode.MbUnitPad
ProjectService.SolutionLoaded += OnSolutionLoaded;
ProjectService.SolutionClosed += OnSolutionClosed;
ProjectService.EndBuild += OnEndBuild;
}
/// <summary>
@ -67,6 +69,7 @@ namespace ICSharpCode.MbUnitPad @@ -67,6 +69,7 @@ namespace ICSharpCode.MbUnitPad
{
ProjectService.SolutionLoaded -= OnSolutionLoaded;
ProjectService.SolutionClosed -= OnSolutionClosed;
ProjectService.EndBuild -= OnEndBuild;
ctl.Dispose();
}
@ -89,6 +92,7 @@ namespace ICSharpCode.MbUnitPad @@ -89,6 +92,7 @@ namespace ICSharpCode.MbUnitPad
public void RunTests()
{
TaskService.Clear();
if (treeView.TypeTree.Nodes.Count == 0) {
treeView.TreePopulated += StartTestsAfterTreePopulation;
treeView.FinishTests += FinishTests;
@ -106,6 +110,7 @@ namespace ICSharpCode.MbUnitPad @@ -106,6 +110,7 @@ namespace ICSharpCode.MbUnitPad
treeView.AbortWorkerThread();
runningTests = false;
UpdateToolbar();
ShowErrorList();
}
void FinishTests(object sender, EventArgs e)
@ -113,6 +118,7 @@ namespace ICSharpCode.MbUnitPad @@ -113,6 +118,7 @@ namespace ICSharpCode.MbUnitPad
treeView.FinishTests -= FinishTests;
runningTests = false;
WorkbenchSingleton.SafeThreadAsyncCall(this, "UpdateToolbar");
WorkbenchSingleton.SafeThreadAsyncCall(this, "ShowErrorList");
}
void StartTestsAfterTreePopulation(object sender, EventArgs e)
@ -126,6 +132,7 @@ namespace ICSharpCode.MbUnitPad @@ -126,6 +132,7 @@ namespace ICSharpCode.MbUnitPad
public void ReloadAssemblyList()
{
LoggingService.Debug("ReloadAssemblyList");
treeView.TestDomains.Clear();
foreach (IProject project in ProjectService.OpenSolution.Projects) {
bool referenceFound = false;
@ -181,5 +188,30 @@ namespace ICSharpCode.MbUnitPad @@ -181,5 +188,30 @@ namespace ICSharpCode.MbUnitPad
{
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 @@ @@ -7,11 +7,14 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
using MbUnit.Forms;
using MbUnit.Core;
using MbUnit.Core.Graph;
@ -58,6 +61,12 @@ namespace ICSharpCode.MbUnitPad @@ -58,6 +61,12 @@ namespace ICSharpCode.MbUnitPad
}
}
public bool IsPopulated {
get {
return TypeTree.Nodes.Count > 0;
}
}
public void ExpandChildNode(TreeNode node)
{
TypeTree.BeginUpdate();
@ -94,38 +103,42 @@ namespace ICSharpCode.MbUnitPad @@ -94,38 +103,42 @@ namespace ICSharpCode.MbUnitPad
public void GotoDefinition()
{
MessageBox.Show("Not implemented.");
// UnitTreeNode node = SelectedNode as UnitTreeNode;
// if (node != null) {
// string fullMemberName = null;
// Fixture fixture = null;
// switch (node.TestNodeType) {
// case TestNodeType.Test:
// fixture = FindFixture(node.DomainIdentifier, node.Parent.Text);
// if (fixture != null)
// fullMemberName = String.Concat(fixture.Type.FullName, ".", node.Text);
// break;
//
// case TestNodeType.Fixture:
// fixture = FindFixture(node.DomainIdentifier, node.Text);
// if (fixture != null)
// fullMemberName = fixture.Type.FullName;
// break;
// }
//
// LoggingService.Debug("MemberName=" + fullMemberName);
// if (fullMemberName != null) {
// foreach (IProjectContent projectContent in ParserService.AllProjectContents) {
// LoggingService.Debug("Checking project content...");
// Position pos = projectContent.GetPosition(fullMemberName);
// if (pos != null && pos.Cu != null) {
// LoggingService.Debug("Pos=" + pos.Line + ", " + pos.Column);
// FileService.JumpToFilePosition(pos.Cu.FileName, Math.Max(0, pos.Line - 1), Math.Max(0, pos.Column - 1));
// break;
// }
// }
// }
// }
UnitTreeNode node = SelectedNode as UnitTreeNode;
if (node != null) {
string methodName = null;
string fixtureName = null;
switch (node.TestNodeType) {
case TestNodeType.Test:
methodName = node.Text;
fixtureName = node.Parent.Text;
break;
case TestNodeType.Fixture:
fixtureName = node.Text;
break;
}
if (fixtureName != null) {
List<IClass> fixtures = FindTestFixtures(fixtureName);
if (fixtures.Count > 0) {
if (methodName == null) {
// Go to fixture definition.
IClass c = fixtures[0];
if (c.CompilationUnit != null) {
FileService.JumpToFilePosition(c.CompilationUnit.FileName, c.Region.BeginLine - 1, c.Region.BeginColumn - 1);
}
} else {
foreach (IClass c in fixtures) {
IMethod method = FindTestMethod(c, methodName);
if (method != null) {
FileService.JumpToFilePosition(c.CompilationUnit.FileName, method.Region.BeginLine - 1, method.Region.BeginColumn - 1);
break;
}
}
}
}
}
}
}
static MessageViewCategory testRunnerCategory;
@ -251,28 +264,46 @@ namespace ICSharpCode.MbUnitPad @@ -251,28 +264,46 @@ namespace ICSharpCode.MbUnitPad
}
}
// TreeTestDomain FindTestDomain(Guid id)
// {
// foreach (TreeTestDomain d in TestDomains) {
// if (d.Identifier == id) {
// return d;
// }
// }
// return null;
// }
//
// Fixture FindFixture(Guid testDomainId, string name)
// {
// 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 null;
// }
List<IClass> FindTestFixtures(string name)
{
List<IClass> fixtures = new List<IClass>();
if (ProjectService.OpenSolution != null) {
foreach (IProject project in ProjectService.OpenSolution.Projects) {
IProjectContent projectContent = ParserService.GetProjectContent(project);
if (projectContent != null) {
foreach (IClass c in projectContent.Classes) {
if (c.Name == name) {
if (HasAttribute(c.Attributes, "TestFixture")) {
fixtures.Add(c);
}
}
}
}
}
}
return fixtures;
}
IMethod FindTestMethod(IClass c, string name)
{
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 @@ -50,8 +50,14 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
if (ProjectService.OpenSolution != null) {
Build.BeforeBuild();
Build.ShowResults(ProjectService.OpenSolution.Build());
Build.AfterBuild();
}
}
public static void AfterBuild()
{
ProjectService.OnEndBuild();
}
}
public class Rebuild : AbstractMenuCommand
@ -61,6 +67,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands @@ -61,6 +67,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
if (ProjectService.OpenSolution != null) {
Build.BeforeBuild();
Build.ShowResults(ProjectService.OpenSolution.Rebuild());
Build.AfterBuild();
}
}
}
@ -107,6 +114,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands @@ -107,6 +114,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
if (ProjectService.CurrentProject != null) {
Build.BeforeBuild();
BuildProject.ShowResults(ProjectService.CurrentProject.Build());
Build.AfterBuild();
}
}
}
@ -118,6 +126,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands @@ -118,6 +126,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
if (ProjectService.CurrentProject != null) {
Build.BeforeBuild();
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 @@ -385,6 +385,11 @@ namespace ICSharpCode.SharpDevelop.Project
}
}
public static void OnEndBuild()
{
OnEndBuild(new EventArgs());
}
static void OnEndBuild(EventArgs e)
{
if (EndBuild != null) {

Loading…
Cancel
Save