Skip to content

Commit 0fbff32

Browse files
Galadbradwilson
authored andcommitted
Fix issue #66 - Test discovery may fail if the test display name is longer than 447 characters.
1 parent 1212fd0 commit 0fbff32

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

xunit.runner.visualstudio.testadapter/Visitors/VsDiscoveryVisitor.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ namespace Xunit.Runner.VisualStudio.TestAdapter
1919
{
2020
public class VsDiscoveryVisitor : TestMessageVisitor<IDiscoveryCompleteMessage>, IVsDiscoveryVisitor
2121
{
22+
const string Ellipsis = "...";
23+
const int MaximumDisplayNameLength = 447;
24+
2225
static readonly Action<TestCase, string, string> addTraitThunk = GetAddTraitThunk();
2326
static readonly Uri uri = new Uri(Constants.ExecutorUri);
2427

@@ -83,7 +86,15 @@ static string Escape(string value)
8386
if (value == null)
8487
return string.Empty;
8588

86-
return value.Replace("\r", "\\r").Replace("\n", "\\n").Replace("\t", "\\t");
89+
return Truncate(value.Replace("\r", "\\r").Replace("\n", "\\n").Replace("\t", "\\t"));
90+
}
91+
92+
static string Truncate(string value)
93+
{
94+
if (value.Length <= MaximumDisplayNameLength)
95+
return value;
96+
97+
return value.Substring(0, MaximumDisplayNameLength - Ellipsis.Length) + Ellipsis;
8798
}
8899

89100
public int Finish()

0 commit comments

Comments
 (0)