Skip to content

Commit f0aadc7

Browse files
committed
Put new tests in HostCommands test class
1 parent 5b55c3b commit f0aadc7

File tree

3 files changed

+134
-90
lines changed

3 files changed

+134
-90
lines changed

src/installer/tests/HostActivation.Tests/FrameworkResolution/MultipleHives.cs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -163,51 +163,6 @@ public void ListRuntimes(bool? multiLevelLookup)
163163
.And.HaveStdErrContaining("Ignoring FX version [9999.9.9] without .deps.json");
164164
}
165165

166-
[Fact]
167-
public void ListRuntimes_OtherArchitectures()
168-
{
169-
// Non-host architectures
170-
string[] otherArchs = new[] { "arm64", "x64", "x86" }.Where(a => a != TestContext.BuildArchitecture).ToArray();
171-
var installLocations = new (string, string)[otherArchs.Length];
172-
173-
using (var testArtifact = TestArtifact.Create("listOtherArchs"))
174-
{
175-
// Add runtimes for other architectures
176-
string[] versions = ["9999.0.0", "9999.0.1", "9999.0.2"];
177-
for (int i = 0; i < otherArchs.Length; i++)
178-
{
179-
string arch = otherArchs[i];
180-
string installLocation = Directory.CreateDirectory(Path.Combine(testArtifact.Location, arch)).FullName;
181-
foreach (string version in versions)
182-
{
183-
DotNetBuilder.AddMicrosoftNETCoreAppFrameworkMockHostPolicy(installLocation, version);
184-
}
185-
186-
installLocations[i] = (arch, installLocation);
187-
}
188-
189-
var dotnet = new DotNetBuilder(testArtifact.Location, TestContext.BuiltDotNet.BinPath, "exe").Build();
190-
using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(dotnet.GreatestVersionHostFxrFilePath))
191-
{
192-
registeredInstallLocationOverride.SetInstallLocation(installLocations);
193-
foreach (var (arch, installLocation) in installLocations)
194-
{
195-
// Verifiy exact match of command output. The output of --list-runtimes is intended to be machine-readable
196-
// and must not change in a way that breaks existing parsing.
197-
string runtimePath = Path.Combine(installLocation, "shared", MicrosoftNETCoreApp);
198-
string expectedOutput = string.Join(string.Empty, versions.Select(v => $"{MicrosoftNETCoreApp} {v} [{runtimePath}]{Environment.NewLine}"));
199-
dotnet.Exec("--list-runtimes", "--arch", arch)
200-
.ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride)
201-
.CaptureStdOut()
202-
.Execute()
203-
.Should().Pass()
204-
.And.HaveStdOut(expectedOutput);
205-
206-
}
207-
}
208-
}
209-
}
210-
211166
[Theory]
212167
[InlineData(true)]
213168
[InlineData(null)]
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.IO;
7+
using System.Linq;
8+
using Microsoft.DotNet.Cli.Build;
9+
using Microsoft.DotNet.Cli.Build.Framework;
10+
using Microsoft.DotNet.CoreSetup.Test;
11+
using Microsoft.DotNet.CoreSetup.Test.HostActivation;
12+
using Microsoft.DotNet.TestUtils;
13+
using Xunit;
14+
15+
namespace HostActivation.Tests
16+
{
17+
public class HostCommands : IClassFixture<HostCommands.SharedTestState>
18+
{
19+
private SharedTestState SharedState { get; }
20+
21+
public HostCommands(SharedTestState sharedState)
22+
{
23+
SharedState = sharedState;
24+
}
25+
26+
[Fact]
27+
public void ListRuntimes_OtherArchitectures()
28+
{
29+
using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(SharedState.DotNet.GreatestVersionHostFxrFilePath))
30+
{
31+
registeredInstallLocationOverride.SetInstallLocation(SharedState.OtherArchInstallLocations);
32+
foreach ((string arch, string installLocation) in SharedState.OtherArchInstallLocations)
33+
{
34+
// Verifiy exact match of command output. The output of --list-runtimes is intended to be machine-readable
35+
// and must not change in a way that breaks existing parsing.
36+
string expectedOutput = GetListRuntimesOutput(installLocation, SharedState.InstalledVersions);
37+
SharedState.DotNet.Exec("--list-runtimes", "--arch", arch)
38+
.ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride)
39+
.CaptureStdOut()
40+
.Execute()
41+
.Should().Pass()
42+
.And.HaveStdOut(expectedOutput);
43+
}
44+
}
45+
}
46+
47+
[Fact]
48+
public void ListSdks_OtherArchitectures()
49+
{
50+
using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(SharedState.DotNet.GreatestVersionHostFxrFilePath))
51+
{
52+
registeredInstallLocationOverride.SetInstallLocation(SharedState.OtherArchInstallLocations);
53+
foreach ((string arch, string installLocation) in SharedState.OtherArchInstallLocations)
54+
{
55+
// Verifiy exact match of command output. The output of --list-sdks is intended to be machine-readable
56+
// and must not change in a way that breaks existing parsing.
57+
string expectedOutput = GetListSdksOutput(installLocation, SharedState.InstalledVersions);
58+
SharedState.DotNet.Exec("--list-sdks", "--arch", arch)
59+
.ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride)
60+
.CaptureStdOut()
61+
.Execute()
62+
.Should().Pass()
63+
.And.HaveStdOut(expectedOutput);
64+
}
65+
}
66+
}
67+
68+
private static string GetListRuntimesOutput(string installLocation, string[] versions)
69+
{
70+
string runtimePath = Path.Combine(installLocation, "shared", Constants.MicrosoftNETCoreApp);
71+
return string.Join(string.Empty, versions.Select(v => $"{Constants.MicrosoftNETCoreApp} {v} [{runtimePath}]{Environment.NewLine}"));
72+
}
73+
74+
private static string GetListSdksOutput(string installLocation, string[] versions)
75+
{
76+
string sdkPath = Path.Combine(installLocation, "sdk");
77+
return string.Join(string.Empty, versions.Select(v => $"{v} [{sdkPath}]{Environment.NewLine}"));
78+
}
79+
80+
public sealed class SharedTestState : IDisposable
81+
{
82+
public DotNetCli DotNet { get; }
83+
84+
// Versions are assumed to be in ascending order. We use this property to check against the
85+
// exact expected output of --list-sdks and --list-runtimes.
86+
public string[] InstalledVersions { get; } = ["5.0.5", "10.0.0", "9999.0.1"];
87+
88+
public (string, string)[] OtherArchInstallLocations { get; }
89+
90+
private TestArtifact _artifact;
91+
92+
public SharedTestState()
93+
{
94+
_artifact = TestArtifact.Create(nameof(HostCommands));
95+
96+
var builder = new DotNetBuilder(_artifact.Location, TestContext.BuiltDotNet.BinPath, "exe");
97+
foreach (string version in InstalledVersions)
98+
{
99+
builder.AddMicrosoftNETCoreAppFrameworkMockHostPolicy(version);
100+
builder.AddMockSDK(version, version);
101+
}
102+
103+
DotNet = builder.Build();
104+
105+
// Add runtimes and SDKs for other architectures
106+
string[] otherArchs = new[] { "arm", "arm64", "x64", "x86" }.Where(a => a != TestContext.BuildArchitecture).ToArray();
107+
OtherArchInstallLocations = new (string, string)[otherArchs.Length];
108+
for (int i = 0; i < otherArchs.Length; i++)
109+
{
110+
string arch = otherArchs[i];
111+
string installLocation = Directory.CreateDirectory(Path.Combine(_artifact.Location, arch)).FullName;
112+
foreach (string version in InstalledVersions)
113+
{
114+
DotNetBuilder.AddMicrosoftNETCoreAppFrameworkMockHostPolicy(installLocation, version);
115+
DotNetBuilder.AddMockSDK(installLocation, version, version);
116+
}
117+
118+
OtherArchInstallLocations[i] = (arch, installLocation);
119+
}
120+
121+
122+
// Enable test-only behavior for the copied .NET. We don't bother disabling the behaviour later,
123+
// as we just delete the entire copy after the tests run.
124+
_ = TestOnlyProductBehavior.Enable(DotNet.GreatestVersionHostFxrFilePath);
125+
126+
}
127+
128+
public void Dispose()
129+
{
130+
_artifact.Dispose();
131+
}
132+
}
133+
}
134+
}

