Skip to content
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ee85981
Integrating interactive logger
nohwnd Jul 18, 2024
c9513d5
Format output
nohwnd Jul 19, 2024
a6d9ce6
per assembly summary
nohwnd Jul 19, 2024
ef0f958
Merge branch 'main' of https://github.com/microsoft/testfx into inter…
nohwnd Jul 22, 2024
b31df8c
Fix warnings
nohwnd Jul 22, 2024
345325b
Push fixes
nohwnd Jul 22, 2024
7c89f56
fixes
nohwnd Jul 22, 2024
914c104
refactor
nohwnd Jul 23, 2024
19e8d89
Fixes
nohwnd Jul 23, 2024
181a987
Review fixes
nohwnd Jul 23, 2024
4ef03f1
Fix framework name shortening
nohwnd Jul 23, 2024
80a4077
Merge branch 'main' into interactive-logger
nohwnd Jul 23, 2024
251f524
Remove unused class
nohwnd Jul 23, 2024
bed2dba
Add help, and clean up more code
nohwnd Jul 23, 2024
5903852
Update src/Platform/Microsoft.Testing.Platform/UI/LoggerOutcome.cs
nohwnd Jul 23, 2024
1771422
Merge branch 'main' into interactive-logger
nohwnd Jul 23, 2024
54b4c1b
bom
nohwnd Jul 23, 2024
f4053ef
Move code and add more extensions
nohwnd Jul 23, 2024
a6c06ef
Reformat
nohwnd Jul 23, 2024
df4d5de
update xlf
nohwnd Jul 23, 2024
c09775c
Apply suggestions from code review
nohwnd Jul 24, 2024
d4c8118
Use background thread
nohwnd Jul 24, 2024
219cad3
Merge branch 'interactive-logger' of https://github.com/microsoft/tes…
nohwnd Jul 24, 2024
1ae8c1e
Write warning and error with newline
nohwnd Jul 24, 2024
9a14f23
Don't write progress in host controller
nohwnd Jul 24, 2024
0036179
Merge branch 'main' into interactive-logger
nohwnd Jul 24, 2024
ffd0969
Fix newline
nohwnd Jul 24, 2024
4697e19
Fixes from pr review
nohwnd Aug 6, 2024
0a5c49e
Merge branch 'main' into interactive-logger
nohwnd Aug 6, 2024
89ad397
Tests fixed
nohwnd Aug 6, 2024
940d3f3
Tests fixed
nohwnd Aug 6, 2024
0fe3732
Remove filter
nohwnd Aug 7, 2024
b3dae94
Merge branch 'main' into interactive-logger
nohwnd Aug 7, 2024
e53f163
Fixed tests
nohwnd Aug 7, 2024
c0e1a33
Fix is test controller
nohwnd Aug 7, 2024
12c30c2
Update test/Utilities/Microsoft.Testing.TestInfrastructure/CommandLin…
nohwnd Aug 8, 2024
c570627
Update test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.In…
nohwnd Aug 8, 2024
4e443bf
Fixes before rename
nohwnd Aug 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ internal interface IConsole
{
event ConsoleCancelEventHandler? CancelKeyPress;

public int BufferHeight { get; }

public int BufferWidth { get; }

public bool IsOutputRedirected { get; }

void SetForegroundColor(ConsoleColor color);

void SetBackgroundColor(ConsoleColor color);
Expand All @@ -36,5 +42,7 @@ internal interface IConsole

void Write(string? value);

void Write(char value);

void Clear();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ internal sealed class SystemConsole : IConsole
{
private const int WriteBufferSize = 256;
private static readonly StreamWriter CaptureConsoleOutWriter;

/// <summary>
/// Gets the height of the buffer area.
/// </summary>
public int BufferHeight => Console.BufferHeight;

/// <summary>
/// Gets the width of the buffer area.
/// </summary>
public int BufferWidth => Console.BufferWidth;

/// <summary>
/// Gets a value indicating whether output has been redirected from the standard output stream.
/// </summary>
public bool IsOutputRedirected => Console.IsOutputRedirected;

private bool _suppressOutput;

static SystemConsole()
Expand Down Expand Up @@ -134,6 +150,14 @@ public void Write(string? value)
}
}

