From 5349e706863892c919ff84bebea7822cfdd9ad94 Mon Sep 17 00:00:00 2001 From: Lucas Loegel Date: Thu, 2 Jul 2015 14:46:13 +0200 Subject: [PATCH] Fix issue #66 - Test discovery may fail if the test display name is longer than 447 characters. --- .../Visitors/VsDiscoveryVisitor.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/xunit.runner.visualstudio.testadapter/Visitors/VsDiscoveryVisitor.cs b/xunit.runner.visualstudio.testadapter/Visitors/VsDiscoveryVisitor.cs index 6bd7cd3a..246846cc 100644 --- a/xunit.runner.visualstudio.testadapter/Visitors/VsDiscoveryVisitor.cs +++ b/xunit.runner.visualstudio.testadapter/Visitors/VsDiscoveryVisitor.cs @@ -23,6 +23,8 @@ public class VsDiscoveryVisitor : TestMessageVisitor, { static readonly Action addTraitThunk = GetAddTraitThunk(); static readonly Uri uri = new Uri(Constants.ExecutorUri); + const string Ellipsis = "..."; + const int MaximumDisplayNameLength = 447; readonly Func cancelThunk; readonly ITestFrameworkDiscoverer discoverer; @@ -85,9 +87,16 @@ 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() { Finished.WaitOne();