Skip to content

Commit

Permalink
Fix issue #66 - Test discovery may fail if the test display name is l…
Browse files Browse the repository at this point in the history
…onger than 447 characters.
  • Loading branch information
Galad authored and bradwilson committed Jul 4, 2015
1 parent 1212fd0 commit 0fbff32
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ namespace Xunit.Runner.VisualStudio.TestAdapter
{
public class VsDiscoveryVisitor : TestMessageVisitor<IDiscoveryCompleteMessage>, IVsDiscoveryVisitor
{
const string Ellipsis = "...";
const int MaximumDisplayNameLength = 447;

static readonly Action<TestCase, string, string> addTraitThunk = GetAddTraitThunk();
static readonly Uri uri = new Uri(Constants.ExecutorUri);

Expand Down Expand Up @@ -83,7 +86,15 @@ static string Escape(string value)
if (value == null)
return string.Empty;

return value.Replace("\r", "\\r").Replace("\n", "\\n").Replace("\t", "\\t");
return Truncate(value.Replace("\r", "\\r").Replace("\n", "\\n").Replace("\t", "\\t"));
}

static string Truncate(string value)
{
if (value.Length <= MaximumDisplayNameLength)
return value;

return value.Substring(0, MaximumDisplayNameLength - Ellipsis.Length) + Ellipsis;
}

public int Finish()
Expand Down

0 comments on commit 0fbff32

Please sign in to comment.