Skip to content
Open
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 @@ -100,6 +100,7 @@ public override (string ID, string Name, string Code) GetAssetsToGenerate() => (
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Testing.Platform" Version="$MicrosoftTestingPlatformVersion$" />
<PackageReference Include="MSTest" Version="$MSTestVersion$" />
<PackageReference Include="Microsoft.Testing.Extensions.JUnitReport" Version="$MicrosoftTestingExtensionsJUnitReportVersion$" />
</ItemGroup>
Expand Down Expand Up @@ -233,6 +234,7 @@ public override (string ID, string Name, string Code) GetAssetsToGenerate() => (
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Testing.Platform" Version="$MicrosoftTestingPlatformVersion$" />
<PackageReference Include="MSTest" Version="$MSTestVersion$" />
<PackageReference Include="Microsoft.Testing.Extensions.JUnitReport" Version="$MicrosoftTestingExtensionsJUnitReportVersion$" />
<PackageReference Include="Microsoft.Testing.Extensions.Retry" Version="$MicrosoftTestingPlatformVersion$" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public sealed class TelemetryTests : AcceptanceTestBase<TelemetryTests.TestAsset
public async Task MTP_RunTests_SendsTelemetryWithSettingsAndAttributes(string tfm)
{
string diagPath = Path.Combine(AssetFixture.MTPProjectPath, "bin", "Release", tfm, TestResultsFolderName);
string diagPathPattern = Path.Combine(diagPath, @"log_.*.diag").Replace(@"\", @"\\");
string diagPathPattern = BuildDefaultDiagnosticFilePathPattern(diagPath, tfm);

var testHost = TestHost.LocateFrom(AssetFixture.MTPProjectPath, MTPAssetName, tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync(
Expand Down Expand Up @@ -66,7 +66,7 @@ public async Task MTP_RunTests_SendsTelemetryWithSettingsAndAttributes(string tf
public async Task MTP_DiscoverTests_SendsTelemetryEvent(string tfm)
{
string diagPath = Path.Combine(AssetFixture.MTPProjectPath, "bin", "Release", tfm, TestResultsFolderName);
string diagPathPattern = Path.Combine(diagPath, @"log_.*.diag").Replace(@"\", @"\\");
string diagPathPattern = BuildDefaultDiagnosticFilePathPattern(diagPath, tfm);

var testHost = TestHost.LocateFrom(AssetFixture.MTPProjectPath, MTPAssetName, tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync(
Expand All @@ -92,7 +92,7 @@ public async Task MTP_DiscoverTests_SendsTelemetryEvent(string tfm)
public async Task MTP_WhenTelemetryDisabled_DoesNotSendMSTestEvent(string tfm)
{
string diagPath = Path.Combine(AssetFixture.MTPProjectPath, "bin", "Release", tfm, TestResultsFolderName);
string diagPathPattern = Path.Combine(diagPath, @"log_.*.diag").Replace(@"\", @"\\");
string diagPathPattern = BuildDefaultDiagnosticFilePathPattern(diagPath, tfm);

var testHost = TestHost.LocateFrom(AssetFixture.MTPProjectPath, MTPAssetName, tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync(
Expand Down Expand Up @@ -195,6 +195,17 @@ private static async Task<string> AssertDiagnosticReportAsync(TestHostResult tes
return (Regex.IsMatch(content, pattern), content);
}

// Build a regex matching the deterministic default diagnostic file name shape:
// "<asset-name>_<tfm>_<arch>_<yyMMddHHmmssfff>.diag". The arch token is taken from the
// current process (the testhost runs on the same machine, so its ProcessArchitecture matches).
private static string BuildDefaultDiagnosticFilePathPattern(string diagPath, string tfm)
{
string arch = RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant();
const string FileNamePlaceholder = "__DIAG_FILENAME__";
string combinedPath = Path.Combine(diagPath, FileNamePlaceholder).Replace(@"\", @"\\");
return combinedPath.Replace(FileNamePlaceholder, $@"{MTPAssetName}_{Regex.Escape(tfm)}_{arch}_\d{{15}}\.diag");
}

#endregion

public sealed class TestAssetFixture() : TestAssetFixtureBase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class TelemetryDisabledTests : AcceptanceTestBase<TelemetryDisable
public async Task Telemetry_WhenEnableTelemetryIsFalse_WithTestApplicationOptions_TelemetryIsDisabled(string tfm)
{
string diagPath = Path.Combine(AssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName);
string diagPathPattern = Path.Combine(diagPath, @"log_.*.diag").Replace(@"\", @"\\");
string diagPathPattern = BuildDefaultDiagnosticFilePathPattern(diagPath, tfm);

var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync("--diagnostic", disableTelemetry: false, cancellationToken: TestContext.CancellationToken);
Expand Down Expand Up @@ -55,6 +55,17 @@ private static async Task<string> AssertDiagnosticReportAsync(TestHostResult tes
return (Regex.IsMatch(content, pattern), content);
}

// Build a regex matching the deterministic default diagnostic file name shape:
// "<asset-name>_<tfm>_<arch>_<yyMMddHHmmssfff>.diag". The arch token is taken from the
// current process (the testhost runs on the same machine, so its ProcessArchitecture matches).
private static string BuildDefaultDiagnosticFilePathPattern(string diagPath, string tfm)
{
string arch = RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant();
const string FileNamePlaceholder = "__DIAG_FILENAME__";
string combinedPath = Path.Combine(diagPath, FileNamePlaceholder).Replace(@"\", @"\\");
return combinedPath.Replace(FileNamePlaceholder, $@"{AssetName}_{Regex.Escape(tfm)}_{arch}_\d{{15}}\.diag");
}

public sealed class TestAssetFixture() : TestAssetFixtureBase()
{
private const string WithoutTelemetry = nameof(WithoutTelemetry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class TelemetryTests : AcceptanceTestBase<TelemetryTests.TestAssetFixture
public async Task Telemetry_ByDefault_TelemetryIsEnabled(string tfm)
{
string diagPath = Path.Combine(AssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName);
string diagPathPattern = Path.Combine(diagPath, @"log_.*.diag").Replace(@"\", @"\\");
string diagPathPattern = BuildDefaultDiagnosticFilePathPattern(diagPath, tfm);

var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync("--diagnostic", disableTelemetry: false, cancellationToken: TestContext.CancellationToken);
Expand All @@ -37,7 +37,7 @@ public async Task Telemetry_ByDefault_TelemetryIsEnabled(string tfm)
public async Task Telemetry_WhenOptingOutTelemetry_WithEnvironmentVariable_TelemetryIsDisabled(string tfm)
{
string diagPath = Path.Combine(AssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName);
string diagPathPattern = Path.Combine(diagPath, @"log_.*.diag").Replace(@"\", @"\\");
string diagPathPattern = BuildDefaultDiagnosticFilePathPattern(diagPath, tfm);

var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync(
Expand Down Expand Up @@ -66,7 +66,7 @@ public async Task Telemetry_WhenOptingOutTelemetry_WithEnvironmentVariable_Telem
public async Task Telemetry_WhenOptingOutTelemetry_With_DOTNET_CLI_EnvironmentVariable_TelemetryIsDisabled(string tfm)
{
string diagPath = Path.Combine(AssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName);
string diagPathPattern = Path.Combine(diagPath, @"log_.*.diag").Replace(@"\", @"\\");
string diagPathPattern = BuildDefaultDiagnosticFilePathPattern(diagPath, tfm);

var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync(
Expand Down Expand Up @@ -113,6 +113,17 @@ private static async Task<string> AssertDiagnosticReportAsync(TestHostResult tes
return (Regex.IsMatch(content, pattern), content);
}

// Build a regex matching the deterministic default diagnostic file name shape:
// "<asset-name>_<tfm>_<arch>_<yyMMddHHmmssfff>.diag". The arch token is taken from the
// current process (the testhost runs on the same machine, so its ProcessArchitecture matches).
private static string BuildDefaultDiagnosticFilePathPattern(string diagPath, string tfm)
{
string arch = RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant();
const string FileNamePlaceholder = "__DIAG_FILENAME__";
string combinedPath = Path.Combine(diagPath, FileNamePlaceholder).Replace(@"\", @"\\");
return combinedPath.Replace(FileNamePlaceholder, $@"{AssetName}_{Regex.Escape(tfm)}_{arch}_\d{{15}}\.diag");
}

public sealed class TestAssetFixture() : TestAssetFixtureBase()
{
private const string WithTelemetry = nameof(WithTelemetry);
Expand Down
Loading