Skip to content

Commit

Permalink
More
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink committed Dec 13, 2024
1 parent a634bdf commit 96bbef7
Show file tree
Hide file tree
Showing 79 changed files with 945 additions and 470 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@

using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Data;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endif
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using ITestDataSource = Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ITestDataSource;
using UTF = Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;

Expand All @@ -36,7 +35,7 @@ public class TestDataSource : ITestDataSource
#if NETFRAMEWORK
public IEnumerable<object>? GetData(ITestMethod testMethodInfo, ITestContext testContext)
#else
IEnumerable<object>? ITestDataSource.GetData(UTF.ITestMethod testMethodInfo, ITestContext testContext)
IEnumerable<object>? ITestDataSource.GetData(ITestMethod testMethodInfo, ITestContext testContext)
#endif
{
#if NETFRAMEWORK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.Testing.Platform.Acceptance.IntegrationTests;
using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers;

using SL = Microsoft.Build.Logging.StructuredLogger;
using SystemTask = System.Threading.Tasks.Task;

namespace MSTest.Acceptance.IntegrationTests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@
namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests;

[TestClass]
public class AbortionTests : AcceptanceTestBase
public class AbortionTests : AcceptanceTestBase<AbortionTests.TestAssetFixture>
{
private const string AssetName = "Abort";
private readonly TestAssetFixture _testAssetFixture;

public AbortionTests(TestAssetFixture testAssetFixture)
=> _testAssetFixture = testAssetFixture;

// We retry because sometime the Canceling the session message is not showing up.
[DynamicData(nameof(TargetFrameworks.All), typeof(TargetFrameworks))]
[DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))]
[TestMethod]
public async Task AbortWithCTRLPlusC_TestHost_Succeeded(string tfm)
{
// We expect the same semantic for Linux, the test setup is not cross and we're using specific
Expand All @@ -28,23 +25,22 @@ public async Task AbortWithCTRLPlusC_TestHost_Succeeded(string tfm)
return;
}

var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm);
var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync();

testHostResult.AssertExitCodeIs(ExitCodes.TestSessionAborted);

// We check only in netcore for netfx is now showing in CI every time, the same behavior in local something works sometime nope.
// Manual test works pretty always as expected, looks like the implementation is different, we care more on .NET Core.
if (TargetFrameworks.Net.Select(x => x.Arguments).Contains(tfm))
if (TargetFrameworks.Net.Contains(tfm))
{
testHostResult.AssertOutputMatchesRegex("Canceling the test session.*");
}

testHostResult.AssertOutputContainsSummary(failed: 0, passed: 0, skipped: 0, aborted: true);
}

