Browse Source

Moved enumerating of all test members from TestProject to test frameworks.

pull/23/head
Tomasz Tretkowski 14 years ago
parent
commit
4117d98d0f
  1. 7
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestFramework.cs
  2. 5
      src/AddIns/Analysis/UnitTesting/Src/IRegisteredTestFrameworks.cs
  3. 10
      src/AddIns/Analysis/UnitTesting/Src/NUnitTestFramework.cs
  4. 7
      src/AddIns/Analysis/UnitTesting/Src/RegisteredTestFrameworks.cs
  5. 40
      src/AddIns/Analysis/UnitTesting/Src/TestClass.cs
  6. 3
      src/AddIns/Analysis/UnitTesting/Src/TestFramework.cs
  7. 4
      src/AddIns/Analysis/UnitTesting/Test/Utils/MockNUnitTestFramework.cs
  8. 4
      src/AddIns/Analysis/UnitTesting/Test/Utils/MockTestFramework.cs
  9. 12
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestFramework.cs
  10. 17
      src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyTestFramework.cs

7
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestFramework.cs

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
@ -28,6 +29,12 @@ namespace ICSharpCode.MachineSpecifications @@ -28,6 +29,12 @@ namespace ICSharpCode.MachineSpecifications
return HasSpecificationMembers(c) && !IsBehavior(c);
}
public IEnumerable<IMember> GetTestMembersFor(IClass @class) {
foreach (var field in @class.Fields)
if (IsSpecificationMember(field))
yield return field;
}
public bool IsTestProject(IProject project) {
if (project != null) {
foreach (ProjectItem item in project.Items)

5
src/AddIns/Analysis/UnitTesting/Src/IRegisteredTestFrameworks.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
@ -17,6 +18,8 @@ namespace ICSharpCode.UnitTesting @@ -17,6 +18,8 @@ namespace ICSharpCode.UnitTesting
bool IsTestClass(IClass c);
bool IsTestProject(IProject project);
bool IsBuildNeededBeforeTestRunForProject(IProject project);
IEnumerable<IMember> GetTestMembersFor(IClass @class);
bool IsBuildNeededBeforeTestRunForProject(IProject project);
}
}

10
src/AddIns/Analysis/UnitTesting/Src/NUnitTestFramework.cs

