diff --git a/src/Microsoft.DotNet.Configurer/NoOpFileSentinel.cs b/src/Microsoft.DotNet.Configurer/NoOpFileSentinel.cs index e77097011..80e3d0831 100644 --- a/src/Microsoft.DotNet.Configurer/NoOpFileSentinel.cs +++ b/src/Microsoft.DotNet.Configurer/NoOpFileSentinel.cs @@ -7,9 +7,16 @@ namespace Microsoft.DotNet.Configurer { public class NoOpFileSentinel : IFileSentinel { + private bool _exists; + + public NoOpFileSentinel(bool exists) + { + _exists = exists; + } + public bool Exists() { - return true; + return _exists; } public void Create() diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index 6ae1409ce..ce08bcb56 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -147,7 +147,7 @@ namespace Microsoft.DotNet.Cli { aspNetCertificateSentinel = new NoOpAspNetCertificateSentinel(); firstTimeUseNoticeSentinel = new NoOpFirstTimeUseNoticeSentinel(); - toolPathSentinel = new NoOpFileSentinel(); + toolPathSentinel = new NoOpFileSentinel(exists: false); hasSuperUserAccess = true; } diff --git a/test/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs b/test/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs index bccc3c053..b554d528e 100644 --- a/test/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs +++ b/test/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs @@ -6,6 +6,7 @@ using System.IO; using System.Collections.Generic; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli; +using Microsoft.DotNet.Configurer; using Microsoft.DotNet.TestFramework; using Microsoft.DotNet.Tools.Test.Utilities; using Xunit; @@ -193,6 +194,49 @@ namespace Microsoft.DotNet.Tests .ContainVisuallySameFragment(Configurer.LocalizableStrings.AspNetCertificateInstalled); } + [LinuxOnlyFact] + public void ItCreatesTheProfileFileOnLinuxWhenInvokedFromNativeInstaller() + { + var emptyHome = Path.Combine(_testDirectory, "empty_home"); + var profiled = Path.Combine(_testDirectory, "profile.d"); + + var command = new DotnetCommand().WithWorkingDirectory(_testDirectory); + command.Environment["HOME"] = emptyHome; + command.Environment["USERPROFILE"] = emptyHome; + command.Environment["APPDATA"] = emptyHome; + command.Environment["DOTNET_CLI_TEST_FALLBACKFOLDER"] = _nugetFallbackFolder.FullName; + command.Environment["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = ""; + command.Environment["DOTNET_CLI_TEST_LINUX_PROFILED_PATH"] = profiled; + command.Environment["DOTNET_DISABLE_MULTICOREJIT"] = "true"; + command.Environment["SkipInvalidConfigurations"] = "true"; + command.ExecuteWithCapturedOutput("internal-reportinstallsuccess test").Should().Pass(); + + File.Exists(profiled).Should().BeTrue(); + File.ReadAllText(profiled).Should().Be( + $"export PATH=\"$PATH:{new CliFolderPathCalculator().ToolsShimPathInUnix.PathWithDollar}\""); + } + + [MacOsOnlyFact] + public void ItCreatesThePathDFileOnMacOSWhenInvokedFromNativeInstaller() + { + var emptyHome = Path.Combine(_testDirectory, "empty_home"); + var pathsd = Path.Combine(_testDirectory, "paths.d"); + + var command = new DotnetCommand().WithWorkingDirectory(_testDirectory); + command.Environment["HOME"] = emptyHome; + command.Environment["USERPROFILE"] = emptyHome; + command.Environment["APPDATA"] = emptyHome; + command.Environment["DOTNET_CLI_TEST_FALLBACKFOLDER"] = _nugetFallbackFolder.FullName; + command.Environment["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = ""; + command.Environment["DOTNET_CLI_TEST_OSX_PATHSD_PATH"] = pathsd; + command.Environment["DOTNET_DISABLE_MULTICOREJIT"] = "true"; + command.Environment["SkipInvalidConfigurations"] = "true"; + command.ExecuteWithCapturedOutput("internal-reportinstallsuccess test").Should().Pass(); + + File.Exists(pathsd).Should().BeTrue(); + File.ReadAllText(pathsd).Should().Be(new CliFolderPathCalculator().ToolsShimPathInUnix.PathWithTilde); + } + [Fact] public void ItRestoresTheNuGetPackagesToTheNuGetCacheFolder() {