src/installer/tests/HostActivation.Tests/SDKLookup.cs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -603,51 +603,6 @@ public void GlobalJson_ErrorMessage()
603603
.And.HaveStdErrContaining(sdk.ErrorMessage);
604604
}
605605

606-
[Fact]
607-
public void ListSdks_OtherArchitectures()
608-
{
609-
// Non-host architectures
610-
var otherArchs = new[] { "arm64", "x64", "x86" }.Where(a => a != TestContext.BuildArchitecture).ToArray();
611-
var installLocations = new (string, string)[otherArchs.Length];
612-
613-
using (var testArtifact = TestArtifact.Create("listOtherArchs"))
614-
{
615-
// Add SDKs for other architectures
616-
string[] versions = ["9999.0.0", "9999.0.1", "9999.0.2"];
617-
for (int i = 0; i < otherArchs.Length; i++)
618-
{
619-
string arch = otherArchs[i];
620-
string installLocation = Directory.CreateDirectory(Path.Combine(testArtifact.Location, arch)).FullName;
621-
foreach (string version in versions)
622-
{
623-
DotNetBuilder.AddMockSDK(installLocation, version, version);
624-
}
625-
626-
installLocations[i] = (arch, installLocation);
627-
}
628-
629-
var dotnet = new DotNetBuilder(testArtifact.Location, TestContext.BuiltDotNet.BinPath, "exe").Build();
630-
using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(dotnet.GreatestVersionHostFxrFilePath))
631-
{
632-
registeredInstallLocationOverride.SetInstallLocation(installLocations);
633-
foreach (var (arch, installLocation) in installLocations)
634-
{
635-
// Verifiy exact match of command output. The output of --list-sdks is intended to be machine-readable
636-
// and must not change in a way that breaks existing parsing.
637-
string sdkPath = Path.Combine(installLocation, "sdk");
638-
string expectedOutput = string.Join(string.Empty, versions.Select(v => $"{v} [{sdkPath}]{Environment.NewLine}"));
639-
dotnet.Exec("--list-sdks", "--arch", arch)
640-
.ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride)
641-
.CaptureStdOut()
642-
.EnableTracingAndCaptureOutputs()
643-
.Execute()
644-
.Should().Pass()
645-
.And.HaveStdOut(expectedOutput);
646-
}
647-
}
648-
}
649-
}
650-
651606
public static IEnumerable<object[]> InvalidGlobalJsonData
652607
{
653608
get

0 commit comments

Comments
 (0)