public void Write(char value)
{
if (!_suppressOutput)
{
CaptureConsoleOutWriter.Write(value);
}
}

public void SetForegroundColor(ConsoleColor color)
{
#if NET8_0_OR_GREATER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ await LogTestHostCreatedAsync(
TestHostControllerConfiguration testHostControllers = await ((TestHostControllersManager)TestHostControllers).BuildAsync(testHostControllersServiceProvider);
if (testHostControllers.RequireProcessRestart)
{
testHostControllerInfo.CurrentProcessIsTestHostController = true;
TestHostControllersTestHost testHostControllersTestHost = new(testHostControllers, testHostControllersServiceProvider, systemEnvironment, loggerFactory, systemClock, dotnetTestPipeClient);

await LogTestHostCreatedAsync(
Expand All @@ -364,6 +365,8 @@ await LogTestHostCreatedAsync(
ApplicationStateGuard.Ensure(currentWorkingDirectory is not null);
configuration.SetTestHostWorkingDirectory(currentWorkingDirectory);

testHostControllerInfo.CurrentProcessIsTestHostController = false;

// If we're under test controllers and currently we're inside the started test host we connect to the out of process
// test controller manager.
NamedPipeClient? testControllerConnection = await ConnectToTestHostProcessMonitorIfAvailableAsync(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.Testing.Platform.OutputDevice.Console;

/// <summary>
/// A collection of standard ANSI/VT100 control codes.
/// </summary>
internal static class AnsiCodes
{
/// <summary>
/// Escape character.
/// </summary>
public const string Esc = "\x1b";

/// <summary>
/// The control sequence introducer.
/// </summary>
public const string CSI = "\x1b[";

/// <summary>
/// Select graphic rendition.
/// </summary>
/// <remarks>
/// Print <see cref="CSI"/>color-code<see cref="SetColor"/> to change text color.
/// </remarks>
public const string SetColor = ";1m";

/// <summary>
/// Select graphic rendition - set bold mode.
/// </summary>
/// <remarks>
/// Print <see cref="CSI"/><see cref="SetBold"/> to change text to bold.
/// </remarks>
public const string SetBold = "1m";

/// <summary>
/// A shortcut to reset color back to normal.
/// </summary>
public const string SetDefaultColor = CSI + "m";

/// <summary>
/// Non-xterm extension to render a hyperlink.
/// </summary>
/// <remarks>
/// Print <see cref="LinkPrefix"/>url<see cref="LinkInfix"/>text<see cref="LinkSuffix"/> to render a hyperlink.
/// </remarks>
public const string LinkPrefix = "\x1b]8;;";

/// <summary>
/// <see cref="LinkPrefix"/>.
/// </summary>
public const string LinkInfix = "\x1b\\";

/// <summary>
/// <see cref="LinkPrefix"/>.
/// </summary>
public const string LinkSuffix = "\x1b]8;;\x1b\\";

/// <summary>
/// Moves up the specified number of lines and puts cursor at the beginning of the line.
/// </summary>
/// <remarks>
/// Print <see cref="CSI"/>N<see cref="MoveUpToLineStart"/> to move N lines up.
/// </remarks>
public const string MoveUpToLineStart = "F";

/// <summary>
/// Moves forward (to the right) the specified number of characters.
/// </summary>
/// <remarks>
/// Print <see cref="CSI"/>N<see cref="MoveForward"/> to move N characters forward.
/// </remarks>
public const string MoveForward = "C";

/// <summary>
/// Moves backward (to the left) the specified number of characters.
/// </summary>
/// <remarks>
/// Print <see cref="CSI"/>N<see cref="MoveBackward"/> to move N characters backward.
/// </remarks>
public const string MoveBackward = "D";

/// <summary>
/// Clears everything from cursor to end of screen.
/// </summary>
/// <remarks>
/// Print <see cref="CSI"/><see cref="EraseInDisplay"/> to clear.
/// </remarks>
public const string EraseInDisplay = "J";

/// <summary>
/// Clears everything from cursor to the end of the current line.
/// </summary>
/// <remarks>
/// Print <see cref="CSI"/><see cref="EraseInLine"/> to clear.
/// </remarks>
public const string EraseInLine = "K";

/// <summary>
/// Hides the cursor.
/// </summary>
public const string HideCursor = "\x1b[?25l";

/// <summary>
/// Shows/restores the cursor.
/// </summary>
public const string ShowCursor = "\x1b[?25h";

/// <summary>
/// Set progress state to a busy spinner. <br/>
/// Note: this code works only on ConEmu terminals, and conflicts with push a notification code on iTerm2.
/// </summary>
/// <remarks>
/// <see href="https://conemu.github.io/en/AnsiEscapeCodes.html#ConEmu_specific_OSC">ConEmu specific OSC codes.</see><br/>
/// <see href="https://iterm2.com/documentation-escape-codes.html">iTerm2 proprietary escape codes.</see>
/// </remarks>
public const string SetBusySpinner = "\x1b]9;4;3;\x1b\\";

/// <summary>
/// Remove progress state, restoring taskbar status to normal. <br/>
/// Note: this code works only on ConEmu terminals, and conflicts with push a notification code on iTerm2.
/// </summary>
/// <remarks>
/// <see href="https://conemu.github.io/en/AnsiEscapeCodes.html#ConEmu_specific_OSC">ConEmu specific OSC codes.</see><br/>
/// <see href="https://iterm2.com/documentation-escape-codes.html">iTerm2 proprietary escape codes.</see>
/// </remarks>
public const string RemoveBusySpinner = "\x1b]9;4;0;\x1b\\";

public static string Colorize(string? s, TerminalColor color)
=> RoslynString.IsNullOrWhiteSpace(s) ? s ?? string.Empty : $"{CSI}{(int)color}{SetColor}{s}{SetDefaultColor}";

public static string MakeBold(string? s)
=> RoslynString.IsNullOrWhiteSpace(s) ? s ?? string.Empty : $"{CSI}{SetBold}{s}{SetDefaultColor}";

public static string MoveCursorBackward(int count) => $"{CSI}{count}{MoveBackward}";

/// <summary>
/// Moves cursor to the specified column, or the rightmost column if <paramref name="column"/> is greater than the width of the terminal.
/// </summary>
/// <param name="column">Column index.</param>
/// <returns>Control codes to set the desired position.</returns>
public static string SetCursorHorizontal(int column) => $"{CSI}{column}G";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

// Portions of the code in this file were ported from the spectre.console by Patrik Svensson, Phil Scott, Nils Andresen
// https://github.com/spectreconsole/spectre.console/blob/main/src/Spectre.Console/Internal/Backends/Ansi/AnsiDetector.cs
// and from the supports-ansi project by Qingrong Ke
// https://github.com/keqingrong/supports-ansi/blob/master/index.js
using System.Text.RegularExpressions;

namespace Microsoft.Testing.Platform.OutputDevice.Console;

/// <summary>
/// Works together with the <see cref="NativeMethods"/> to figure out if the current console is capable of using ANSI output codes.
/// </summary>
internal class AnsiDetector
{
private static readonly Regex[] TerminalsRegexes =
{
new("^xterm"), // xterm, PuTTY, Mintty
new("^rxvt"), // RXVT
new("^(?!eterm-color).*eterm.*"), // Accepts eterm, but not eterm-color, which does not support moving the cursor, see #9950.
new("^screen"), // GNU screen, tmux
new("tmux"), // tmux
new("^vt100"), // DEC VT series
new("^vt102"), // DEC VT series
new("^vt220"), // DEC VT series
new("^vt320"), // DEC VT series
new("ansi"), // ANSI
new("scoansi"), // SCO ANSI
new("cygwin"), // Cygwin, MinGW
new("linux"), // Linux console
new("konsole"), // Konsole
new("bvterm"), // Bitvise SSH Client
new("^st-256color"), // Suckless Simple Terminal, st
new("alacritty"), // Alacritty
};

public static bool IsAnsiSupported(string? termType)
=> !RoslynString.IsNullOrEmpty(termType) && TerminalsRegexes.Any(regex => regex.IsMatch(termType));
}
Loading