Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
@@ -1,11 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.CodeAnalysis;

namespace Microsoft.Testing.Platform.OutputDevice.Terminal;

/// <summary>
/// A collection of standard ANSI/VT100 control codes.
/// </summary>
[Embedded]
internal static class AnsiCodes
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
// 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 Microsoft.CodeAnalysis;

namespace Microsoft.Testing.Platform.OutputDevice.Terminal;

/// <summary>
/// Works together with the <see cref="NativeMethods"/> to figure out if the current console is capable of using ANSI output codes.
/// </summary>
[Embedded]
internal static class AnsiDetector
{
public static bool IsAnsiSupported(string? termType)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.CodeAnalysis;
using Microsoft.Testing.Platform.Helpers;
using Microsoft.Testing.Platform.Resources;

namespace Microsoft.Testing.Platform.OutputDevice.Terminal;

/// <summary>
/// Terminal writer that is used when writing ANSI is allowed. It is capable of batching as many updates as possible and writing them at the end,
/// because the terminal is responsible for rendering the colors and control codes.
/// </summary>
[Embedded]
internal sealed class AnsiTerminal : ITerminal
{
/// <summary>
Expand Down Expand Up @@ -150,7 +151,7 @@ public void StartUpdate()
{
if (_isBatching)
{
throw new InvalidOperationException(PlatformResources.ConsoleIsAlreadyInBatchingMode);
throw new InvalidOperationException(TerminalResources.ConsoleIsAlreadyInBatchingMode);
}

_stringBuilder.Clear();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.CodeAnalysis;

namespace Microsoft.Testing.Platform.OutputDevice.Terminal;

/// <summary>
/// Captures <see cref="TestProgressState"/> that was rendered to screen, so we can only partially update the screen on next update.
/// </summary>
[Embedded]
internal sealed class AnsiTerminalTestProgressFrame
{
private const int MaxColumn = 250;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.CodeAnalysis;

namespace Microsoft.Testing.Platform.OutputDevice.Terminal;

/// <summary>
Expand All @@ -9,6 +11,7 @@ namespace Microsoft.Testing.Platform.OutputDevice.Terminal;
/// or <see cref="AnsiMode.ForceAnsi"/>).
/// </summary>
[UnsupportedOSPlatform("browser")]
[Embedded]
internal sealed class CursorProgressRenderer : IProgressRenderer
{
// We only show seconds on the screen, but we want the in-place progress to look responsive, so we
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.CodeAnalysis;

namespace Microsoft.Testing.Platform.OutputDevice.Terminal;

[Embedded]
internal sealed class ExceptionFlattener
{
internal static FlatException[] Flatten(string? errorMessage, Exception? exception)
Expand Down Expand Up @@ -46,4 +49,5 @@ internal static FlatException[] Flatten(string? errorMessage, Exception? excepti
}
}

[Embedded]
internal sealed record FlatException(string? ErrorMessage, string? ErrorType, string? StackTrace);
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.CodeAnalysis;

namespace Microsoft.Testing.Platform.OutputDevice.Terminal;

[Embedded]
internal static class FileUtilities
{
internal static readonly StringComparison PathComparison = GetIsFileSystemCaseSensitive() ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.CodeAnalysis;

namespace Microsoft.Testing.Platform.OutputDevice.Terminal;

[Embedded]
internal static class HumanReadableDurationFormatter
{
public static void Append(ITerminal terminal, TimeSpan duration, bool wrapInParentheses = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.CodeAnalysis;

namespace Microsoft.Testing.Platform.OutputDevice.Terminal;

/// <summary>
Expand All @@ -19,6 +21,7 @@ namespace Microsoft.Testing.Platform.OutputDevice.Terminal;
/// except <see cref="OnTestCompleted"/> which may be called from the message pump and MUST be thread-safe.
/// </remarks>
[UnsupportedOSPlatform("browser")]
[Embedded]
internal interface IProgressRenderer
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.CodeAnalysis;

namespace Microsoft.Testing.Platform.OutputDevice.Terminal;

/// <summary>
/// An ANSI or non-ANSI terminal that is capable of rendering the messages from <see cref="TestProgressStateAwareTerminal"/>.
/// </summary>
[Embedded]
internal interface ITerminal
{
int Width { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.CodeAnalysis;

namespace Microsoft.Testing.Platform.OutputDevice.Terminal;

[Embedded]
internal static class NativeMethods
{
internal const uint FILE_TYPE_CHAR = 0x0002;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.CodeAnalysis;
using Microsoft.Testing.Platform.Helpers;

namespace Microsoft.Testing.Platform.OutputDevice.Terminal;
Expand All @@ -9,6 +10,7 @@ namespace Microsoft.Testing.Platform.OutputDevice.Terminal;
/// Non-ANSI terminal that writes text using the standard Console.Foreground color capabilities to stay compatible with
/// standard Windows command line, and other command lines that are not capable of ANSI, or when output is redirected.
/// </summary>
[Embedded]
internal sealed class NonAnsiTerminal : SimpleTerminal
{
private readonly ConsoleColor _defaultForegroundColor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.CodeAnalysis;
using Microsoft.Testing.Platform.Helpers;
using Microsoft.Testing.Platform.Resources;

namespace Microsoft.Testing.Platform.OutputDevice.Terminal;

Expand All @@ -17,6 +17,7 @@ namespace Microsoft.Testing.Platform.OutputDevice.Terminal;
/// A healthy fast suite emits zero heartbeat lines.
/// </summary>
[UnsupportedOSPlatform("browser")]
[Embedded]
internal sealed class SilenceDrivenHeartbeatRenderer : IProgressRenderer
{
private readonly TimeSpan _silenceThreshold;
Expand Down Expand Up @@ -111,10 +112,10 @@ private void EmitSilenceHeartbeat(ITerminal terminal, TestProgressState?[] progr
}
}

string line = string.Format(CultureInfo.CurrentCulture, PlatformResources.TerminalProgressHeartbeat, completed, failed);
string line = string.Format(CultureInfo.CurrentCulture, TerminalResources.TerminalProgressHeartbeat, completed, failed);
if (activeTest is not null)
{
line += string.Format(CultureInfo.CurrentCulture, PlatformResources.TerminalProgressHeartbeatActiveSuffix, activeTest);
line += string.Format(CultureInfo.CurrentCulture, TerminalResources.TerminalProgressHeartbeatActiveSuffix, activeTest);
}

terminal.AppendLine(line);
Expand Down Expand Up @@ -158,7 +159,7 @@ private void EmitSlowTests(ITerminal terminal, TestProgressState?[] progressItem
// Report the test's actual elapsed time rather than the scheduled threshold so a delayed
// tick (GC pause, debugger break, CPU starvation) does not under-report the runtime.
string duration = HumanReadableDurationFormatter.Render(TimeSpan.FromTicks(elapsed), wrapInParentheses: false);
terminal.AppendLine(string.Format(CultureInfo.CurrentCulture, PlatformResources.TerminalProgressSlowTest, duration, BuildSlowTestDescription(item, detail)));
terminal.AppendLine(string.Format(CultureInfo.CurrentCulture, TerminalResources.TerminalProgressSlowTest, duration, BuildSlowTestDescription(item, detail)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.CodeAnalysis;
using Microsoft.Testing.Platform.Helpers;

namespace Microsoft.Testing.Platform.OutputDevice.Terminal;
Expand All @@ -9,6 +10,7 @@ namespace Microsoft.Testing.Platform.OutputDevice.Terminal;
/// Simple terminal that uses 4-bit ANSI for colors but does not move cursor and does not do other fancy stuff to stay compatible with CI systems.
/// The colors are set on start of every line to properly color multiline strings in CI log viewers that reset color state at each newline (e.g. Azure DevOps).
/// </summary>
[Embedded]
internal sealed class SimpleAnsiTerminal : SimpleTerminal
{
private string? _foregroundColor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.CodeAnalysis;
using Microsoft.Testing.Platform.Helpers;
using Microsoft.Testing.Platform.Resources;

namespace Microsoft.Testing.Platform.OutputDevice.Terminal;

[Embedded]
internal abstract class SimpleTerminal : ITerminal
{
private object? _batchingLock;
Expand Down Expand Up @@ -171,7 +172,7 @@ public void StartUpdate()
{
if (_isBatching)
{
throw new InvalidOperationException(PlatformResources.ConsoleIsAlreadyInBatchingMode);
throw new InvalidOperationException(TerminalResources.ConsoleIsAlreadyInBatchingMode);
}

bool lockTaken = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.CodeAnalysis;

namespace Microsoft.Testing.Platform.OutputDevice.Terminal;

/// <summary>
/// Enumerates the text colors supported by VT100 terminal.
/// </summary>
[Embedded]
internal enum TerminalColor
{
/// <summary>
Expand Down
Loading