|
4 | 4 | using System; |
5 | 5 | using System.IO; |
6 | 6 | using System.Runtime.InteropServices; |
| 7 | +using Microsoft.DotNet.Cli.Build; |
7 | 8 | using Microsoft.DotNet.Cli.Build.Framework; |
8 | 9 | using Microsoft.DotNet.CoreSetup.Test; |
9 | 10 | using Microsoft.DotNet.CoreSetup.Test.HostActivation; |
@@ -146,6 +147,44 @@ public void EnvironmentVariable_DotnetRootPathExistsButHasNoHost() |
146 | 147 | } |
147 | 148 | } |
148 | 149 |
|
| 150 | + [Fact] |
| 151 | + public void EnvironmentVariable_DotNetInfo_ListEnvironment() |
| 152 | + { |
| 153 | + var dotnet = new DotNetCli(sharedTestState.RepoDirectories.BuiltDotnet); |
| 154 | + |
| 155 | + var command = dotnet.Exec("--info") |
| 156 | + .CaptureStdOut(); |
| 157 | + |
| 158 | + var envVars = new (string Architecture, string Path)[] { |
| 159 | + ("arm64", "/arm64/dotnet/root"), |
| 160 | + ("x64", "/x64/dotnet/root"), |
| 161 | + ("x86", "/x86/dotnet/root") |
| 162 | + }; |
| 163 | + foreach(var envVar in envVars) |
| 164 | + { |
| 165 | + command = command.DotNetRoot(envVar.Path, envVar.Architecture); |
| 166 | + } |
| 167 | + |
| 168 | + string dotnetRootNoArch = "/dotnet/root"; |
| 169 | + command = command.DotNetRoot(dotnetRootNoArch); |
| 170 | + |
| 171 | + (string Architecture, string Path) unknownEnvVar = ("unknown", "/unknown/dotnet/root"); |
| 172 | + command = command.DotNetRoot(unknownEnvVar.Path, unknownEnvVar.Architecture); |
| 173 | + |
| 174 | + var result = command.Execute(); |
| 175 | + result.Should().Pass() |
| 176 | + .And.HaveStdOutContaining("Environment variables:") |
| 177 | + .And.HaveStdOutMatching($@"{Constants.DotnetRoot.EnvironmentVariable}\s*\[{dotnetRootNoArch}\]") |
| 178 | + .And.NotHaveStdOutContaining($"{Constants.DotnetRoot.ArchitectureEnvironmentVariablePrefix}{unknownEnvVar.Architecture.ToUpper()}") |
| 179 | + .And.NotHaveStdOutContaining($"[{unknownEnvVar.Path}]"); |
| 180 | + |
| 181 | + foreach ((string architecture, string path) in envVars) |
| 182 | + { |
| 183 | + result.Should() |
| 184 | + .HaveStdOutMatching($@"{Constants.DotnetRoot.ArchitectureEnvironmentVariablePrefix}{architecture.ToUpper()}\s*\[{path}\]"); |
| 185 | + } |
| 186 | + } |
| 187 | + |
149 | 188 | [Fact] |
150 | 189 | public void RegisteredInstallLocation_ArchSpecificLocationIsPickedFirst() |
151 | 190 | { |
@@ -241,6 +280,49 @@ public void InstallLocationFile_MissingFile() |
241 | 280 | } |
242 | 281 | } |
243 | 282 |
|
| 283 | + [Fact] |
| 284 | + public void RegisteredInstallLocation_DotNetInfo_ListOtherArchitectures() |
| 285 | + { |
| 286 | + using (var testArtifact = new TestArtifact(SharedFramework.CalculateUniqueTestDirectory(Path.Combine(TestArtifact.TestArtifactsPath, "listOtherArchs")))) |
| 287 | + { |
| 288 | + var dotnet = new DotNetBuilder(testArtifact.Location, sharedTestState.RepoDirectories.BuiltDotnet, "exe").Build(); |
| 289 | + using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(dotnet.GreatestVersionHostFxrFilePath)) |
| 290 | + { |
| 291 | + var installLocations = new (string, string)[] { |
| 292 | + ("arm64", "/arm64/install/path"), |
| 293 | + ("x64", "/x64/install/path"), |
| 294 | + ("x86", "/x86/install/path") |
| 295 | + }; |
| 296 | + (string Architecture, string Path) unknownArchInstall = ("unknown", "/unknown/install/path"); |
| 297 | + registeredInstallLocationOverride.SetInstallLocation(installLocations); |
| 298 | + registeredInstallLocationOverride.SetInstallLocation(unknownArchInstall); |
| 299 | + |
| 300 | + var result = dotnet.Exec("--info") |
| 301 | + .CaptureStdOut() |
| 302 | + .ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride) |
| 303 | + .Execute(); |
| 304 | + |
| 305 | + result.Should().Pass() |
| 306 | + .And.HaveStdOutContaining("Other architectures found:") |
| 307 | + .And.NotHaveStdOutContaining(unknownArchInstall.Architecture) |
| 308 | + .And.NotHaveStdOutContaining($"[{unknownArchInstall.Path}]"); |
| 309 | + |
| 310 | + string pathOverride = OperatingSystem.IsWindows() // Host uses short form of base key for Windows |
| 311 | + ? registeredInstallLocationOverride.PathValueOverride.Replace(Microsoft.Win32.Registry.CurrentUser.Name, "HKCU") |
| 312 | + : registeredInstallLocationOverride.PathValueOverride; |
| 313 | + pathOverride = System.Text.RegularExpressions.Regex.Escape(pathOverride); |
| 314 | + foreach ((string arch, string path) in installLocations) |
| 315 | + { |
| 316 | + if (arch == sharedTestState.RepoDirectories.BuildArchitecture) |
| 317 | + continue; |
| 318 | + |
| 319 | + result.Should() |
| 320 | + .HaveStdOutMatching($@"{arch}\s*\[{path}\]\r?$\s*registered at \[{pathOverride}.*{arch}.*\]", System.Text.RegularExpressions.RegexOptions.Multiline); |
| 321 | + } |
| 322 | + } |
| 323 | + } |
| 324 | + } |
| 325 | + |
244 | 326 | public class SharedTestState : IDisposable |
245 | 327 | { |
246 | 328 | public string BaseDirectory { get; } |
|
0 commit comments