Skip to content

Commit 68ac963

Browse files
committed
Add screen reader test fixture
And work around helper module's test filter.
1 parent bcd050d commit 68ac963

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

test/MockConsole.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,17 @@ public virtual void BlankRestOfLine()
300300
buffer[writePos + i].ForegroundColor = ForegroundColor;
301301
}
302302
}
303+
304+
public virtual void BlankRestOfBuffer()
305+
{
306+
var writePos = CursorTop * BufferWidth + CursorLeft;
307+
for (int i = 0; i < buffer.Length - writePos; i++)
308+
{
309+
buffer[writePos + i].UnicodeChar = ' ';
310+
buffer[writePos + i].BackgroundColor = BackgroundColor;
311+
buffer[writePos + i].ForegroundColor = ForegroundColor;
312+
}
313+
}
303314

304315
public virtual void Clear()
305316
{
@@ -334,6 +345,7 @@ private static void ToggleNegative(TestConsole c, bool b)
334345
c.BackgroundColor = (ConsoleColor)((int)c.BackgroundColor ^ 7);
335346
c._negative = b;
336347
}
348+
337349
protected static readonly Dictionary<string, Action<TestConsole>> EscapeSequenceActions = new()
338350
{
339351
{"7", c => ToggleNegative(c, true) },
@@ -376,7 +388,8 @@ private static void ToggleNegative(TestConsole c, bool b)
376388
c.ForegroundColor = DefaultForeground;
377389
c.BackgroundColor = DefaultBackground;
378390
}},
379-
{"2J", c => c.SetCursorPosition(0, 0) }
391+
{ "0J", c => c.BlankRestOfBuffer() },
392+
{ "2J", c => c.SetCursorPosition(0, 0) },
380393
};
381394
}
382395

@@ -520,6 +533,17 @@ public override void BlankRestOfLine()
520533
}
521534
}
522535

536+
public override void BlankRestOfBuffer()
537+
{
538+
var writePos = (_offset + CursorTop) * BufferWidth + CursorLeft;
539+
for (int i = 0; i < buffer.Length - writePos; i++)
540+
{
541+
buffer[writePos + i].UnicodeChar = ' ';
542+
buffer[writePos + i].BackgroundColor = BackgroundColor;
543+
buffer[writePos + i].ForegroundColor = ForegroundColor;
544+
}
545+
}
546+
523547
public override void Clear()
524548
{
525549
_offset = 0;

test/UnitTestReadLine.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ protected ReadLine(ConsoleFixture fixture, ITestOutputHelper output, string lang
130130
internal virtual bool KeyboardHasGreaterThan => true;
131131
internal virtual bool KeyboardHasCtrlRBracket => true;
132132
internal virtual bool KeyboardHasCtrlAt => true;
133+
internal virtual bool ScreenReaderModeEnabled => false;
133134

134135
static ReadLine()
135136
{
@@ -444,8 +445,13 @@ private void AssertScreenIs(int top, int lines, params object[] items)
444445
// that shouldn't be and aren't ever set by any code in PSReadLine, so we'll
445446
// ignore those bits and just check the stuff we do set.
446447
Assert.Equal(expectedBuffer[i].UnicodeChar, consoleBuffer[i].UnicodeChar);
447-
Assert.Equal(expectedBuffer[i].ForegroundColor, consoleBuffer[i].ForegroundColor);
448-
Assert.Equal(expectedBuffer[i].BackgroundColor, consoleBuffer[i].BackgroundColor);
448+
if (!ScreenReaderModeEnabled)
449+
{
450+
// Changing colors is not supported in screen reader mode,
451+
// and this is the simplest way to disable checking that in all the tests.
452+
Assert.Equal(expectedBuffer[i].ForegroundColor, consoleBuffer[i].ForegroundColor);
453+
Assert.Equal(expectedBuffer[i].BackgroundColor, consoleBuffer[i].BackgroundColor);
454+
}
449455
}
450456
}
451457

@@ -582,6 +588,7 @@ private void TestSetup(TestConsole console, KeyMode keyMode, params KeyHandler[]
582588
ContinuationPrompt = PSConsoleReadLineOptions.DefaultContinuationPrompt,
583589
DingDuration = 1, // Make tests virtually silent when they ding
584590
DingTone = 37, // Make tests virtually silent when they ding
591+
EnableScreenReaderMode = ScreenReaderModeEnabled,
585592
ExtraPromptLineCount = PSConsoleReadLineOptions.DefaultExtraPromptLineCount,
586593
HistoryNoDuplicates = PSConsoleReadLineOptions.DefaultHistoryNoDuplicates,
587594
HistorySaveStyle = HistorySaveStyle.SaveNothing,
@@ -668,4 +675,14 @@ public fr_FR_Windows(ConsoleFixture fixture, ITestOutputHelper output)
668675
internal override bool KeyboardHasCtrlRBracket => false;
669676
internal override bool KeyboardHasCtrlAt => false;
670677
}
678+
679+
public class ScreenReader : Test.ReadLine, IClassFixture<ConsoleFixture>
680+
{
681+
public ScreenReader(ConsoleFixture fixture, ITestOutputHelper output)
682+
: base(fixture, output, "en-US", "windows")
683+
{
684+
}
685+
686+
internal override bool ScreenReaderModeEnabled => true;
687+
}
671688
}

tools/helper.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ function Start-TestRun
210210

211211
function RunXunitTestsInNewProcess ([string] $Layout, [string] $OperatingSystem)
212212
{
213-
$filter = "FullyQualifiedName~Test.{0}_{1}" -f ($Layout -replace '-','_'), $OperatingSystem
213+
$filter = "(FullyQualifiedName~Test.{0}_{1})|(FullyQualifiedName~Test.ScreenReader)" -f ($Layout -replace '-','_'), $OperatingSystem
214214
$testResultFile = "xUnitTestResults.{0}.xml" -f $Layout
215215
$testResultFile = Join-Path $testResultFolder $testResultFile
216216

0 commit comments

Comments
 (0)