Skip to content
This repository has been archived by the owner on Dec 12, 2017. It is now read-only.

Commit

Permalink
More robust execution of dynamic elements
Browse files Browse the repository at this point in the history
Only include valid method and theory elements as known children of a
class. Including invalid elements could confuse things - it's a known
child, but there's no task, so the dynamic element isn't executed.
  • Loading branch information
citizenmatt committed Nov 17, 2015
1 parent 36381e8 commit e0a453d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion resharper/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
[assembly : AssemblyDescription("xUnit.net unit test provider for " + ProductInfo.Product)]
[assembly : AssemblyCopyright("Copyright (C) Matt Ellis")]
[assembly : ComVisible(false)]
[assembly : AssemblyVersion("2.3.0.0")]
[assembly : AssemblyVersion("2.3.1.0")]
5 changes: 4 additions & 1 deletion resharper/nuget/xunitcontrib.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
<metadata>
<id>CitizenMatt.Xunit</id>
<title>xUnit.net Test Support for ReSharper 10</title>
<version>2.3.0</version>
<version>2.3.1</version>
<authors>Matt Ellis</authors>
<owners>Matt Ellis</owners>
<description>A unit test provider for xUnit.net. Discovers and runs xUnit.net 1.x and 2.x tests. Includes annotations to aid ReSharper inspections and Live Templates to speed up inserting test methods and asserts.</description>
<summary>A unit test provider for xUnit.net</summary>
<releaseNotes>
&#8226; Fixed issue with discovering theories at runtime

From previous releases:
&#8226; Support for ReSharper 10 (#82)
&#8226; Inherited tests not showing in results (#79)
&#8226; Theories can now be excluded by category (#89)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@ public override IEnumerable<IProjectFile> GetProjectFiles()
public override IList<UnitTestTask> GetTaskSequence(ICollection<IUnitTestElement> explicitElements, IUnitTestRun run)
{
var knownMethods = from c in Children.OfType<XunitTestMethodElement>()
where c.State.IsValid()
select c.MethodName;
var knownTheories = from c in Children.OfType<XunitTestMethodElement>()
where c.State.IsValid()
from gc in c.Children.OfType<XunitTestTheoryElement>()
where gc.State.IsValid()
select gc.ShortName;
var knownChildren = new HashSet<string>(knownMethods);
knownChildren.AddRange(knownTheories);
Expand Down
20 changes: 13 additions & 7 deletions resharper/src/runner/DiagnosticMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ namespace XunitContrib.Runner.ReSharper.RemoteRunner
public class DiagnosticMessages
{
private readonly DiagnosticsVisitor visitor;
private readonly IList<string> messages;

public DiagnosticMessages(bool enabled)
{
visitor = new DiagnosticsVisitor(enabled);
messages = new List<string>();
visitor = new DiagnosticsVisitor(enabled, messages);
}

public IMessageSink Visitor { get { return visitor; } }
public bool HasMessages { get { return visitor.Messages.Count > 0; } }
public bool HasMessages { get { return messages.Count > 0; } }

public string Messages
{
get { return string.Join(Environment.NewLine, visitor.Messages.ToArray()); }
get { return string.Join(Environment.NewLine, messages.ToArray()); }
}

public void Report(IRemoteTaskServer server)
Expand All @@ -34,24 +36,28 @@ public void Report(IRemoteTaskServer server)
private class DiagnosticsVisitor : TestMessageVisitor
{
private readonly bool enabled;
private readonly IList<string> messages;

public DiagnosticsVisitor(bool enabled)
public DiagnosticsVisitor(bool enabled, IList<string> messages)
{
this.enabled = enabled;
Messages = new List<string>();
this.messages = messages;
}

protected override bool Visit(IDiagnosticMessage diagnosticMessage)
{
if (enabled && !string.IsNullOrEmpty(diagnosticMessage.Message))
{
Logger.LogVerbose("xunit diagnostic: {0}", diagnosticMessage.Message);
Messages.Add(diagnosticMessage.Message);
messages.Add(diagnosticMessage.Message);
}
return base.Visit(diagnosticMessage);
}
}

public IList<string> Messages { get; private set; }
public void Add(string message)
{
messages.Add(message);
}
}
}
1 change: 1 addition & 0 deletions resharper/src/runner/Tasks/XunitTaskBase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Xml;
using JetBrains.ReSharper.TaskRunnerFramework;
using JetBrains.ReSharper.UnitTestFramework;

namespace XunitContrib.Runner.ReSharper.RemoteRunner.Tasks
{
Expand Down
9 changes: 5 additions & 4 deletions resharper/src/runner/TestRunner.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using JetBrains.ReSharper.TaskRunnerFramework;
using JetBrains.Util;
using Xunit;
using XunitContrib.Runner.ReSharper.RemoteRunner.Logging;
using XunitContrib.Runner.ReSharper.RemoteRunner.Tasks;
Expand Down Expand Up @@ -31,7 +32,9 @@ public void Run(XunitTestAssemblyTask assemblyTask)
var discoverer = new Discoverer(controller, RunContext, environment);
var testCases = discoverer.GetTestCases();

// TODO: Report something if no test cases?
if (testCases.Count == 0)
throw new InternalErrorException("Unexpected: Unable to find any matching test cases");

if (testCases.Count > 0)
{
RunContext.AddRange(testCases);
Expand Down Expand Up @@ -66,15 +69,13 @@ private void ReportException(XunitTestAssemblyTask assemblyTask, TestEnvironment
{
Logger.LogException(e);

var message = e.Message + Environment.NewLine + Environment.NewLine +
"(Note: xUnit.net ReSharper runner requires projects are built with xUnit.net 2.0.0 RTM or later)";
var description = "Exception: " + e;
if (environment.DiagnosticMessages != null && environment.DiagnosticMessages.HasMessages)
{
description = string.Format("{0}{1}{1}Diagnostic Messages:{1}{2}", description,
Environment.NewLine, environment.DiagnosticMessages.Messages);
}
server.ShowNotification("Unable to run xUnit.net tests - " + message, description);
server.ShowNotification("Unable to run xUnit.net tests - " + e.Message, description);

// This doesn't help - assemblyTask doesn't map to anything in the tree...
server.TaskException(assemblyTask, new[] {new TaskException(e)});
Expand Down

0 comments on commit e0a453d

Please sign in to comment.