Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 2c1b406

Browse files
Robert MatusewiczRobert Matusewicz
authored andcommitted
In NamedArgumentTests - wrap Console.SetOut in a helper function that
will override the console before test and reset it after test. Fixes #28667
1 parent 6ae0da1 commit 2c1b406

File tree

3 files changed

+418
-352
lines changed

3 files changed

+418
-352
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.IO;
3+
4+
namespace Microsoft.CSharp.RuntimeBinder.Tests
5+
{
6+
public static class Helpers
7+
{
8+
public static void OverrideConsoleAndRun(Action<StringWriter> command)
9+
{
10+
TextWriter savedOut = Console.Out;
11+
try
12+
{
13+
using (var stringWriter = new StringWriter())
14+
{
15+
Console.SetOut(stringWriter);
16+
command(stringWriter);
17+
}
18+
}
19+
finally
20+
{
21+
Console.SetOut(savedOut);
22+
}
23+
}
24+
}
25+
}

src/Microsoft.CSharp/tests/Microsoft.CSharp.Tests.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<Compile Include="BindingErrors.cs" />
1717
<Compile Include="EnumUnaryOperationTests.cs" />
1818
<Compile Include="ExplicitConversionTests.cs" />
19+
<Compile Include="Helpers.cs" />
1920
<Compile Include="ImplicitConversionTests.cs" />
2021
<Compile Include="CSharpArgumentInfoTests.cs" />
2122
<Compile Include="DefaultParameterTests.cs" />
@@ -36,5 +37,8 @@
3637
<ItemGroup Condition="'$(TargetGroup)' == 'netcoreapp'">
3738
<Compile Include="AccessTests.netcoreapp.cs" />
3839
</ItemGroup>
40+
<ItemGroup>
41+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
42+
</ItemGroup>
3943
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
40-
</Project>
44+
</Project>

0 commit comments

Comments
 (0)