Permalink
Browse files

Fixing behavior specification runs, simplifying Task implementations …

…a bit

i.e. BehaviorTask is not needed
  • Loading branch information...
agross committed Jan 31, 2013
1 parent 43d0405 commit a58dca9e718b73dff0886fd7129972a123aa5367
Showing with 264 additions and 414 deletions.
  1. +35 −0 Source/Machine.Specifications.ReSharperRunner.6.1/EnumerableExtensions.cs
  2. +9 −8 Source/Machine.Specifications.ReSharperRunner.6.1/Factories/BehaviorFactory.cs
  3. +1 −20 Source/Machine.Specifications.ReSharperRunner.6.1/Factories/ContextFactory.cs
  4. +7 −23 Source/Machine.Specifications.ReSharperRunner.6.1/Factories/UnitTestTaskFactory.cs
  5. +2 −2 Source/Machine.Specifications.ReSharperRunner.6.1/Machine.Specifications.ReSharperRunner.6.1.csproj
  6. +7 −2 Source/Machine.Specifications.ReSharperRunner.6.1/NormalizedTypeName.cs
  7. +9 −9 Source/Machine.Specifications.ReSharperRunner.6.1/Presentation/BehaviorElement.cs
  8. +8 −27 Source/Machine.Specifications.ReSharperRunner.6.1/Presentation/Element.cs
  9. +1 −1 ...ications.ReSharperRunner.6.1/Runners/Notifications/BehaviorSpecificationRemoteTaskNotification.cs
  10. +5 −0 .../Machine.Specifications.ReSharperRunner.6.1/Runners/Notifications/SilentRemoteTaskNotification.cs
  11. +1 −1 Source/Machine.Specifications.ReSharperRunner.6.1/Runners/PerContextRunListener.cs
  12. +1 −15 Source/Machine.Specifications.ReSharperRunner.6.1/Runners/RecursiveMSpecTaskRunner.cs
  13. +37 −42 Source/Machine.Specifications.ReSharperRunner.6.1/Tasks/BehaviorSpecificationTask.cs
  14. +0 −80 Source/Machine.Specifications.ReSharperRunner.6.1/Tasks/BehaviorTask.cs
  15. +28 −26 Source/Machine.Specifications.ReSharperRunner.6.1/Tasks/ContextSpecificationTask.cs
  16. +28 −11 Source/Machine.Specifications.ReSharperRunner.6.1/Tasks/ContextTask.cs
  17. +0 −74 Source/Machine.Specifications.ReSharperRunner.6.1/Tasks/RunAssemblyContextsTask.cs
  18. +43 −0 Source/Machine.Specifications.ReSharperRunner.6.1/Tasks/RunAssemblyTask.cs
  19. +17 −48 Source/Machine.Specifications.ReSharperRunner.6.1/Tasks/Task.cs
  20. +5 −5 Source/Machine.Specifications.ReSharperRunner.7.0/Machine.Specifications.ReSharperRunner.7.0.csproj
  21. +5 −5 Source/Machine.Specifications.ReSharperRunner.7.1/Machine.Specifications.ReSharperRunner.7.1.csproj
  22. +5 −5 Source/Machine.Specifications.dotCoverRunner.2.0/Machine.Specifications.dotCoverRunner.2.0.csproj
  23. +5 −5 Source/Machine.Specifications.dotCoverRunner.2.1/Machine.Specifications.dotCoverRunner.2.1.csproj
  24. +5 −5 Source/Machine.Specifications.dotCoverRunner.2.2/Machine.Specifications.dotCoverRunner.2.2.csproj
