Skip to content
Merged
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 src/installer/tests/HostActivation.Tests/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static class TestOnlyEnvironmentVariables
public const string DefaultInstallPath = "_DOTNET_TEST_DEFAULT_INSTALL_PATH";
public const string RegistryPath = "_DOTNET_TEST_REGISTRY_PATH";
public const string GloballyRegisteredPath = "_DOTNET_TEST_GLOBALLY_REGISTERED_PATH";
public const string InstallLocationFilePath = "_DOTNET_TEST_INSTALL_LOCATION_FILE_PATH";
public const string InstallLocationPath = "_DOTNET_TEST_INSTALL_LOCATION_PATH";
}

public static class RuntimeId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


using System;
using System.IO;
using System.Runtime.InteropServices;
using FluentAssertions;
using Microsoft.DotNet.Cli.Build.Framework;
Expand Down Expand Up @@ -45,14 +46,14 @@ public static AndConstraint<CommandResultAssertions> HaveUsedGlobalInstallLocati
return assertion.HaveStdErrContaining($"Using global installation location [{installLocation}]");
}

public static AndConstraint<CommandResultAssertions> HaveFoundDefaultInstallLocationInConfigFile(this CommandResultAssertions assertion, string installLocation)
public static AndConstraint<CommandResultAssertions> HaveLookedForDefaultInstallLocation(this CommandResultAssertions assertion, string installLocationPath)
{
return assertion.HaveStdErrContaining($"Found install location path '{installLocation}'.");
return assertion.HaveStdErrContaining($"Looking for install_location file in '{Path.Combine(installLocationPath, "install_location")}'.");
}

public static AndConstraint<CommandResultAssertions> HaveFoundArchSpecificInstallLocationInConfigFile(this CommandResultAssertions assertion, string installLocation, string arch)
public static AndConstraint<CommandResultAssertions> HaveLookedForArchitectureSpecificInstallLocation(this CommandResultAssertions assertion, string installLocationPath, string architecture)
{
return assertion.HaveStdErrContaining($"Found architecture-specific install location path: '{installLocation}' ('{arch}').");
return assertion.HaveStdErrContaining($"Looking for architecture specific install_location file in '{Path.Combine(installLocationPath, "install_location_" + architecture.ToLowerInvariant())}'.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,40 +174,14 @@ public void InstallLocationFile_ArchSpecificLocationIsPickedFirst()

if (!OperatingSystem.IsWindows())
{
result.Should().HaveFoundDefaultInstallLocationInConfigFile(path1)
.And.HaveFoundArchSpecificInstallLocationInConfigFile(path1, arch1)
.And.HaveFoundArchSpecificInstallLocationInConfigFile(path2, arch2);
result.Should()
.HaveLookedForArchitectureSpecificInstallLocation(registeredInstallLocationOverride.PathValueOverride, arch2);
}

result.Should().HaveUsedGlobalInstallLocation(path2);
}
}

[Fact]
[SkipOnPlatform(TestPlatforms.Windows, "This test targets the install_location config file which is only used on Linux and macOS.")]
public void InstallLocationFile_OnlyFirstLineMayNotSpecifyArchitecture()
{
var fixture = sharedTestState.PortableAppFixture
.Copy();

var appExe = fixture.TestProject.AppExe;
using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(appExe))
{
registeredInstallLocationOverride.SetInstallLocation(new (string, string)[] {
(string.Empty, "a/b/c"),
(string.Empty, "x/y/z"),
});
Command.Create(appExe)
.EnableTracingAndCaptureOutputs()
.ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride)
.DotNetRoot(null)
.Execute()
.Should().HaveFoundDefaultInstallLocationInConfigFile("a/b/c")
.And.HaveStdErrContaining($"Only the first line in '{registeredInstallLocationOverride.PathValueOverride}' may not have an architecture prefix.")
.And.HaveUsedConfigFileInstallLocation("a/b/c");
}
}

