public void GetHostFxrPath_GlobalInstallation_HasNoDefaultInstallationPath() { string installLocation = Path.Combine(sharedState.ValidInstallRoot, "dotnet"); using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(sharedState.NethostPath)) { registeredInstallLocationOverride.SetInstallLocation(new (string, string)[] {
public void GetHostFxrPath_InstallLocationFile(string value, bool shouldPass) { string installLocation = Path.Combine(sharedState.ValidInstallRoot, "dotnet"); using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(sharedState.NethostPath)) { File.WriteAllText(registeredInstallLocationOverride.PathValueOverride, string.Format(value, 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().HaveStdErrContaining($"Looking for install_location file in '{registeredInstallLocationOverride.PathValueOverride}'."); if (shouldPass) { result.Should().Pass() .And.HaveStdErrContaining($"Using install location '{installLocation}'.") .And.HaveStdOutContaining($"hostfxr_path: {sharedState.HostFxrPath}".ToLower()); } else { result.Should().Fail() .And.ExitWith(1) .And.HaveStdOutContaining($"{GetHostFxrPath} failed: 0x{Constants.ErrorCode.CoreHostLibMissingFailure.ToString("x")}") .And.HaveStdErrContaining($"The required library {HostFxrName} could not be found"); } } }
public void InstallLocationFile_ArchSpecificLocationIsPickedFirst() { var fixture = sharedTestState.PortableAppFixture .Copy(); var appExe = fixture.TestProject.AppExe; var arch1 = "someArch"; var path1 = "x/y/z"; var arch2 = fixture.RepoDirProvider.BuildArchitecture; var path2 = "a/b/c"; using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(appExe)) { registeredInstallLocationOverride.SetInstallLocation(new (string, string)[] {
public void GetHostFxrPath_GlobalInstallation(bool explicitLoad, bool useAssemblyPath, bool useRegisteredLocation, bool isValid) { // Override the registry key for self-registered global installs. // If using the registered location, set the install location value to the valid/invalid root. // If not using the registered location, do not set the value. When the value does not exist, // the product falls back to the default install location. CommandResult result; string installLocation = Path.Combine(isValid ? sharedState.ValidInstallRoot : sharedState.InvalidInstallRoot, "dotnet"); using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(sharedState.NethostPath)) { if (useRegisteredLocation) { registeredInstallLocationOverride.SetInstallLocation((sharedState.RepoDirectories.BuildArchitecture, installLocation)); } result = Command.Create(sharedState.NativeHostPath, $"{GetHostFxrPath} {explicitLoad} {(useAssemblyPath ? sharedState.TestAssemblyPath : string.Empty)}") .EnableTracingAndCaptureOutputs() .ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride) .EnvironmentVariable( // Redirect the default install location to a test directory Constants.TestOnlyEnvironmentVariables.DefaultInstallPath, useRegisteredLocation ? sharedState.InvalidInstallRoot : installLocation) .DotNetRoot(null) .Execute(); } result.Should().HaveUsedGlobalInstallLocation(installLocation); if (useRegisteredLocation) { result.Should().HaveUsedRegisteredInstallLocation(installLocation); } if (isValid) { result.Should().Pass() .And.HaveStdOutContaining($"hostfxr_path: {sharedState.HostFxrPath}".ToLower()); } else { result.Should().Fail() .And.ExitWith(1) .And.HaveStdOutContaining($"{GetHostFxrPath} failed: 0x{Constants.ErrorCode.CoreHostLibMissingFailure.ToString("x")}") .And.HaveStdErrContaining($"The required library {HostFxrName} could not be found"); } }
public void GetHostFxrPath_InstallLocationFile(string value, bool shouldPass) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // This test targets the install_location config file which is only used on Linux and macOS. return; } string installLocation = Path.Combine(sharedState.ValidInstallRoot, "dotnet"); using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(sharedState.NethostPath)) { File.WriteAllText(registeredInstallLocationOverride.PathValueOverride, string.Format(value, installLocation)); CommandResult result = Command.Create(sharedState.NativeHostPath, GetHostFxrPath) .CaptureStdErr() .CaptureStdOut() .EnvironmentVariable("COREHOST_TRACE", "1") .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) .Execute(); result.Should().HaveStdErrContaining($"Looking for install_location file in '{registeredInstallLocationOverride.PathValueOverride}'."); if (shouldPass) { result.Should().Pass() .And.HaveStdErrContaining($"Using install location '{installLocation}'.") .And.HaveStdOutContaining($"hostfxr_path: {sharedState.HostFxrPath}".ToLower()); } else { result.Should().Fail() .And.ExitWith(1) .And.HaveStdOutContaining($"{GetHostFxrPath} failed: 0x{CoreHostLibMissingFailure.ToString("x")}") .And.HaveStdErrContaining($"The required library {HostFxrName} could not be found"); } } }
public void EnvironmentVariable_DotNetRootIsUsedOverInstallLocationIfSet() { var fixture = sharedTestState.PortableAppFixture .Copy(); var appExe = fixture.TestProject.AppExe; var arch = fixture.RepoDirProvider.BuildArchitecture.ToUpper(); var dotnet = fixture.BuiltDotnet.BinPath; using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(appExe)) { registeredInstallLocationOverride.SetInstallLocation((arch, "some/install/location")); Command.Create(appExe) .EnableTracingAndCaptureOutputs() .ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride) .DotNetRoot(dotnet, arch) .Execute() .Should().Pass() .And.HaveUsedDotNetRootInstallLocation(dotnet, fixture.CurrentRid, arch) .And.NotHaveStdErrContaining("Using global install location"); } }