@ -2,6 +2,8 @@ @@ -2,6 +2,8 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Linq;
using System.Collections.Generic;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
@ -56,7 +58,7 @@ namespace ICSharpCode.UnitTesting @@ -56,7 +58,7 @@ namespace ICSharpCode.UnitTesting
return false;
}
StringComparer GetNameComparer(IClass c)
static StringComparer GetNameComparer(IClass c)
{
if (c != null) {
IProjectContent projectContent = c.ProjectContent;
@ -84,7 +86,11 @@ namespace ICSharpCode.UnitTesting @@ -84,7 +86,11 @@ namespace ICSharpCode.UnitTesting
return false;
}
bool IsTestMethod(IMethod method)
public IEnumerable<IMember> GetTestMembersFor(IClass @class) {
return @class.Methods.Where(IsTestMethod);
}
static bool IsTestMethod(IMethod method)
{
var nameComparer = GetNameComparer(method.DeclaringType);
if (nameComparer != null) {

7
src/AddIns/Analysis/UnitTesting/Src/RegisteredTestFrameworks.cs

@ -39,6 +39,13 @@ namespace ICSharpCode.UnitTesting @@ -39,6 +39,13 @@ namespace ICSharpCode.UnitTesting
return false;
}
public IEnumerable<IMember> GetTestMembersFor(IClass @class) {
ITestFramework testFramework = GetTestFramework(@class);
if (testFramework != null)
return testFramework.GetTestMembersFor(@class);
return new IMember[0];
}
ITestFramework GetTestFramework(IMember member)
{
if (member != null) {

40
src/AddIns/Analysis/UnitTesting/Src/TestClass.cs

@ -280,42 +280,32 @@ namespace ICSharpCode.UnitTesting @@ -280,42 +280,32 @@ namespace ICSharpCode.UnitTesting
TestMemberCollection GetTestMembers(IClass c)
{
TestMemberCollection testMembers = new TestMemberCollection();
foreach (IMember member in c.AllMembers) {
if (IsTestMember(member)) {
if (!testMembers.Contains(member.Name)) {
testMembers.Add(new TestMember(member));
}
}
}
foreach (var member in testFrameworks.GetTestMembersFor(c))
if (!testMembers.Contains(member.Name)) {
testMembers.Add(new TestMember(member));
}
// Add base class test members.
IClass declaringType = c;
while (c.BaseClass != null) {
foreach (var method in c.BaseClass.AllMembers) {
if (IsTestMember(method)) {
BaseTestMethod baseTestMethod = new BaseTestMethod(declaringType, method);
TestMember testMethod = new TestMember(c.BaseClass.Name, baseTestMethod);
if (method.IsVirtual) {
if (!testMembers.Contains(method.Name)) {
testMembers.Add(testMethod);
}
} else {
if (!testMembers.Contains(testMethod.Name)) {
testMembers.Add(testMethod);
}
foreach (var method in testFrameworks.GetTestMembersFor(c.BaseClass)) {
BaseTestMethod baseTestMethod = new BaseTestMethod(declaringType, method);
TestMember testMethod = new TestMember(c.BaseClass.Name, baseTestMethod);
if (method.IsVirtual) {
if (!testMembers.Contains(method.Name)) {
testMembers.Add(testMethod);
}
}
} else {
if (!testMembers.Contains(testMethod.Name)) {
testMembers.Add(testMethod);
}
}
}
c = c.BaseClass;
}
return testMembers;
}
bool IsTestMember(IMember member)
{
return testFrameworks.IsTestMember(member);
}
/// <summary>
/// Updates the test class's test result after the test member's
/// test result has changed.

3
src/AddIns/Analysis/UnitTesting/Src/TestFramework.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
@ -13,6 +14,8 @@ namespace ICSharpCode.UnitTesting @@ -13,6 +14,8 @@ namespace ICSharpCode.UnitTesting
bool IsTestClass(IClass c);
bool IsTestProject(IProject project);
IEnumerable<IMember> GetTestMembersFor(IClass @class);
ITestRunner CreateTestRunner();
ITestRunner CreateTestDebugger();

4
src/AddIns/Analysis/UnitTesting/Test/Utils/MockNUnitTestFramework.cs

@ -54,6 +54,10 @@ namespace UnitTesting.Tests.Utils @@ -54,6 +54,10 @@ namespace UnitTesting.Tests.Utils
throw new NotImplementedException();
}
public IEnumerable<IMember> GetTestMembersFor(IClass @class) {
throw new NotImplementedException();
}
public bool IsTestClass(IClass c)
{
throw new NotImplementedException();

4
src/AddIns/Analysis/UnitTesting/Test/Utils/MockTestFramework.cs

@ -31,6 +31,10 @@ namespace UnitTesting.Tests.Utils @@ -31,6 +31,10 @@ namespace UnitTesting.Tests.Utils
return testMembers.Contains(member);
}
public IEnumerable<IMember> GetTestMembersFor(IClass @class) {
return testMembers;
}
public IMember IsTestMemberParameterUsed {
get { return isTestMemberParameterUsed; }
}

12
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestFramework.cs

@ -2,6 +2,8 @@ @@ -2,6 +2,8 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
@ -14,11 +16,19 @@ namespace ICSharpCode.PythonBinding @@ -14,11 +16,19 @@ namespace ICSharpCode.PythonBinding
{
var method = member as IMethod;
if (method != null) {
return method.Name.StartsWith("test");
return IsTestMethod(method);
}
return false;
}
public IEnumerable<IMember> GetTestMembersFor(IClass @class) {
return @class.Methods.Where(IsTestMethod);
}
static bool IsTestMethod(IMethod method) {
return method.Name.StartsWith("test");
}
public bool IsTestClass(IClass c)
{
while (c != null) {

17
src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyTestFramework.cs

@ -2,6 +2,9 @@ @@ -2,6 +2,9 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
@ -13,12 +16,20 @@ namespace ICSharpCode.RubyBinding @@ -13,12 +16,20 @@ namespace ICSharpCode.RubyBinding
public bool IsTestMember(IMember member)
{
var method = member as IMethod;
if (method != null) {
return method.Name.StartsWith("test");
}
if (method != null)
return IsTestMethod(method);
return false;
}
public IEnumerable<IMember> GetTestMembersFor(IClass @class) {
return @class.Methods.Where(IsTestMethod);
}
bool IsTestMethod(IMethod method)
{
return method.Name.StartsWith("test");
}
public bool IsTestClass(IClass c)
{
while (c != null) {

Loading…
Cancel
Save