[Fact]
[SkipOnPlatform(TestPlatforms.Windows, "This test targets the install_location config file which is only used on Linux and macOS.")]
public void InstallLocationFile_ReallyLongInstallPathIsParsedCorrectly()
Expand All @@ -229,7 +203,7 @@ public void InstallLocationFile_ReallyLongInstallPathIsParsedCorrectly()
.ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride)
.DotNetRoot(null)
.Execute()
.Should().HaveFoundDefaultInstallLocationInConfigFile(reallyLongPath)
.Should().HaveLookedForDefaultInstallLocation(registeredInstallLocationOverride.PathValueOverride)
.And.HaveUsedConfigFileInstallLocation(reallyLongPath);
}
}
Expand All @@ -247,16 +221,15 @@ public void InstallLocationFile_MissingFile()
{
Directory.CreateDirectory(testArtifactsPath);

string directory = Path.Combine(testArtifactsPath, "installLocationOverride");
Directory.CreateDirectory(directory);
string nonExistentLocationFile = Path.Combine(directory, "install_location");
string installLocationDirectory = Path.Combine(testArtifactsPath, "installLocationOverride");
Directory.CreateDirectory(installLocationDirectory);
string defaultInstallLocation = Path.Combine(testArtifactsPath, "defaultInstallLocation");

Command.Create(appExe)
.CaptureStdErr()
.EnvironmentVariable(
Constants.TestOnlyEnvironmentVariables.InstallLocationFilePath,
nonExistentLocationFile)
Constants.TestOnlyEnvironmentVariables.InstallLocationPath,
installLocationDirectory)
.EnvironmentVariable(
Constants.TestOnlyEnvironmentVariables.DefaultInstallPath,
defaultInstallLocation)
Expand Down
58 changes: 20 additions & 38 deletions src/installer/tests/HostActivation.Tests/NativeHosting/Nethost.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using HostActivation.Tests;
using Microsoft.DotNet.Cli.Build.Framework;
using System;
using System.IO;
Expand Down Expand Up @@ -216,12 +217,21 @@ public void GetHostFxrPath_InstallLocationFile(string value, bool shouldUseArchS
.DotNetRoot(null)
.Execute();

result.Should().HaveStdErrContaining($"Looking for install_location file in '{registeredInstallLocationOverride.PathValueOverride}'.");
if (shouldUseArchSpecificInstallLocation)
{
result.Should().HaveLookedForArchitectureSpecificInstallLocation(
registeredInstallLocationOverride.PathValueOverride,
sharedState.RepoDirectories.BuildArchitecture);
}
else
{
result.Should().HaveLookedForDefaultInstallLocation(registeredInstallLocationOverride.PathValueOverride);
}

if (shouldPass)
{
result.Should().Pass()
.And.HaveStdErrContaining($"Using install location '{installLocation}'.")
.And.HaveUsedConfigFileInstallLocation(installLocation)
.And.HaveStdOutContaining($"hostfxr_path: {sharedState.HostFxrPath}".ToLower());
}
else
Expand All @@ -234,35 +244,6 @@ public void GetHostFxrPath_InstallLocationFile(string value, bool shouldUseArchS
}
}

[Fact]
[SkipOnPlatform(TestPlatforms.Windows, "This test targets the install_location config file which is only used on Linux and macOS.")]
public void GetHostFxrPath_GlobalInstallation_HasMoreThanOneDefaultInstallationPath()
{
string installLocation = Path.Combine(sharedState.ValidInstallRoot, "dotnet");
using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(sharedState.NethostPath))
{
registeredInstallLocationOverride.SetInstallLocation(new (string, string)[] {
(string.Empty, installLocation), (string.Empty, installLocation)
});

CommandResult result = Command.Create(sharedState.NativeHostPath, GetHostFxrPath)
.EnableTracingAndCaptureOutputs()
.ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride)
.EnvironmentVariable( // Redirect the default install location to an invalid location so that it doesn't cause the test to pass
Constants.TestOnlyEnvironmentVariables.DefaultInstallPath,
sharedState.InvalidInstallRoot)
.DotNetRoot(null)
.Execute();

result.Should().Pass()
.And.HaveStdErrContaining($"Looking for install_location file in '{registeredInstallLocationOverride.PathValueOverride}'.")
.And.HaveStdErrContaining($"Found install location path '{installLocation}'.")
.And.HaveStdErrContaining($"Only the first line in '{registeredInstallLocationOverride.PathValueOverride}' may not have an architecture prefix.")
.And.HaveStdErrContaining($"Using install location '{installLocation}'.")
.And.HaveStdOutContaining($"hostfxr_path: {sharedState.HostFxrPath}".ToLower());
}
}

