From 4117d98d0f84c39c3da443e235aa7069f08ba5c3 Mon Sep 17 00:00:00 2001 From: Tomasz Tretkowski Date: Fri, 21 Oct 2011 20:34:11 +0200 Subject: [PATCH] Moved enumerating of all test members from TestProject to test frameworks. --- .../src/MSpecTestFramework.cs | 7 ++++ .../Src/IRegisteredTestFrameworks.cs | 5 ++- .../UnitTesting/Src/NUnitTestFramework.cs | 10 ++++- .../Src/RegisteredTestFrameworks.cs | 7 ++++ .../Analysis/UnitTesting/Src/TestClass.cs | 40 +++++++------------ .../Analysis/UnitTesting/Src/TestFramework.cs | 3 ++ .../Test/Utils/MockNUnitTestFramework.cs | 4 ++ .../Test/Utils/MockTestFramework.cs | 4 ++ .../Project/Src/PythonTestFramework.cs | 12 +++++- .../Project/Src/RubyTestFramework.cs | 17 ++++++-- 10 files changed, 77 insertions(+), 32 deletions(-) diff --git a/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestFramework.cs b/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestFramework.cs index ac9d5c102e..b0b4b74f76 100644 --- a/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestFramework.cs +++ b/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestFramework.cs @@ -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 return HasSpecificationMembers(c) && !IsBehavior(c); } + public IEnumerable 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) diff --git a/src/AddIns/Analysis/UnitTesting/Src/IRegisteredTestFrameworks.cs b/src/AddIns/Analysis/UnitTesting/Src/IRegisteredTestFrameworks.cs index a01f55f0b5..6bcd921064 100644 --- a/src/AddIns/Analysis/UnitTesting/Src/IRegisteredTestFrameworks.cs +++ b/src/AddIns/Analysis/UnitTesting/Src/IRegisteredTestFrameworks.cs @@ -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 bool IsTestClass(IClass c); bool IsTestProject(IProject project); - bool IsBuildNeededBeforeTestRunForProject(IProject project); + IEnumerable GetTestMembersFor(IClass @class); + + bool IsBuildNeededBeforeTestRunForProject(IProject project); } } diff --git a/src/AddIns/Analysis/UnitTesting/Src/NUnitTestFramework.cs b/src/AddIns/Analysis/UnitTesting/Src/NUnitTestFramework.cs index 88314c15ff..6c9bf0685e 100644 --- a/src/AddIns/Analysis/UnitTesting/Src/NUnitTestFramework.cs +++ b/src/AddIns/Analysis/UnitTesting/Src/NUnitTestFramework.cs @@ -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 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 return false; } - bool IsTestMethod(IMethod method) + public IEnumerable GetTestMembersFor(IClass @class) { + return @class.Methods.Where(IsTestMethod); + } + + static bool IsTestMethod(IMethod method) { var nameComparer = GetNameComparer(method.DeclaringType); if (nameComparer != null) { diff --git a/src/AddIns/Analysis/UnitTesting/Src/RegisteredTestFrameworks.cs b/src/AddIns/Analysis/UnitTesting/Src/RegisteredTestFrameworks.cs index 444c79bb12..37ef125f6f 100644 --- a/src/AddIns/Analysis/UnitTesting/Src/RegisteredTestFrameworks.cs +++ b/src/AddIns/Analysis/UnitTesting/Src/RegisteredTestFrameworks.cs @@ -39,6 +39,13 @@ namespace ICSharpCode.UnitTesting return false; } + public IEnumerable 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) { diff --git a/src/AddIns/Analysis/UnitTesting/Src/TestClass.cs b/src/AddIns/Analysis/UnitTesting/Src/TestClass.cs index 33411e7023..fd0b54dc1b 100644 --- a/src/AddIns/Analysis/UnitTesting/Src/TestClass.cs +++ b/src/AddIns/Analysis/UnitTesting/Src/TestClass.cs @@ -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); - } - /// /// Updates the test class's test result after the test member's /// test result has changed. diff --git a/src/AddIns/Analysis/UnitTesting/Src/TestFramework.cs b/src/AddIns/Analysis/UnitTesting/Src/TestFramework.cs index 43f2b3374e..84a877b590 100644 --- a/src/AddIns/Analysis/UnitTesting/Src/TestFramework.cs +++ b/src/AddIns/Analysis/UnitTesting/Src/TestFramework.cs @@ -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 bool IsTestClass(IClass c); bool IsTestProject(IProject project); + IEnumerable GetTestMembersFor(IClass @class); + ITestRunner CreateTestRunner(); ITestRunner CreateTestDebugger(); diff --git a/src/AddIns/Analysis/UnitTesting/Test/Utils/MockNUnitTestFramework.cs b/src/AddIns/Analysis/UnitTesting/Test/Utils/MockNUnitTestFramework.cs index 3100c1c312..afdfca7d42 100644 --- a/src/AddIns/Analysis/UnitTesting/Test/Utils/MockNUnitTestFramework.cs +++ b/src/AddIns/Analysis/UnitTesting/Test/Utils/MockNUnitTestFramework.cs @@ -54,6 +54,10 @@ namespace UnitTesting.Tests.Utils throw new NotImplementedException(); } + public IEnumerable GetTestMembersFor(IClass @class) { + throw new NotImplementedException(); + } + public bool IsTestClass(IClass c) { throw new NotImplementedException(); diff --git a/src/AddIns/Analysis/UnitTesting/Test/Utils/MockTestFramework.cs b/src/AddIns/Analysis/UnitTesting/Test/Utils/MockTestFramework.cs index 4649f1f503..9f9c043672 100644 --- a/src/AddIns/Analysis/UnitTesting/Test/Utils/MockTestFramework.cs +++ b/src/AddIns/Analysis/UnitTesting/Test/Utils/MockTestFramework.cs @@ -31,6 +31,10 @@ namespace UnitTesting.Tests.Utils return testMembers.Contains(member); } + public IEnumerable GetTestMembersFor(IClass @class) { + return testMembers; + } + public IMember IsTestMemberParameterUsed { get { return isTestMemberParameterUsed; } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestFramework.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestFramework.cs index 238a6b247c..ee5ae05ec0 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestFramework.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestFramework.cs @@ -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 { var method = member as IMethod; if (method != null) { - return method.Name.StartsWith("test"); + return IsTestMethod(method); } return false; } + public IEnumerable 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) { diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyTestFramework.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyTestFramework.cs index b8be7ab48d..79059affdb 100644 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyTestFramework.cs +++ b/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyTestFramework.cs @@ -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 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 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) {