Skip to content

Commit b012db3

Browse files
committed
Fix #157: Tests using OutputReader sometimes hang
This fix handles an edge case when buffered output that ends with a newline is treated incorrectly causing an extra empty line to be returend by the OutputReader.
1 parent e094024 commit b012db3

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

test/PowerShellEditorServices.Test.Host/LanguageServerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,8 @@ await requestContext.SendResult(
490490
ChosenItem = "a"
491491
});
492492

493-
// Skip the initial script lines (6 script lines plus 3 blank lines)
494-
await outputReader.ReadLines(9);
493+
// Skip the initial script lines (6 script lines plus 2 blank lines)
494+
string[] outputLines = await outputReader.ReadLines(8);
495495

496496
// Wait for the selection to appear as output
497497
await evaluateTask;

test/PowerShellEditorServices.Test.Host/OutputReader.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ public async Task<string> ReadLine(string expectedOutputCategory = "stdout")
8989
outputLines[i],
9090

9191
// The line has a newline if it's not the last segment or
92-
// if the current output string ends with a newline
92+
// if the last segment is not an empty string and the
93+
// complete output string ends with a newline
9394
i < outputLines.Length - 1 ||
94-
nextOutputEvent.Output.EndsWith("\n")));
95+
(outputLines[outputLines.Length - 1].Length > 0 &&
96+
nextOutputEvent.Output.EndsWith("\n"))));
9597
}
9698
}
9799

0 commit comments

Comments
 (0)