[Fact]
[SkipOnPlatform(TestPlatforms.Windows, "This test targets the install_location config file which is only used on Linux and macOS.")]
public void GetHostFxrPath_GlobalInstallation_HasNoDefaultInstallationPath()
Expand All @@ -285,9 +266,10 @@ public void GetHostFxrPath_GlobalInstallation_HasNoDefaultInstallationPath()
.Execute();

result.Should().Pass()
.And.HaveStdErrContaining($"Looking for install_location file in '{registeredInstallLocationOverride.PathValueOverride}'.")
.And.HaveStdErrContaining($"Found architecture-specific install location path: '{installLocation}' ('{sharedState.RepoDirectories.BuildArchitecture.ToLower()}').")
.And.HaveStdErrContaining($"Using install location '{installLocation}'.")
.And.HaveLookedForArchitectureSpecificInstallLocation(
registeredInstallLocationOverride.PathValueOverride,
sharedState.RepoDirectories.BuildArchitecture)
.And.HaveUsedConfigFileInstallLocation(installLocation)
.And.HaveStdOutContaining($"hostfxr_path: {sharedState.HostFxrPath}".ToLower());
}
}
Expand All @@ -314,10 +296,10 @@ public void GetHostFxrPath_GlobalInstallation_ArchitectureSpecificPathIsPickedOv
.Execute();

result.Should().Pass()
.And.HaveStdErrContaining($"Looking for install_location file in '{registeredInstallLocationOverride.PathValueOverride}'.")
.And.HaveStdErrContaining($"Found install location path '{installLocation}/a/b/c'.")
.And.HaveStdErrContaining($"Found architecture-specific install location path: '{installLocation}' ('{sharedState.RepoDirectories.BuildArchitecture.ToLower()}').")
.And.HaveStdErrContaining($"Using install location '{installLocation}'.")
.And.HaveLookedForArchitectureSpecificInstallLocation(
registeredInstallLocationOverride.PathValueOverride,
sharedState.RepoDirectories.BuildArchitecture)
.And.HaveUsedConfigFileInstallLocation(installLocation)
.And.HaveStdOutContaining($"hostfxr_path: {sharedState.HostFxrPath}".ToLower());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ public RegisteredInstallLocationOverride(string productBinaryPath)
// On Linux/macOS the install location is registered in a file which is normally
// located in /etc/dotnet/install_location
// So we need to redirect it to a different place here.
string directory = Path.Combine(TestArtifact.TestArtifactsPath, "installLocationOverride");
string directory = Path.Combine(TestArtifact.TestArtifactsPath, "installLocationOverride" + Process.GetCurrentProcess().Id.ToString());
if (Directory.Exists(directory))
Directory.Delete(directory, true);
Directory.CreateDirectory(directory);
PathValueOverride = Path.Combine(directory, "install_location." + Process.GetCurrentProcess().Id.ToString());
File.WriteAllText(PathValueOverride, "");
PathValueOverride = directory;
}
}

Expand All @@ -78,9 +79,12 @@ public void SetInstallLocation(params (string Architecture, string Path)[] locat
}
else
{
File.WriteAllText(PathValueOverride, string.Join(Environment.NewLine,
locations.Select(l => string.Format("{0}{1}",
(!string.IsNullOrWhiteSpace(l.Architecture) ? l.Architecture + "=" : ""), l.Path))));
foreach (var location in locations)
{
string installLocationFileName = "install_location" +
(!string.IsNullOrWhiteSpace(location.Architecture) ? ("_" + location.Architecture) : string.Empty);
File.WriteAllText(Path.Combine(PathValueOverride, installLocationFileName), location.Path);
}
}
}

Expand Down Expand Up @@ -127,7 +131,7 @@ public static Command ApplyRegisteredInstallLocationOverride(
else
{
return command.EnvironmentVariable(
Constants.TestOnlyEnvironmentVariables.InstallLocationFilePath,
Constants.TestOnlyEnvironmentVariables.InstallLocationPath,
registeredInstallLocationOverride.PathValueOverride);
}
}
Expand Down
Loading