Skip to content

Commit 8127357

Browse files
authored
[DotnetTrace][Tests] Add functional tests validating Collect output (#5581)
Supplements #5570 per #5570 (review)
1 parent b64e35d commit 8127357

File tree

16 files changed

+457
-84
lines changed

16 files changed

+457
-84
lines changed

src/Tools/Common/Commands/Utils.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Diagnostics;
66
using System.Collections.Generic;
77
using Microsoft.Diagnostics.NETCore.Client;
8+
using Microsoft.Diagnostics.Tools.Common;
89

910
namespace Microsoft.Internal.Common.Utils
1011
{
@@ -147,7 +148,12 @@ internal sealed class LineRewriter
147148
{
148149
public int LineToClear { get; set; }
149150

150-
public LineRewriter() { }
151+
private IConsole Console { get; }
152+
153+
public LineRewriter(IConsole console)
154+
{
155+
Console = console;
156+
}
151157

152158
// ANSI escape codes:
153159
// [2K => clear current line

src/Tools/dotnet-counters/Exporters/DefaultConsole.cs renamed to src/Tools/Common/DefaultConsole.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
5+
using System.IO;
6+
using Microsoft.Diagnostics.Tools.Common;
57

6-
namespace Microsoft.Diagnostics.Tools.Counters.Exporters
8+
namespace Microsoft.Diagnostics.Tools.Common
79
{
810
/// <summary>
911
/// The default implementation of IConsole maps everything to System.Console. In the future
@@ -27,10 +29,24 @@ public DefaultConsole(bool useAnsi)
2729
public bool CursorVisible { get => Console.CursorVisible; set { Console.CursorVisible = value; } }
2830
#pragma warning restore CA1416
2931

32+
public int CursorLeft => Console.CursorLeft;
33+
3034
public int CursorTop => Console.CursorTop;
3135

3236
public int BufferWidth => Console.BufferWidth;
3337

38+
public int BufferHeight => Console.BufferHeight;
39+
40+
public bool IsOutputRedirected => Console.IsOutputRedirected;
41+
42+
public bool IsInputRedirected => Console.IsInputRedirected;
43+
44+
public bool KeyAvailable => Console.KeyAvailable;
45+
46+
public TextWriter Out => Console.Out;
47+
48+
public TextWriter Error => Console.Error;
49+
3450
public void Clear()
3551
{
3652
if (_useAnsi)
@@ -57,5 +73,7 @@ public void SetCursorPosition(int col, int row)
5773
public void Write(string text) => Console.Write(text);
5874
public void WriteLine(string text) => Console.WriteLine(text);
5975
public void WriteLine() => Console.WriteLine();
76+
public ConsoleKeyInfo ReadKey() => Console.ReadKey();
77+
public ConsoleKeyInfo ReadKey(bool intercept) => Console.ReadKey(intercept);
6078
}
6179
}

src/Tools/Common/IConsole.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.IO;
6+
7+
namespace Microsoft.Diagnostics.Tools.Common
8+
{
9+
/// <summary>
10+
/// Abstraction over console operations so tools can render to custom consoles in tests.
11+
/// Mirrors the APIs dotnet-counters and dotnet-trace need for their renderers.
12+
/// </summary>
13+
internal interface IConsole
14+
{
15+
int WindowHeight { get; }
16+
int WindowWidth { get; }
17+
bool CursorVisible { get; set; }
18+
int CursorLeft { get; }
19+
int CursorTop { get; }
20+
int BufferWidth { get; }
21+
int BufferHeight { get; }
22+
bool IsOutputRedirected { get; }
23+
bool IsInputRedirected { get; }
24+
bool KeyAvailable { get; }
25+
TextWriter Out { get; }
26+
TextWriter Error { get; }
27+
28+
void Clear();
29+
void SetCursorPosition(int col, int row);
30+
void Write(string text);
31+
void WriteLine();
32+
void WriteLine(string text);
33+
ConsoleKeyInfo ReadKey();
34+
ConsoleKeyInfo ReadKey(bool intercept);
35+
}
36+
}

src/Tools/dotnet-counters/CounterMonitor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using Microsoft.Diagnostics.Monitoring;
1515
using Microsoft.Diagnostics.Monitoring.EventPipe;
1616
using Microsoft.Diagnostics.NETCore.Client;
17+
using Microsoft.Diagnostics.Tools.Common;
1718
using Microsoft.Diagnostics.Tools.Counters.Exporters;
1819
using Microsoft.Internal.Common.Utils;
1920

src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Globalization;
77
using System.Linq;
88
using Microsoft.Diagnostics.Monitoring.EventPipe;
9+
using Microsoft.Diagnostics.Tools.Common;
910

1011
namespace Microsoft.Diagnostics.Tools.Counters.Exporters
1112
{

src/Tools/dotnet-counters/Exporters/IConsole.cs

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/Tools/dotnet-counters/dotnet-counters.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
<Compile Include="..\Common\WindowsProcessExtension\WindowsProcessExtension.cs" Link="WindowsProcessExtension.cs" />
2323
<Compile Include="..\Common\CommandLineErrorException.cs" Link="CommandLineErrorException.cs" />
2424
<Compile Include="..\Common\DsRouterProcessLauncher.cs" Link="DsRouterProcessLauncher.cs" />
25-
</ItemGroup>
25+
<Compile Include="..\Common\IConsole.cs" Link="IConsole.cs" />
26+
<Compile Include="..\Common\DefaultConsole.cs" Link="DefaultConsole.cs" />
27+
</ItemGroup>
2628

2729
<ItemGroup>
2830
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\Microsoft.Diagnostics.NETCore.Client\Microsoft.Diagnostics.NETCore.Client.csproj" />

src/Tools/dotnet-dump/dotnet-dump.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
<Compile Include="$(MSBuildThisFileDirectory)..\Common\Commands\Utils.cs" Link="Utils.cs" />
2323
<Compile Include="$(MSBuildThisFileDirectory)..\Common\ProcessNativeMethods\ProcessNativeMethods.cs" Link="ProcessNativeMethods.cs" />
2424
<Compile Include="$(MSBuildThisFileDirectory)..\Common\WindowsProcessExtension\WindowsProcessExtension.cs" Link="WindowsProcessExtension.cs" />
25-
<Compile Include="..\Common\DsRouterProcessLauncher.cs" Link="DsRouterProcessLauncher.cs" />
25+
<Compile Include="$(MSBuildThisFileDirectory)..\Common\DsRouterProcessLauncher.cs" Link="DsRouterProcessLauncher.cs" />
26+
<Compile Include="$(MSBuildThisFileDirectory)..\Common\IConsole.cs" Link="IConsole.cs" />
2627
</ItemGroup>
2728

2829
<ItemGroup>

src/Tools/dotnet-gcdump/dotnet-gcdump.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<Compile Include="..\Common\ProcessNativeMethods\ProcessNativeMethods.cs" Link="ProcessNativeMethods.cs" />
2828
<Compile Include="..\Common\WindowsProcessExtension\WindowsProcessExtension.cs" Link="WindowsProcessExtension.cs" />
2929
<Compile Include="..\Common\DsRouterProcessLauncher.cs" Link="DsRouterProcessLauncher.cs" />
30+
<Compile Include="..\Common\IConsole.cs" Link="IConsole.cs" />
3031
</ItemGroup>
3132

3233
</Project>

src/Tools/dotnet-stack/dotnet-stack.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<Compile Include="..\Common\ProcessNativeMethods\ProcessNativeMethods.cs" Link="ProcessNativeMethods.cs" />
2727
<Compile Include="..\Common\WindowsProcessExtension\WindowsProcessExtension.cs" Link="WindowsProcessExtension.cs" />
2828
<Compile Include="..\Common\DsRouterProcessLauncher.cs" Link="DsRouterProcessLauncher.cs" />
29+
<Compile Include="..\Common\IConsole.cs" Link="IConsole.cs" />
2930
</ItemGroup>
3031

3132
<ItemGroup>

0 commit comments

Comments
 (0)