Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This is a .NET based repository that contains the MSTest testing framework and M
The codebase ships several distinct (but related) products. Knowing which product a change belongs to is essential because they have different conventions, target frameworks, and public API surfaces:

- `src/Platform/Microsoft.Testing.Platform` — Microsoft.Testing.Platform (MTP), a lightweight, in-process test host that replaces VSTest. Most other folders under `src/Platform/` are MTP extensions (`TrxReport`, `CrashDump`, `HangDump`, `HotReload`, `Retry`, `Telemetry`, `HtmlReport`, `AzureDevOpsReport`, `MSBuild`, `VSTestBridge`, …).
- `src/TestFramework` — MSTest itself: the public `Microsoft.VisualStudio.TestTools.UnitTesting` API (attributes, `Assert`, `TestContext`, …) plus `TestFramework.Extensions`.
- `src/TestFramework` — MSTest itself: the shared `Microsoft.VisualStudio.TestTools.UnitTesting` API (attributes, `Assert`, `TestContext`, …), plus the explicit `MSTest.Uwp` and `MSTest.WinUI` application-model packages.
- `src/Adapter` — bridges MSTest to test hosts: `MSTest.TestAdapter` (VSTest adapter) and `MSTestAdapter.PlatformServices` (platform-services abstraction shared by both hosts).
- `src/Analyzers` — Roslyn analyzers and code fixes shipped as `MSTest.Analyzers`.
- `src/Package/MSTest.Sdk` — the MSBuild project SDK that wires the pieces together for consumers.
Expand Down
3 changes: 0 additions & 3 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ filegroup(
":crashdump",
":ctrf",
":framework",
":framework_extensions",
":github_report",
":globalconfigs_generator",
":hangdump",
Expand Down Expand Up @@ -179,7 +178,6 @@ testfx_binary(
":adapter",
":ctrf",
":framework",
":framework_extensions",
":html",
":junit",
":trx",
Expand Down Expand Up @@ -210,7 +208,6 @@ testfx_binary(
deps = [
":assert_generator",
":framework",
":framework_extensions",
":internal_test_framework",
":trx",
"@paket.source//awesomeassertions",
Expand Down
3 changes: 2 additions & 1 deletion MSTest.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"src\\Package\\MSTest\\MSTest.csproj",
"src\\Platform\\Microsoft.Testing.Extensions.PackagedApp.Controller\\Microsoft.Testing.Extensions.PackagedApp.Controller.csproj",
"src\\Platform\\Microsoft.Testing.Extensions.PackagedApp.MSBuild\\Microsoft.Testing.Extensions.PackagedApp.MSBuild.csproj",
"src\\TestFramework\\TestFramework.Extensions\\TestFramework.Extensions.csproj",
"src\\TestFramework\\MSTest.Uwp\\MSTest.Uwp.csproj",
"src\\TestFramework\\MSTest.WinUI\\MSTest.WinUI.csproj",
"src\\TestFramework\\TestFramework.Windows.UIAutomation\\TestFramework.Windows.UIAutomation.csproj",
"src\\TestFramework\\TestFramework.SourceGeneration\\TestFramework.SourceGeneration.csproj",
"src\\TestFramework\\TestFramework\\TestFramework.csproj",
Expand Down
1 change: 0 additions & 1 deletion NonWindowsTests.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"src\\Platform\\Microsoft.Testing.Platform.MSBuild\\Microsoft.Testing.Platform.MSBuild.csproj",
"src\\Platform\\Microsoft.Testing.Platform.ServerMode.Client.Sources\\Microsoft.Testing.Platform.ServerMode.Client.Sources.csproj",
"src\\Platform\\Microsoft.Testing.Platform\\Microsoft.Testing.Platform.csproj",
"src\\TestFramework\\TestFramework.Extensions\\TestFramework.Extensions.csproj",
"src\\TestFramework\\TestFramework.Windows.UIAutomation\\TestFramework.Windows.UIAutomation.csproj",
"src\\TestFramework\\TestFramework.SourceGeneration\\TestFramework.SourceGeneration.csproj",
"src\\TestFramework\\TestFramework\\TestFramework.csproj",
Expand Down
3 changes: 2 additions & 1 deletion TestFx.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
<Project Path="src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csproj" />
</Folder>
<Folder Name="/src/3 - TestFramework/">
<Project Path="src/TestFramework/TestFramework.Extensions/TestFramework.Extensions.csproj" />
<Project Path="src/TestFramework/MSTest.Uwp/MSTest.Uwp.csproj" />
<Project Path="src/TestFramework/MSTest.WinUI/MSTest.WinUI.csproj" />
<Project Path="src/TestFramework/TestFramework.Windows.UIAutomation/TestFramework.Windows.UIAutomation.csproj" />
<Project Path="src/TestFramework/TestFramework/TestFramework.csproj" />
<Project Path="src/TestFramework/TestFramework.SourceGeneration/TestFramework.SourceGeneration.csproj" />
Expand Down
200 changes: 200 additions & 0 deletions docs/decisions/bazel-build.md

Large diffs are not rendered by default.

334 changes: 334 additions & 0 deletions docs/decisions/mstest-platform-packages.md

Large diffs are not rendered by default.

35 changes: 26 additions & 9 deletions eng/bazel/MSTestPackageVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
using System.Text;
using System.Text.Json.Nodes;

if (args.Length != 3)
bool exactFramework = args.Length == 4 && args[3] == "--exact-framework";
if (args.Length != 3 && !exactFramework)
{
throw new ArgumentException("Expected <package-request-template> <platform-version-file> <package-request-output>.");
throw new ArgumentException("Expected <package-request-template> <dependency-version-file> <package-request-output> [--exact-framework].");
}

string version = File.ReadAllText(args[1]).Trim();
Expand All @@ -25,26 +26,42 @@
?? throw new InvalidDataException("Expected a package request object.");
if (request["dependencyGroups"] is not JsonArray groups || groups.Count == 0)
{
throw new InvalidDataException("Expected nonempty platform dependency groups.");
throw new InvalidDataException("Expected nonempty dependency groups.");
}

if (exactFramework)
{
if (request["metadata"]?["id"]?.GetValue<string>() is not ("MSTest.Uwp" or "MSTest.WinUI"))
{
throw new InvalidDataException("Only UI packages may pin the matching framework dependency.");
}

string ownVersionFile = request["versionFile"]?.GetValue<string>()
?? throw new InvalidDataException("The UI package must declare its own version file.");
if (File.ReadAllText(ownVersionFile).Trim() != version)
{
throw new InvalidDataException("The UI package and core dependency versions must match exactly.");
}
}

string dependencyId = exactFramework ? "MSTest.TestFramework" : "Microsoft.Testing.Platform";
foreach (JsonNode? group in groups)
{
if (group?["dependencies"] is not JsonArray dependencies)
{
throw new InvalidDataException("A package dependency group is missing its dependencies.");
}

JsonObject[] platform = dependencies.OfType<JsonObject>()
.Where(dependency => dependency["id"]?.GetValue<string>() == "Microsoft.Testing.Platform")
JsonObject[] bounded = dependencies.OfType<JsonObject>()
.Where(dependency => dependency["id"]?.GetValue<string>() == dependencyId)
.ToArray();
if (platform.Length != 1)
if (bounded.Length != 1)
{
throw new InvalidDataException("Each bounded group must declare exactly one platform dependency.");
throw new InvalidDataException($"Each bounded group must declare exactly one {dependencyId} dependency.");
}

_ = platform[0].Remove("versionFile");
platform[0]["version"] = $"[{version}, {nextMajor}.0.0)";
_ = bounded[0].Remove("versionFile");
bounded[0]["version"] = exactFramework ? $"[{version}]" : $"[{version}, {nextMajor}.0.0)";
}

File.WriteAllText(args[2], request.ToJsonString(), new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
12 changes: 8 additions & 4 deletions eng/bazel/SdkPackageTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ string ExpandMetadata(string value) => Regex.Replace(value, @"\$\(([^()]+)\)", m
ProjectUrl = "https://github.com/microsoft/testfx",
Repository = new { Type = "git", Url = "https://github.com/microsoft/testfx" },
ReleaseNotes = ExpandMetadata(Property(sourceProperties, "PackageReleaseNotes"))
+ "\nExperimental native Bazel build, not an official release. Portable .NET 8/9/10/11 package scope; Windows, .NET Framework, UWP and NativeAOT execution are not validated.",
+ "\nExperimental native Bazel build, not an official release. Portable .NET 10/11 package scope; Windows, .NET Framework, UWP and NativeAOT execution are not validated.",
},
PackageTypes = Array.Empty<string>(),
DependencyGroups = input.PackageId == "MSTest"
Expand Down Expand Up @@ -193,8 +193,9 @@ static Dependency[] MetaPackageDependencies(XElement project, Dictionary<string,
{
var projectDependencies = new Dictionary<string, (string id, string version, string condition)>(StringComparer.Ordinal)
{
["$(RepoRoot)src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csproj"] = ("MSTest.TestAdapter", versions["MSTestVersion"], ""),
["$(RepoRoot)src/TestFramework/TestFramework.Extensions/TestFramework.Extensions.csproj"] = ("MSTest.TestFramework", versions["MSTestVersion"], ""),
["$(RepoRoot)src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csproj"] = ("MSTest.TestAdapter", versions["MSTestVersion"], "'$(TargetFramework)'!='$(UwpMinimum)'"),
["$(RepoRoot)src/TestFramework/MSTest.Uwp/MSTest.Uwp.csproj"] = ("MSTest.Uwp", versions["MSTestVersion"], "'$(TargetFramework)'=='$(UwpMinimum)'"),
["$(RepoRoot)src/TestFramework/TestFramework/TestFramework.csproj"] = ("MSTest.TestFramework", versions["MSTestVersion"], ""),
["$(RepoRoot)src/Platform/Microsoft.Testing.Extensions.TrxReport/Microsoft.Testing.Extensions.TrxReport.csproj"] = ("Microsoft.Testing.Extensions.TrxReport", versions["MicrosoftTestingPlatformVersion"], "'$(TargetFramework)'!='$(UwpMinimum)'"),
};
var dependencies = new List<Dependency>();
Expand All @@ -207,7 +208,10 @@ static Dependency[] MetaPackageDependencies(XElement project, Dictionary<string,
throw new InvalidDataException($"Unsupported meta-package project reference or condition: {path}");
}

dependencies.Add(new(dependency.id, dependency.version, ["Build", "Analyzers"]));
if (dependency.condition != "'$(TargetFramework)'=='$(UwpMinimum)'")
{
dependencies.Add(new(dependency.id, dependency.version, ["Build", "Analyzers"]));
}
}

if (projectDependencies.Count != 0)
Expand Down
2 changes: 0 additions & 2 deletions eng/bazel/compatibility.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ _PROJECTS = {
"crashdump",
"ctrf",
"framework",
"framework_extensions",
"github_report",
"hangdump",
"hosting",
Expand All @@ -36,7 +35,6 @@ _PROJECTS = {
"net462": [
"adapter",
"framework",
"framework_extensions",
"mstest_hosting",
"platform_services",
],
Expand Down
2 changes: 1 addition & 1 deletion eng/bazel/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

load("@rules_dotnet//dotnet:defs.bzl", "csharp_binary", "csharp_library", "import_library")

PORTABLE_FRAMEWORKS = ["net8.0", "net9.0", "net10.0", "net11.0"]
PORTABLE_FRAMEWORKS = ["net10.0", "net11.0"]
STANDARD_FRAMEWORKS = PORTABLE_FRAMEWORKS + ["netstandard2.0"]
DESKTOP_FRAMEWORKS = PORTABLE_FRAMEWORKS + ["net462"]

Expand Down
2 changes: 1 addition & 1 deletion eng/bazel/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def extension_libraries():
"src/Adapter/MSTest.Extensions.Hosting/Resources/HostingResources.resx": "Microsoft.VisualStudio.TestTools.UnitTesting.Hosting.Resources.HostingResources",
},
internals_visible_to = ["Microsoft.Testing.Extensions.UnitTests", "Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests"],
deps = [":adapter", ":hosting", ":framework", ":framework_extensions"] + testfx_nuget(["microsoft.extensions.dependencyinjection.abstractions"], compatibility_group = "compatibility_hosting") + select({
deps = [":adapter", ":hosting", ":framework"] + testfx_nuget(["microsoft.extensions.dependencyinjection.abstractions"], compatibility_group = "compatibility_hosting") + select({
"//eng/bazel/compatibility:net462": [":netframework_netstandard_facade", ":netframework_runtime_information"],
"//conditions:default": [],
}),
Expand Down
38 changes: 30 additions & 8 deletions eng/bazel/mstest-consumer/NativePackageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public void NativeAssembliesAreLoadedFromConsumer()
string[] names =
[
"MSTest.TestFramework",
"MSTest.TestFramework.Extensions",
"MSTest.TestAdapter",
"MSTestAdapter.PlatformServices",
"Microsoft.Testing.Platform",
Expand All @@ -31,6 +30,7 @@ public void NativeAssembliesAreLoadedFromConsumer()
"Microsoft.Testing.Extensions.TrxReport.Abstractions",
];
Assert.AreSequenceEqual(names, assemblies.EnumerateObject().Select(property => property.Name).ToArray(), SequenceOrder.InAnyOrder);
Assert.IsFalse(File.Exists(Path.Combine(AppContext.BaseDirectory, "MSTest.TestFramework.Extensions.dll")));

var loaded = new List<object>();
foreach (string name in names)
Expand All @@ -48,13 +48,19 @@ public void NativeAssembliesAreLoadedFromConsumer()

string evidence = Environment.GetEnvironmentVariable("TESTFX_BAZEL_CONSUMER_EVIDENCE")
?? throw new InvalidOperationException("The consumer evidence path was not supplied.");
File.WriteAllText(evidence, JsonSerializer.Serialize(new
string reportPath = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(evidence))!, "loaded-assemblies-" + Guid.NewGuid().ToString("N") + ".json");
using (FileStream report = File.Open(reportPath, FileMode.CreateNew, FileAccess.Write, FileShare.Read))
{
Runtime = RuntimeInformation.FrameworkDescription,
CoreLib = typeof(object).Assembly.Location,
Framework = expectations.RootElement.GetProperty("Framework").GetString(),
Assemblies = loaded,
}));
JsonSerializer.Serialize(report, new
{
Runtime = RuntimeInformation.FrameworkDescription,
CoreLib = typeof(object).Assembly.Location,
Framework = expectations.RootElement.GetProperty("Framework").GetString(),
Assemblies = loaded,
});
}

File.AppendAllLines(evidence, [reportPath]);
}

[TestMethod]
Expand All @@ -80,9 +86,25 @@ public void KoreanSatellitesAreCopiedAndLoadable()
}

[TestMethod]
public void PackagedTargetsProvideExtensionsAndParallelization()
public void PackagedTargetsProvideCoreAndParallelization()
{
Assert.AreEqual("MSTest.TestFramework", typeof(TestContext).Assembly.GetName().Name);
Assert.AreSame(typeof(Assert).Assembly, typeof(TestContext).Assembly);
Assert.AreSame(typeof(Assert).Assembly, typeof(DeploymentItemAttribute).Assembly);
string[] directories =
[
nameof(TestContext.TestRunDirectory),
nameof(TestContext.DeploymentDirectory),
nameof(TestContext.ResultsDirectory),
nameof(TestContext.TestRunResultsDirectory),
nameof(TestContext.TestResultsDirectory),
nameof(TestContext.TestTempDirectory),
];
foreach (string directory in directories)
{
Assert.IsNotNull(typeof(TestContext).GetProperty(directory), directory);
}

ParallelizeAttribute? parallelize = typeof(NativePackageTests).Assembly.GetCustomAttribute<ParallelizeAttribute>();
Assert.IsNotNull(parallelize);
Assert.AreEqual(ExecutionScope.MethodLevel, parallelize.Scope);
Expand Down
Loading
Loading