@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+
+namespace Machine.Specifications.ReSharperRunner
+{
+ static class EnumerableExtensions
+ {
+ internal static IEnumerable<T> Flatten<T>(this IEnumerable<T> source,
+ Func<T, IEnumerable<T>> childSelector)
+ {
+ foreach (var s in source)
+ {
+ yield return s;
+
+ var childs = childSelector(s);
+ foreach (var c in childs.Flatten(childSelector))
+ {
+ yield return c;
+ }
+ }
+ }
+
+ internal static IEnumerable<T> Flatten<T>(this T source,
+ Func<T, IEnumerable<T>> childSelector)
+ {
+ yield return source;
+
+ var childs = childSelector(source);
+ foreach (var c in childs.Flatten(childSelector))
+ {
+ yield return c;
+ }
+ }
+ }
+}
@@ -5,6 +5,7 @@
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.Caches;
using JetBrains.ReSharper.Psi.Impl.Reflection2;
+using JetBrains.ReSharper.Psi.Util;
using JetBrains.ReSharper.UnitTestFramework;
using JetBrains.ReSharper.UnitTestFramework.Elements;
@@ -55,7 +56,7 @@ public BehaviorElement CreateBehavior(IDeclaredElement field)
return null;
}
- var fullyQualifiedTypeName = new NormalizedTypeName(field as ITypeOwner);
+ var fieldType = new NormalizedTypeName(field as ITypeOwner);
var behavior = GetOrCreateBehavior(_provider,
_manager,
@@ -67,7 +68,7 @@ public BehaviorElement CreateBehavior(IDeclaredElement field)
clazz.GetClrName(),
field.ShortName,
field.IsIgnored(),
- fullyQualifiedTypeName);
+ fieldType);
foreach (var child in behavior.Children)
{
@@ -83,7 +84,7 @@ public BehaviorElement CreateBehavior(ContextElement context, IMetadataField beh
var typeContainingBehaviorSpecifications = behavior.GetFirstGenericArgument();
var metadataTypeName = behavior.FirstGenericArgumentClass().FullyQualifiedName();
- var fullyQualifiedTypeName = new NormalizedTypeName(metadataTypeName);
+ var fieldType = new NormalizedTypeName(new ClrTypeName(metadataTypeName));
var behaviorElement = GetOrCreateBehavior(_provider,
_manager,
@@ -95,7 +96,7 @@ public BehaviorElement CreateBehavior(ContextElement context, IMetadataField beh
_reflectionTypeNameCache.GetClrName(behavior.DeclaringType),
behavior.Name,
behavior.IsIgnored() || typeContainingBehaviorSpecifications.IsIgnored(),
- fullyQualifiedTypeName);
+ fieldType);
return behaviorElement;
}
@@ -110,9 +111,9 @@ public BehaviorElement CreateBehavior(ContextElement context, IMetadataField beh
IClrTypeName declaringTypeName,
string fieldName,
bool isIgnored,
- string fullyQualifiedTypeName)
+ string fieldType)
{
- var id = BehaviorElement.CreateId(context, fullyQualifiedTypeName, fieldName);
+ var id = BehaviorElement.CreateId(context, fieldType, fieldName);
var behavior = manager.GetElementById(project, id) as BehaviorElement;
if (behavior != null)
{
@@ -129,7 +130,7 @@ public BehaviorElement CreateBehavior(ContextElement context, IMetadataField beh
declaringTypeName,
fieldName,
isIgnored,
- fullyQualifiedTypeName);
+ fieldType);
}
public void UpdateChildState(IDeclaredElement field)
@@ -142,7 +143,7 @@ public void UpdateChildState(IDeclaredElement field)
foreach (var element in behavior
.Children.Where(x => x.State == UnitTestElementState.Pending)
- .Traverse(x => x.Children))
+ .Flatten(x => x.Children))
{
element.State = UnitTestElementState.Invalid;
}
@@ -1,4 +1,3 @@
-using System;
using System.Collections.Generic;
using System.Linq;
@@ -125,28 +124,10 @@ public void UpdateChildState(ITypeElement type)
foreach (var element in context
.Children.Where(x => x.State == UnitTestElementState.Pending)
- .Traverse(x => x.Children))
+ .Flatten(x => x.Children))
{
element.State = UnitTestElementState.Invalid;
}
}
}
-
- static class EnumExt
- {
- internal static IEnumerable<T> Traverse<T>(this IEnumerable<T> source,
- Func<T, IEnumerable<T>> childSelector)
- {
- foreach (var s in source)
- {
- yield return s;
-
- var childs = childSelector(s);
- foreach (var c in childs.Traverse(childSelector))
- {
- yield return c;
- }
- }
- }
- }
}
@@ -6,7 +6,7 @@
namespace Machine.Specifications.ReSharperRunner.Factories
{
- internal class UnitTestTaskFactory
+ class UnitTestTaskFactory
{
readonly string _providerId;
@@ -27,50 +27,34 @@ public UnitTestTask CreateRunAssemblyTask(ContextElement context)
new RunAssemblyTask(_providerId, context.AssemblyLocation));
}
- public UnitTestTask CreateContextTask(ContextElement context, bool isExplicit)
+ public UnitTestTask CreateContextTask(ContextElement context)
{
return new UnitTestTask(context,
new ContextTask(_providerId,
context.AssemblyLocation,
- context.GetTypeClrName().FullName,
- false));
+ context.GetTypeClrName().FullName));
}
public UnitTestTask CreateContextSpecificationTask(ContextElement context,
- ContextSpecificationElement contextSpecification,
- bool isExplicit)
+ ContextSpecificationElement contextSpecification)
{
return new UnitTestTask(contextSpecification,
new ContextSpecificationTask(_providerId,
context.AssemblyLocation,
context.GetTypeClrName().FullName,
- contextSpecification.FieldName,
- false));
- }
-
- public UnitTestTask CreateBehaviorTask(ContextElement context, BehaviorElement behavior, bool isExplicit)
- {
- return new UnitTestTask(behavior,
- new BehaviorTask(_providerId,
- context.AssemblyLocation,
- context.GetTypeClrName().FullName,
- behavior.FullyQualifiedTypeName,
- behavior.FieldName,
- false));
+ contextSpecification.FieldName));
}
public UnitTestTask CreateBehaviorSpecificationTask(ContextElement context,
- BehaviorSpecificationElement behaviorSpecification,
- bool isExplicit)
+ BehaviorSpecificationElement behaviorSpecification)
{
return new UnitTestTask(behaviorSpecification,
new BehaviorSpecificationTask(_providerId,
context.AssemblyLocation,
context.GetTypeClrName().FullName,
behaviorSpecification.Behavior.FieldName,
behaviorSpecification.FieldName,
- behaviorSpecification.GetTypeClrName().FullName,
- false));
+ behaviorSpecification.Behavior.FieldType));
}
}
}
@@ -114,6 +114,7 @@
<Compile Include="..\VersionInfo.cs">
<Link>Properties\VersionInfo.cs</Link>
</Compile>
+ <Compile Include="EnumerableExtensions.cs" />
<Compile Include="Explorers\AssemblyExplorer.cs" />
<Compile Include="Explorers\ElementHandlers\BehaviorElementHandler.cs" />
<Compile Include="Explorers\ElementHandlers\ContextElementHandler.cs" />
@@ -160,10 +161,9 @@
<Compile Include="Runners\RecursiveMSpecTaskRunner.cs" />
<Compile Include="Runners\VersionCompatibilityChecker.cs" />
<Compile Include="Tasks\BehaviorSpecificationTask.cs" />
- <Compile Include="Tasks\BehaviorTask.cs" />
<Compile Include="Tasks\ContextSpecificationTask.cs" />
<Compile Include="Tasks\ContextTask.cs" />
- <Compile Include="Tasks\RunAssemblyContextsTask.cs" />
+ <Compile Include="Tasks\RunAssemblyTask.cs" />
<Compile Include="Tasks\Task.cs" />
</ItemGroup>
<ItemGroup>
@@ -11,9 +11,14 @@ class NormalizedTypeName
static readonly Regex OpenBracketFollowedByDart = new Regex(@"\[.*->\s", RegexOptions.Compiled);
static readonly Regex DoubleOpenBrackets = new Regex(@"\[\[", RegexOptions.Compiled);
- public NormalizedTypeName(string fullyQualifiedTypeName)
+ public NormalizedTypeName(string typeName)
{
- _normalized = QualifiedNetNotationWithoutAssembly(fullyQualifiedTypeName);
+ _normalized = QualifiedNetNotationWithoutAssembly(typeName);
+ }
+
+ public NormalizedTypeName(IClrTypeName clrTypeName)
+ {
+ _normalized = QualifiedNetNotationWithoutAssembly(clrTypeName.FullName);
}
public NormalizedTypeName(ITypeOwner field)
@@ -26,7 +26,7 @@ public class BehaviorElement : FieldElement
IClrTypeName declaringTypeName,
string fieldName,
bool isIgnored,
- string fullyQualifiedTypeName)
+ string fieldType)
: base(
provider,
psiModuleManager,
@@ -37,16 +37,16 @@ public class BehaviorElement : FieldElement
fieldName,
isIgnored || context.Explicit)
{
- FullyQualifiedTypeName = fullyQualifiedTypeName;
- _id = CreateId(context, fullyQualifiedTypeName, fieldName);
+ FieldType = fieldType;
+ _id = CreateId(context, fieldType, fieldName);
}
public ContextElement Context
{
get { return (ContextElement) Parent; }
}
- public string FullyQualifiedTypeName { get; private set; }
+ public string FieldType { get; private set; }
public override string Kind
{
@@ -80,7 +80,7 @@ public override string GetTitlePrefix()
public override void WriteToXml(XmlElement parent)
{
base.WriteToXml(parent);
- parent.SetAttribute("typeFQN", FullyQualifiedTypeName);
+ parent.SetAttribute("fieldType", FieldType);
}
public static IUnitTestElement ReadFromXml(XmlElement parent,
@@ -108,7 +108,7 @@ CacheManager cacheManager
var typeName = parent.GetAttribute("typeName");
var methodName = parent.GetAttribute("methodName");
var isIgnored = bool.Parse(parent.GetAttribute("isIgnored"));
- var fullyQualifiedTypeName = parent.GetAttribute("typeFQN");
+ var fieldType = parent.GetAttribute("fieldType");
return BehaviorFactory.GetOrCreateBehavior(provider,
manager,
@@ -120,12 +120,12 @@ CacheManager cacheManager
new ClrTypeName(typeName),
methodName,
isIgnored,
- fullyQualifiedTypeName);
+ fieldType);
}
- public static string CreateId(ContextElement contextElement, string fullyQualifiedTypeName, string fieldName)
+ public static string CreateId(ContextElement contextElement, string fieldType, string fieldName)
{
- return String.Format("{0}.{1}.{2}", contextElement.Id, fullyQualifiedTypeName, fieldName);
+ return String.Format("{0}.{1}.{2}", contextElement.Id, fieldType, fieldName);
}
}
}
@@ -192,52 +192,33 @@ public IList<UnitTestTask> GetTaskSequence(IList<IUnitTestElement> explicitEleme
if (this is ContextSpecificationElement)
{
var contextSpecification = this as ContextSpecificationElement;
- ContextElement context = contextSpecification.Context;
+ var context = contextSpecification.Context;
return new List<UnitTestTask>
{
_taskFactory.CreateAssemblyLoadTask(context),
_taskFactory.CreateRunAssemblyTask(context),
- _taskFactory.CreateContextTask(context, explicitElements.Contains(context)),
- _taskFactory.CreateContextSpecificationTask(context,
- contextSpecification,
- explicitElements.Contains(contextSpecification))
- };
- }
-
- if (this is BehaviorElement)
- {
- var behavior = this as BehaviorElement;
- ContextElement context = behavior.Context;
-
- return new List<UnitTestTask>
- {
- _taskFactory.CreateAssemblyLoadTask(context),
- _taskFactory.CreateRunAssemblyTask(context),
- _taskFactory.CreateContextTask(context, explicitElements.Contains(context)),
- _taskFactory.CreateBehaviorTask(context, behavior, explicitElements.Contains(behavior))
+ _taskFactory.CreateContextTask(context),
+ _taskFactory.CreateContextSpecificationTask(context, contextSpecification)
};
}
if (this is BehaviorSpecificationElement)
{
var behaviorSpecification = this as BehaviorSpecificationElement;
- BehaviorElement behavior = behaviorSpecification.Behavior;
- ContextElement context = behavior.Context;
+ var behavior = behaviorSpecification.Behavior;
+ var context = behavior.Context;
return new List<UnitTestTask>
{
_taskFactory.CreateAssemblyLoadTask(context),
_taskFactory.CreateRunAssemblyTask(context),
- _taskFactory.CreateContextTask(context, explicitElements.Contains(context)),
- _taskFactory.CreateBehaviorTask(context, behavior, explicitElements.Contains(behavior)),
- _taskFactory.CreateBehaviorSpecificationTask(context,
- behaviorSpecification,
- explicitElements.Contains(behaviorSpecification))
+ _taskFactory.CreateContextTask(context),
+ _taskFactory.CreateBehaviorSpecificationTask(context, behaviorSpecification)
};
}
- if (this is ContextElement)
+ if (this is ContextElement || this is BehaviorElement)
{
return EmptyArray<UnitTestTask>.Instance;
}
@@ -45,7 +45,7 @@ public override bool Matches(object infoFromRunner)
return false;
}
- return ContainingType == specification.ContainingType &&
+ return ContainingType == new NormalizedTypeName(specification.ContainingType) &&
FieldName == specification.FieldName;
}
@@ -15,5 +15,10 @@ public override bool Matches(object infoFromRunner)
{
return false;
}
+
+ public override string ToString()
+ {
+ return "Silent";
+ }
}
}
Oops, something went wrong.

0 comments on commit a58dca9

Please sign in to comment.