[TestFixture(TestFixtureSharingStrategy.PerTestGroup)]
private sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder)
public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder)
{
private const string Sources = """
#file Abort.csproj
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@
namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests;

[TestClass]
public sealed class CrashDumpTests : AcceptanceTestBase
public sealed class CrashDumpTests : AcceptanceTestBase<CrashDumpTests.TestAssetFixture>
{
private readonly TestAssetFixture _testAssetFixture;

public CrashDumpTests(TestAssetFixture testAssetFixture)
=> _testAssetFixture = testAssetFixture;

[DynamicData(nameof(TargetFrameworks.Net), typeof(TargetFrameworks))]
[DynamicData(nameof(TargetFrameworks.NetForDynamicData), typeof(TargetFrameworks))]
[TestMethod]
public async Task CrashDump_DefaultSetting_CreateDump(string tfm)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
Expand All @@ -25,14 +21,15 @@ public async Task CrashDump_DefaultSetting_CreateDump(string tfm)
return;
}

string resultDirectory = Path.Combine(_testAssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"));
var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, "CrashDump", tfm);
string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"));
var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "CrashDump", tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync($"--crashdump --results-directory {resultDirectory}");
testHostResult.AssertExitCodeIs(ExitCodes.TestHostProcessExitedNonGracefully);
string? dumpFile = Directory.GetFiles(resultDirectory, "CrashDump.dll_*.dmp", SearchOption.AllDirectories).SingleOrDefault();
Assert.IsTrue(dumpFile is not null, $"Dump file not found '{tfm}'\n{testHostResult}'");
}

[TestMethod]
public async Task CrashDump_CustomDumpName_CreateDump()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
Expand All @@ -41,8 +38,8 @@ public async Task CrashDump_CustomDumpName_CreateDump()
return;
}

string resultDirectory = Path.Combine(_testAssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"));
var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, "CrashDump", TargetFrameworks.NetCurrent);
string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"));
var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "CrashDump", TargetFrameworks.NetCurrent);
TestHostResult testHostResult = await testHost.ExecuteAsync($"--crashdump --crashdump-filename customdumpname.dmp --results-directory {resultDirectory}");
testHostResult.AssertExitCodeIs(ExitCodes.TestHostProcessExitedNonGracefully);
Assert.IsTrue(Directory.GetFiles(resultDirectory, "customdumpname.dmp", SearchOption.AllDirectories).SingleOrDefault() is not null, "Dump file not found");
Expand All @@ -52,6 +49,7 @@ public async Task CrashDump_CustomDumpName_CreateDump()
[DataRow("Heap")]
[DataRow("Triage")]
[DataRow("Full")]
[TestMethod]
public async Task CrashDump_Formats_CreateDump(string format)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
Expand All @@ -60,26 +58,26 @@ public async Task CrashDump_Formats_CreateDump(string format)
return;
}

string resultDirectory = Path.Combine(_testAssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"));
var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, "CrashDump", TargetFrameworks.NetCurrent);
string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"));
var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "CrashDump", TargetFrameworks.NetCurrent);
TestHostResult testHostResult = await testHost.ExecuteAsync($"--crashdump --crashdump-type {format} --results-directory {resultDirectory}");
testHostResult.AssertExitCodeIs(ExitCodes.TestHostProcessExitedNonGracefully);
string? dumpFile = Directory.GetFiles(resultDirectory, "CrashDump.dll_*.dmp", SearchOption.AllDirectories).SingleOrDefault();
Assert.IsTrue(dumpFile is not null, $"Dump file not found '{format}'\n{testHostResult}'");
File.Delete(dumpFile);
}

[TestMethod]
public async Task CrashDump_InvalidFormat_ShouldFail()
{
string resultDirectory = Path.Combine(_testAssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"));
var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, "CrashDump", TargetFrameworks.NetCurrent);
string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"));
var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "CrashDump", TargetFrameworks.NetCurrent);
TestHostResult testHostResult = await testHost.ExecuteAsync($"--crashdump --crashdump-type invalid --results-directory {resultDirectory}");
testHostResult.AssertExitCodeIs(ExitCodes.InvalidCommandLine);
testHostResult.AssertOutputContains("Option '--crashdump-type' has invalid arguments: 'invalid' is not a valid dump type. Valid options are 'Mini', 'Heap', 'Triage' and 'Full'");
}

[TestFixture(TestFixtureSharingStrategy.PerTestGroup)]
private sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder)
public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder)
{
private const string AssetName = "CrashDumpFixture";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@
namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests;

[TestClass]
public sealed class CrashPlusHangDumpTests : AcceptanceTestBase
public sealed class CrashPlusHangDumpTests : AcceptanceTestBase<CrashPlusHangDumpTests.TestAssetFixture>
{
private readonly TestAssetFixture _testAssetFixture;

public CrashPlusHangDumpTests(TestAssetFixture testAssetFixture)
=> _testAssetFixture = testAssetFixture;

[TestMethod]
public async Task CrashPlusHangDump_InCaseOfCrash_CreateCrashDump()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
Expand All @@ -24,8 +20,8 @@ public async Task CrashPlusHangDump_InCaseOfCrash_CreateCrashDump()
return;
}

string resultDirectory = Path.Combine(_testAssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), TargetFrameworks.NetCurrent);
var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, "CrashPlusHangDump", TargetFrameworks.NetCurrent);
string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), TargetFrameworks.NetCurrent);
var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "CrashPlusHangDump", TargetFrameworks.NetCurrent);
TestHostResult testHostResult = await testHost.ExecuteAsync(
$"--hangdump --hangdump-timeout 5m --crashdump --results-directory {resultDirectory}",
new Dictionary<string, string?>
Expand All @@ -43,6 +39,7 @@ public async Task CrashPlusHangDump_InCaseOfCrash_CreateCrashDump()
Assert.IsFalse(Directory.GetFiles(resultDirectory, "CrashPlusHangDump*_hang.dmp", SearchOption.AllDirectories).Length > 0, $"Dump file not found '{TargetFrameworks.NetCurrent}'\n{testHostResult}'");
}

[TestMethod]
public async Task CrashPlusHangDump_InCaseOfHang_CreateHangDump()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
Expand All @@ -51,8 +48,8 @@ public async Task CrashPlusHangDump_InCaseOfHang_CreateHangDump()
return;
}

string resultDirectory = Path.Combine(_testAssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), TargetFrameworks.NetCurrent);
var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, "CrashPlusHangDump", TargetFrameworks.NetCurrent);
string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), TargetFrameworks.NetCurrent);
var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "CrashPlusHangDump", TargetFrameworks.NetCurrent);
TestHostResult testHostResult = await testHost.ExecuteAsync(
$"--hangdump --hangdump-timeout 8s --crashdump --results-directory {resultDirectory}",
new Dictionary<string, string?>
Expand All @@ -70,8 +67,7 @@ public async Task CrashPlusHangDump_InCaseOfHang_CreateHangDump()
Assert.IsTrue(Directory.GetFiles(resultDirectory, "CrashPlusHangDump*_hang.dmp", SearchOption.AllDirectories).Length > 0, $"Dump file not found '{TargetFrameworks.NetCurrent}'\n{testHostResult}'");
}

[TestFixture(TestFixtureSharingStrategy.PerTestGroup)]
private sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder)
public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder)
{
private const string AssetName = "AssetFixture";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,26 @@
namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests;

[TestClass]
public class CustomBannerTests : AcceptanceTestBase
public class CustomBannerTests : AcceptanceTestBase<CustomBannerTests.TestAssetFixture>
{
private const string AssetName = "CustomBannerTest";
private readonly TestAssetFixture _testAssetFixture;

public CustomBannerTests(TestAssetFixture testAssetFixture)
=> _testAssetFixture = testAssetFixture;

[DynamicData(nameof(TargetFrameworks.All), typeof(TargetFrameworks))]
[DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))]
[TestMethod]
public async Task UsingNoBanner_TheBannerDoesNotAppear(string tfm)
{
var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm);
var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync("--no-banner");

testHostResult.AssertExitCodeIs(ExitCodes.ZeroTests);
testHostResult.AssertOutputDoesNotContain(TestAssetFixture.CustomBannerPrefix);
}

[DynamicData(nameof(TargetFrameworks.All), typeof(TargetFrameworks))]
[DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))]
[TestMethod]
public async Task UsingNoBanner_InTheEnvironmentVars_TheBannerDoesNotAppear(string tfm)
{
var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm);
var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync(
null,
new Dictionary<string, string?>
Expand All @@ -40,10 +38,11 @@ public async Task UsingNoBanner_InTheEnvironmentVars_TheBannerDoesNotAppear(stri
testHostResult.AssertOutputDoesNotContain(TestAssetFixture.CustomBannerPrefix);
}

[DynamicData(nameof(TargetFrameworks.All), typeof(TargetFrameworks))]
[DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))]
[TestMethod]
public async Task UsingDotnetNoLogo_InTheEnvironmentVars_TheBannerDoesNotAppear(string tfm)
{
var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm);
var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync(
null,
new Dictionary<string, string?>
Expand All @@ -55,18 +54,18 @@ public async Task UsingDotnetNoLogo_InTheEnvironmentVars_TheBannerDoesNotAppear(
testHostResult.AssertOutputDoesNotContain(TestAssetFixture.CustomBannerPrefix);
}

[DynamicData(nameof(TargetFrameworks.All), typeof(TargetFrameworks))]
[DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))]
[TestMethod]
public async Task WithoutUsingNoBanner_TheBannerAppears(string tfm)
{
var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm);
var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync();

testHostResult.AssertExitCodeIs(ExitCodes.ZeroTests);
testHostResult.AssertOutputMatchesRegex($"{TestAssetFixture.CustomBannerPrefix} Platform info: Name: .NET Testing Platform, Version: .+?, Hash: .*?, Date: .+?");
}

[TestFixture(TestFixtureSharingStrategy.PerTestGroup)]
private sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder)
public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder)
{
public const string CustomBannerPrefix = "Custom banner |";

Expand Down
Loading

0 comments on commit 96bbef7

Please sign in to comment.