Skip to content

Commit 9c622d4

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 9c622d4

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

test/PowerShellEditorServices.Test.Host/LanguageServerTests.cs

Lines changed: 3 additions & 13 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;
@@ -541,18 +541,8 @@ await requestContext.SendResult(
541541
// Skip the initial script lines (4 script lines plus 2 blank lines)
542542
string[] scriptLines = await outputReader.ReadLines(6);
543543

544-
// In some cases an extra newline appears after the script lines.
545-
// I have no idea why this happens, but it normally seems to occur
546-
// on my local machine and not the CI server. For now, adjust for
547-
// it here.
548-
string outputLine = await outputReader.ReadLine();
549-
if (string.IsNullOrEmpty(outputLine))
550-
{
551-
outputLine = await outputReader.ReadLine();
552-
}
553-
554544
// Verify the first line
555-
Assert.Equal("Name: John", outputLine);
545+
Assert.Equal("Name: John", await outputReader.ReadLine());
556546

557547
// Verify the rest of the output
558548
string[] outputLines = await outputReader.ReadLines(4);

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)