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
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Testing.Extensions.CtrfReport;
using Microsoft.Testing.Extensions.CtrfReport.Resources;
using Microsoft.Testing.Platform.Builder;
using Microsoft.Testing.Platform.Extensions;
using Microsoft.Testing.Platform.Helpers;
Expand All @@ -22,6 +23,11 @@ public static class CtrfReportExtensions
/// <param name="builder">The test application builder.</param>
public static void AddCtrfReportProvider(this ITestApplicationBuilder builder)
{
if (builder is not TestApplicationBuilder)
{
throw new InvalidOperationException(ExtensionResources.InvalidTestApplicationBuilderType);
}

var commandLine = new CtrfReportGeneratorCommandLine();

var compositeCtrfReportGenerator =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,29 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Testing.Extensions.CtrfReport.Resources;
using Microsoft.Testing.Platform.CommandLine;
using Microsoft.Testing.Platform.Extensions;
using Microsoft.Testing.Platform.Extensions.CommandLine;

namespace Microsoft.Testing.Extensions.CtrfReport;

internal sealed class CtrfReportGeneratorCommandLine : CommandLineOptionsProviderBase
internal sealed class CtrfReportGeneratorCommandLine : ReportGeneratorCommandLineBase
{
public const string CtrfReportOptionName = "report-ctrf";
public const string CtrfReportFileNameOptionName = "report-ctrf-filename";

public CtrfReportGeneratorCommandLine()
: base(
nameof(CtrfReportGeneratorCommandLine),
ExtensionVersion.DefaultSemVer,
ExtensionResources.CtrfReportGeneratorDisplayName,
ExtensionResources.CtrfReportGeneratorDescription,
[
new(CtrfReportOptionName, ExtensionResources.CtrfReportOptionDescription, ArgumentArity.Zero, false),
new(CtrfReportFileNameOptionName, ExtensionResources.CtrfReportFileNameOptionDescription, ArgumentArity.ExactlyOne, false),
])
{
}

public override Task<ValidationResult> ValidateOptionArgumentsAsync(CommandLineOption commandOption, string[] arguments)
=> commandOption.Name == CtrfReportFileNameOptionName
? ReportFileNameValidator.ValidateReportFileNameArgumentAsync(
arguments,
".json",
ExtensionResources.CtrfReportFileNameMustNotBeEmpty,
ExtensionResources.CtrfReportFileNameExtensionIsNotJson,
ExtensionResources.CtrfReportFileNameRelativePathMustStayUnderResultsDirectory)
: ValidationResult.ValidTask;

public override Task<ValidationResult> ValidateCommandLineOptionsAsync(ICommandLineOptions commandLineOptions)
=> ReportFileNameValidator.ValidateReportCommandLineOptionsAsync(
commandLineOptions,
CtrfReportOptionName,
CtrfReportFileNameOptionName,
ExtensionResources.CtrfReportOptionDescription,
ExtensionResources.CtrfReportFileNameOptionDescription,
".json",
ExtensionResources.CtrfReportFileNameMustNotBeEmpty,
ExtensionResources.CtrfReportFileNameExtensionIsNotJson,
ExtensionResources.CtrfReportFileNameRelativePathMustStayUnderResultsDirectory,
ExtensionResources.CtrfReportFileNameRequiresCtrfReport,
ExtensionResources.CtrfReportIsNotValidForDiscovery,
PlatformCommandLineProvider.DiscoverTestsOptionKey);
ExtensionResources.CtrfReportIsNotValidForDiscovery)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ This package extends Microsoft Testing Platform to produce test reports in the C
<Compile Include="$(RepoRoot)src\Platform\Microsoft.Testing.Platform\Resources\PlatformResources.cs" Link="Resources\PlatformResources.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportEngineBase.cs" Link="Helpers\ReportEngineBase.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportGeneratorBase.cs" Link="Helpers\ReportGeneratorBase.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportGeneratorCommandLineBase.cs" Link="Helpers\ReportGeneratorCommandLineBase.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportFileNameValidator.cs" Link="Helpers\ReportFileNameValidator.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\TestResultCaptureHelper.cs" Link="Helpers\TestResultCaptureHelper.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,8 @@ Example: MyReport_{tfm}.ctrf.json</value>
<value>Enable generating a CTRF (Common Test Report Format) JSON report</value>
<comment>Do not localize option name {Locked="--report-ctrf"} or format names {Locked="CTRF"}{Locked="Common Test Report Format"}{Locked="JSON"}.</comment>
</data>
<data name="InvalidTestApplicationBuilderType" xml:space="preserve">
<value>Invalid test application builder type. Expected 'TestApplicationBuilder'.</value>
<comment>Do not localize {Locked="TestApplicationBuilder"}.</comment>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ Příklad: MyReport_{tfm}.ctrf.json</target>
<target state="translated">Povolit generování sestavy JSON CTRF (Common Test Report Format)</target>
<note>Do not localize option name {Locked="--report-ctrf"} or format names {Locked="CTRF"}{Locked="Common Test Report Format"}{Locked="JSON"}.</note>
</trans-unit>
<trans-unit id="InvalidTestApplicationBuilderType">
<source>Invalid test application builder type. Expected 'TestApplicationBuilder'.</source>
<target state="new">Invalid test application builder type. Expected 'TestApplicationBuilder'.</target>
<note>Do not localize {Locked="TestApplicationBuilder"}.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ Beispiel: MyReport_{tfm}.ctrf.json</target>
<target state="translated">Generierung eines CTRF-JSON-Berichts (Common Test Report Format) aktivieren</target>
<note>Do not localize option name {Locked="--report-ctrf"} or format names {Locked="CTRF"}{Locked="Common Test Report Format"}{Locked="JSON"}.</note>
</trans-unit>
<trans-unit id="InvalidTestApplicationBuilderType">
<source>Invalid test application builder type. Expected 'TestApplicationBuilder'.</source>
<target state="new">Invalid test application builder type. Expected 'TestApplicationBuilder'.</target>
<note>Do not localize {Locked="TestApplicationBuilder"}.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ Ejemplo: MyReport_{tfm}.ctrf.json</target>
<target state="translated">Habilitación de la generación de un informe JSON de CTRF (Common Test Report Format)</target>
<note>Do not localize option name {Locked="--report-ctrf"} or format names {Locked="CTRF"}{Locked="Common Test Report Format"}{Locked="JSON"}.</note>
</trans-unit>
<trans-unit id="InvalidTestApplicationBuilderType">
<source>Invalid test application builder type. Expected 'TestApplicationBuilder'.</source>
<target state="new">Invalid test application builder type. Expected 'TestApplicationBuilder'.</target>
<note>Do not localize {Locked="TestApplicationBuilder"}.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ Exemple : MyReport_{tfm}.ctrf.json</target>
<target state="translated">Activer la génération d’un rapport JSON CTRF (Common Test Report Format)</target>
<note>Do not localize option name {Locked="--report-ctrf"} or format names {Locked="CTRF"}{Locked="Common Test Report Format"}{Locked="JSON"}.</note>
</trans-unit>
<trans-unit id="InvalidTestApplicationBuilderType">
<source>Invalid test application builder type. Expected 'TestApplicationBuilder'.</source>
<target state="new">Invalid test application builder type. Expected 'TestApplicationBuilder'.</target>
<note>Do not localize {Locked="TestApplicationBuilder"}.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ Esempio: MyReport_{tfm}.ctrf.json</target>
<target state="translated">Abilita la generazione di un report JSON CTRF (Common Test Report Format)</target>
<note>Do not localize option name {Locked="--report-ctrf"} or format names {Locked="CTRF"}{Locked="Common Test Report Format"}{Locked="JSON"}.</note>
</trans-unit>
<trans-unit id="InvalidTestApplicationBuilderType">
<source>Invalid test application builder type. Expected 'TestApplicationBuilder'.</source>
<target state="new">Invalid test application builder type. Expected 'TestApplicationBuilder'.</target>
<note>Do not localize {Locked="TestApplicationBuilder"}.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ Example: MyReport_{tfm}.ctrf.json</source>
<target state="translated">CTRF (Common Test Report Format) JSON レポートの生成を有効にする</target>
<note>Do not localize option name {Locked="--report-ctrf"} or format names {Locked="CTRF"}{Locked="Common Test Report Format"}{Locked="JSON"}.</note>
</trans-unit>
<trans-unit id="InvalidTestApplicationBuilderType">
<source>Invalid test application builder type. Expected 'TestApplicationBuilder'.</source>
<target state="new">Invalid test application builder type. Expected 'TestApplicationBuilder'.</target>
<note>Do not localize {Locked="TestApplicationBuilder"}.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ Example: MyReport_{tfm}.ctrf.json</source>
<target state="translated">CTRF(Common Test Report Format) JSON 보고서 생성 사용</target>
<note>Do not localize option name {Locked="--report-ctrf"} or format names {Locked="CTRF"}{Locked="Common Test Report Format"}{Locked="JSON"}.</note>
</trans-unit>
<trans-unit id="InvalidTestApplicationBuilderType">
<source>Invalid test application builder type. Expected 'TestApplicationBuilder'.</source>
<target state="new">Invalid test application builder type. Expected 'TestApplicationBuilder'.</target>
<note>Do not localize {Locked="TestApplicationBuilder"}.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ Przykład: MyReport_{tfm}.ctrf.json</target>
<target state="translated">Włącz generowanie raportu JSON CTRF (Common Test Report Format)</target>
<note>Do not localize option name {Locked="--report-ctrf"} or format names {Locked="CTRF"}{Locked="Common Test Report Format"}{Locked="JSON"}.</note>
</trans-unit>
<trans-unit id="InvalidTestApplicationBuilderType">
<source>Invalid test application builder type. Expected 'TestApplicationBuilder'.</source>
<target state="new">Invalid test application builder type. Expected 'TestApplicationBuilder'.</target>
<note>Do not localize {Locked="TestApplicationBuilder"}.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ Exemplo: MyReport_{tfm}.ctrf.json</target>
<target state="translated">Habilitar a geração de um relatório JSON CTRF (Common Test Report Format)</target>
<note>Do not localize option name {Locked="--report-ctrf"} or format names {Locked="CTRF"}{Locked="Common Test Report Format"}{Locked="JSON"}.</note>
</trans-unit>
<trans-unit id="InvalidTestApplicationBuilderType">
<source>Invalid test application builder type. Expected 'TestApplicationBuilder'.</source>
<target state="new">Invalid test application builder type. Expected 'TestApplicationBuilder'.</target>
<note>Do not localize {Locked="TestApplicationBuilder"}.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ Example: MyReport_{tfm}.ctrf.json</source>
<target state="translated">Включить создание JSON-отчета в формате CTRF (Common Test Report Format)</target>
<note>Do not localize option name {Locked="--report-ctrf"} or format names {Locked="CTRF"}{Locked="Common Test Report Format"}{Locked="JSON"}.</note>
</trans-unit>
<trans-unit id="InvalidTestApplicationBuilderType">
<source>Invalid test application builder type. Expected 'TestApplicationBuilder'.</source>
<target state="new">Invalid test application builder type. Expected 'TestApplicationBuilder'.</target>
<note>Do not localize {Locked="TestApplicationBuilder"}.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ Example: MyReport_{tfm}.ctrf.json</source>
<target state="translated">CTRF (Common Test Report Format) JSON raporu oluşturmayı etkinleştir</target>
<note>Do not localize option name {Locked="--report-ctrf"} or format names {Locked="CTRF"}{Locked="Common Test Report Format"}{Locked="JSON"}.</note>
</trans-unit>
<trans-unit id="InvalidTestApplicationBuilderType">
<source>Invalid test application builder type. Expected 'TestApplicationBuilder'.</source>
<target state="new">Invalid test application builder type. Expected 'TestApplicationBuilder'.</target>
<note>Do not localize {Locked="TestApplicationBuilder"}.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ Example: MyReport_{tfm}.ctrf.json</source>
<target state="translated">启用生成 CTRF (Common Test Report Format) JSON 报表</target>
<note>Do not localize option name {Locked="--report-ctrf"} or format names {Locked="CTRF"}{Locked="Common Test Report Format"}{Locked="JSON"}.</note>
</trans-unit>
<trans-unit id="InvalidTestApplicationBuilderType">
<source>Invalid test application builder type. Expected 'TestApplicationBuilder'.</source>
<target state="new">Invalid test application builder type. Expected 'TestApplicationBuilder'.</target>
<note>Do not localize {Locked="TestApplicationBuilder"}.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ Example: MyReport_{tfm}.ctrf.json</source>
<target state="translated">能夠產生 CTRF (Common Test Report Format) JSON 報告</target>
<note>Do not localize option name {Locked="--report-ctrf"} or format names {Locked="CTRF"}{Locked="Common Test Report Format"}{Locked="JSON"}.</note>
</trans-unit>
<trans-unit id="InvalidTestApplicationBuilderType">
<source>Invalid test application builder type. Expected 'TestApplicationBuilder'.</source>
<target state="new">Invalid test application builder type. Expected 'TestApplicationBuilder'.</target>
<note>Do not localize {Locked="TestApplicationBuilder"}.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ namespace Microsoft.Testing.Extensions.CtrfReport;
// stdout/stderr/stack traces) in memory for the whole session.
internal static class TestResultCapture
{
internal const int MaxStandardStreamLength = 32 * 1024;
internal const int MaxStackTraceLength = 32 * 1024;
internal const int MaxMessageLength = 16 * 1024;
internal const int MaxIdentityFieldLength = 4 * 1024;
internal const int MaxTraitFieldLength = 1024;
internal const int MaxStandardStreamLength = TestResultCaptureHelper.MaxStandardStreamLength;
internal const int MaxStackTraceLength = TestResultCaptureHelper.MaxStackTraceLength;
internal const int MaxMessageLength = TestResultCaptureHelper.MaxMessageLength;
internal const int MaxIdentityFieldLength = TestResultCaptureHelper.MaxIdentityFieldLength;
internal const int MaxTraitFieldLength = TestResultCaptureHelper.MaxTraitFieldLength;

public static CapturedTestResult? TryCapture(TestNode node)
{
Expand Down Expand Up @@ -149,8 +149,5 @@ private static (string? Namespace, string? ClassName, string? MethodName) GetCla
}

internal static string? Truncate(string? value, int maxLength)
=> value is null || value.Length <= maxLength
? value
: value.Substring(0, maxLength)
+ $"\n…[truncated, original length: {value.Length.ToString(CultureInfo.InvariantCulture)}]";
=> TestResultCaptureHelper.Truncate(value, maxLength);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,29 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Testing.Extensions.HtmlReport.Resources;
using Microsoft.Testing.Platform.CommandLine;
using Microsoft.Testing.Platform.Extensions;
using Microsoft.Testing.Platform.Extensions.CommandLine;

namespace Microsoft.Testing.Extensions.HtmlReport;

internal sealed class HtmlReportGeneratorCommandLine : CommandLineOptionsProviderBase
internal sealed class HtmlReportGeneratorCommandLine : ReportGeneratorCommandLineBase
{
public const string HtmlReportOptionName = "report-html";
public const string HtmlReportFileNameOptionName = "report-html-filename";

public HtmlReportGeneratorCommandLine()
: base(
nameof(HtmlReportGeneratorCommandLine),
ExtensionVersion.DefaultSemVer,
ExtensionResources.HtmlReportGeneratorDisplayName,
ExtensionResources.HtmlReportGeneratorDescription,
[
new(HtmlReportOptionName, ExtensionResources.HtmlReportOptionDescription, ArgumentArity.Zero, false),
new(HtmlReportFileNameOptionName, ExtensionResources.HtmlReportFileNameOptionDescription, ArgumentArity.ExactlyOne, false),
])
{
}

public override Task<ValidationResult> ValidateOptionArgumentsAsync(CommandLineOption commandOption, string[] arguments)
=> commandOption.Name == HtmlReportFileNameOptionName
? ReportFileNameValidator.ValidateReportFileNameArgumentAsync(
arguments,
".html",
ExtensionResources.HtmlReportFileNameMustNotBeEmpty,
ExtensionResources.HtmlReportFileNameExtensionIsNotHtml,
ExtensionResources.HtmlReportFileNameRelativePathMustStayUnderResultsDirectory)
: ValidationResult.ValidTask;

public override Task<ValidationResult> ValidateCommandLineOptionsAsync(ICommandLineOptions commandLineOptions)
=> ReportFileNameValidator.ValidateReportCommandLineOptionsAsync(
commandLineOptions,
HtmlReportOptionName,
HtmlReportFileNameOptionName,
ExtensionResources.HtmlReportOptionDescription,
ExtensionResources.HtmlReportFileNameOptionDescription,
".html",
ExtensionResources.HtmlReportFileNameMustNotBeEmpty,
ExtensionResources.HtmlReportFileNameExtensionIsNotHtml,
ExtensionResources.HtmlReportFileNameRelativePathMustStayUnderResultsDirectory,
ExtensionResources.HtmlReportFileNameRequiresHtmlReport,
ExtensionResources.HtmlReportIsNotValidForDiscovery,
PlatformCommandLineProvider.DiscoverTestsOptionKey);
ExtensionResources.HtmlReportIsNotValidForDiscovery)
{
}
}
Loading