From e3c7ae5f38875c76fbfb3d8659c252c96a07ffaf Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Sat, 18 Jul 2015 14:35:17 -0700 Subject: [PATCH] Fixes #616 Visual Studio runs out of memory Moves "escape" update outside of condition to ensure we always advance even when colour codes are invalid. Adds test for printing all characters. --- Common/Product/ReplWindow/Repl/OutputBuffer.cs | 3 +-- Common/Tests/Utilities.UI/UI/ReplWindowProxy.cs | 14 +++++++++++--- Common/Tests/Utilities/Mocks/MockReplWindow.cs | 3 +-- .../PythonTools/Repl/BasePythonReplEvaluator.cs | 4 ++-- .../ReplWindowPythonSmokeTests.cs | 16 ++++++++++++++++ 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/Common/Product/ReplWindow/Repl/OutputBuffer.cs b/Common/Product/ReplWindow/Repl/OutputBuffer.cs index 942b46bc19..d1943abd22 100644 --- a/Common/Product/ReplWindow/Repl/OutputBuffer.cs +++ b/Common/Product/ReplWindow/Repl/OutputBuffer.cs @@ -195,10 +195,9 @@ private void AppendEscapedText(string text, bool isError, int escape) { break; } } - - escape = text.IndexOf('\x1b', escape + 1); }// else not an escape sequence, process as text + escape = text.IndexOf('\x1b', escape + 1); } while (escape != -1); if (start != text.Length) { AppendText(text.Substring(start), kind, color); diff --git a/Common/Tests/Utilities.UI/UI/ReplWindowProxy.cs b/Common/Tests/Utilities.UI/UI/ReplWindowProxy.cs index 5d5a928c83..34ab31ea5b 100644 --- a/Common/Tests/Utilities.UI/UI/ReplWindowProxy.cs +++ b/Common/Tests/Utilities.UI/UI/ReplWindowProxy.cs @@ -333,11 +333,19 @@ private bool MatchTextInternal(IList expected, bool matchAtStart, bool m // Resplit lines to handle cases where linebreaks are embedded in // a single string. This helps ensure the comparison is correct and // the output is sensible. - expected = expected.SelectMany(l => l.Split('\n')).Select(l => l.TrimEnd('\r', '\n')).ToList(); - var lines = Window.TextView.TextBuffer.CurrentSnapshot.Lines; + expected = expected.SelectMany(l => l.Split('\n')).Select(l => l.TrimEnd('\r', '\n', ' ')).ToList(); + var snapshot = Window.TextView.TextBuffer.CurrentSnapshot; + var lines = snapshot.Lines; + // Cap the number of lines we'll ever look at to avoid breaking here + // when tests get stuck in infinite loops + if (matchAtStart && !matchAtEnd) { + lines = lines.Take(expected.Count + 1); + } else if (!matchAtStart && matchAtEnd) { + lines = lines.Skip(snapshot.LineCount - expected.Count - 2); + } var actual = lines .SelectMany(l => l.GetText().Split('\n')) - .Select(l => l.TrimEnd('\r', '\n')) + .Select(l => l.TrimEnd('\r', '\n', ' ')) .ToList(); bool isMatch = true; diff --git a/Common/Tests/Utilities/Mocks/MockReplWindow.cs b/Common/Tests/Utilities/Mocks/MockReplWindow.cs index 4f5f6f1550..5377c23efc 100644 --- a/Common/Tests/Utilities/Mocks/MockReplWindow.cs +++ b/Common/Tests/Utilities/Mocks/MockReplWindow.cs @@ -242,10 +242,9 @@ private void AppendEscapedText(string text) { break; } } - - escape = text.IndexOf('\x1b', escape + 1); }// else not an escape sequence, process as text + escape = text.IndexOf('\x1b', escape + 1); } while (escape != -1); if (start != text.Length - 1) { _output.Append(text.Substring(start)); diff --git a/Python/Product/PythonTools/PythonTools/Repl/BasePythonReplEvaluator.cs b/Python/Product/PythonTools/PythonTools/Repl/BasePythonReplEvaluator.cs index 222b930166..bedb400aa0 100644 --- a/Python/Product/PythonTools/PythonTools/Repl/BasePythonReplEvaluator.cs +++ b/Python/Product/PythonTools/PythonTools/Repl/BasePythonReplEvaluator.cs @@ -2035,9 +2035,9 @@ public static void AppendEscapedText(this IInteractiveWindow window, string text break; } } - - escape = text.IndexOf('\x1b', escape + 1); }// else not an escape sequence, process as text + + escape = text.IndexOf('\x1b', escape + 1); } if (start != text.Length) { diff --git a/Python/Tests/ReplWindowUITests/ReplWindowPythonSmokeTests.cs b/Python/Tests/ReplWindowUITests/ReplWindowPythonSmokeTests.cs index 952d29a627..6bf3d90f17 100644 --- a/Python/Tests/ReplWindowUITests/ReplWindowPythonSmokeTests.cs +++ b/Python/Tests/ReplWindowUITests/ReplWindowPythonSmokeTests.cs @@ -12,6 +12,8 @@ * * ***************************************************************************/ +using System; +using System.Linq; using System.Runtime.InteropServices; using System.Threading; using Microsoft.PythonTools; @@ -148,6 +150,20 @@ public virtual void QuitAndReset() { } } + [TestMethod, Priority(0)] + [HostType("VSTestHost")] + public virtual void PrintAllCharacters() { + using (var interactive = Prepare()) { + interactive.SubmitCode("print(\"" + + string.Join("", Enumerable.Range(0, 256).Select(i => string.Format("\\x{0:X2}", i))) + + "\\nDONE\")", + timeout: TimeSpan.FromSeconds(10.0) + ); + + interactive.WaitForTextEnd("DONE", ">"); + } + } + [TestMethod, Priority(0)] [HostType("VSTestHost")] public virtual void AttachReplTest() {