2017-11-27 18:45:43 +00:00
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using FluentAssertions;
|
2018-03-23 19:40:58 +00:00
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
2017-12-04 22:13:24 +00:00
|
|
|
using Microsoft.DotNet.Configurer;
|
2018-01-13 17:40:48 +00:00
|
|
|
using Microsoft.DotNet.Tools;
|
2017-11-27 18:45:43 +00:00
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
using Microsoft.Extensions.DependencyModel.Tests;
|
2018-03-23 19:40:58 +00:00
|
|
|
using Moq;
|
2017-11-27 18:45:43 +00:00
|
|
|
using Xunit;
|
|
|
|
|
2017-12-04 22:13:24 +00:00
|
|
|
namespace Microsoft.DotNet.ShellShim.Tests
|
2017-11-27 18:45:43 +00:00
|
|
|
{
|
|
|
|
public class OsxEnvironmentPathTests
|
|
|
|
{
|
|
|
|
[Fact]
|
2018-03-23 19:40:58 +00:00
|
|
|
public void GivenPathNotSetItPrintsManualInstructions()
|
2017-11-27 18:45:43 +00:00
|
|
|
{
|
2018-01-18 03:26:52 +00:00
|
|
|
var reporter = new BufferedReporter();
|
2018-03-23 19:40:58 +00:00
|
|
|
var toolsPath = new BashPathUnderHomeDirectory("/home/user", ".dotnet/tools");
|
|
|
|
var pathValue = @"/usr/bin";
|
|
|
|
var provider = new Mock<IEnvironmentProvider>(MockBehavior.Strict);
|
|
|
|
|
|
|
|
provider
|
|
|
|
.Setup(p => p.GetEnvironmentVariable("PATH"))
|
|
|
|
.Returns(pathValue);
|
|
|
|
|
|
|
|
var environmentPath = new OSXEnvironmentPath(
|
|
|
|
toolsPath,
|
2018-01-18 03:26:52 +00:00
|
|
|
reporter,
|
2018-03-23 19:40:58 +00:00
|
|
|
provider.Object,
|
|
|
|
FileSystemMockBuilder.Empty.File);
|
2017-11-27 18:45:43 +00:00
|
|
|
|
2018-03-23 19:40:58 +00:00
|
|
|
environmentPath.PrintAddPathInstructionIfPathDoesNotExist();
|
2017-11-27 18:45:43 +00:00
|
|
|
|
2018-01-18 03:26:52 +00:00
|
|
|
reporter.Lines.Should().Equal(
|
2018-01-13 17:40:48 +00:00
|
|
|
string.Format(
|
2018-01-28 21:35:04 +00:00
|
|
|
CommonLocalizableStrings.EnvironmentPathOSXManualInstructions,
|
2018-03-23 19:40:58 +00:00
|
|
|
toolsPath.Path));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void GivenPathNotSetAndProfileExistsItPrintsReopenMessage()
|
|
|
|
{
|
|
|
|
var reporter = new BufferedReporter();
|
|
|
|
var toolsPath = new BashPathUnderHomeDirectory("/home/user", ".dotnet/tools");
|
|
|
|
var pathValue = @"/usr/bin";
|
|
|
|
var provider = new Mock<IEnvironmentProvider>(MockBehavior.Strict);
|
|
|
|
|
|
|
|
provider
|
|
|
|
.Setup(p => p.GetEnvironmentVariable("PATH"))
|
|
|
|
.Returns(pathValue);
|
|
|
|
|
|
|
|
var environmentPath = new OSXEnvironmentPath(
|
|
|
|
toolsPath,
|
|
|
|
reporter,
|
|
|
|
provider.Object,
|
|
|
|
new FileSystemMockBuilder()
|
|
|
|
.AddFile(OSXEnvironmentPath.DotnetCliToolsPathsDPath, "")
|
|
|
|
.Build()
|
|
|
|
.File);
|
|
|
|
|
|
|
|
environmentPath.PrintAddPathInstructionIfPathDoesNotExist();
|
|
|
|
|
|
|
|
reporter.Lines.Should().Equal(CommonLocalizableStrings.EnvironmentPathOSXNeedReopen);
|
2017-11-27 18:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Theory]
|
2018-03-23 19:40:58 +00:00
|
|
|
[InlineData("/home/user/.dotnet/tools")]
|
|
|
|
[InlineData("~/.dotnet/tools")]
|
|
|
|
public void GivenPathSetItPrintsNothing(string toolsDiretoryOnPath)
|
|
|
|
{
|
|
|
|
var reporter = new BufferedReporter();
|
|
|
|
var toolsPath = new BashPathUnderHomeDirectory("/home/user", ".dotnet/tools");
|
|
|
|
var pathValue = @"/usr/bin";
|
|
|
|
var provider = new Mock<IEnvironmentProvider>(MockBehavior.Strict);
|
|
|
|
|
|
|
|
provider
|
|
|
|
.Setup(p => p.GetEnvironmentVariable("PATH"))
|
|
|
|
.Returns(pathValue + ":" + toolsDiretoryOnPath);
|
|
|
|
|
|
|
|
var environmentPath = new OSXEnvironmentPath(
|
|
|
|
toolsPath,
|
|
|
|
reporter,
|
|
|
|
provider.Object,
|
|
|
|
FileSystemMockBuilder.Empty.File);
|
|
|
|
|
|
|
|
environmentPath.PrintAddPathInstructionIfPathDoesNotExist();
|
|
|
|
|
|
|
|
reporter.Lines.Should().BeEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void GivenPathSetItDoesNotAddPathToEnvironment()
|
2017-11-27 18:45:43 +00:00
|
|
|
{
|
2018-01-18 03:26:52 +00:00
|
|
|
var reporter = new BufferedReporter();
|
2018-03-23 19:40:58 +00:00
|
|
|
var toolsPath = new BashPathUnderHomeDirectory("/home/user", ".dotnet/tools");
|
|
|
|
var pathValue = @"/usr/bin";
|
|
|
|
var provider = new Mock<IEnvironmentProvider>(MockBehavior.Strict);
|
|
|
|
var fileSystem = new FileSystemMockBuilder().Build().File;
|
|
|
|
|
|
|
|
provider
|
|
|
|
.Setup(p => p.GetEnvironmentVariable("PATH"))
|
|
|
|
.Returns(pathValue + ":" + toolsPath.Path);
|
|
|
|
|
|
|
|
var environmentPath = new OSXEnvironmentPath(
|
|
|
|
toolsPath,
|
2018-01-18 03:26:52 +00:00
|
|
|
reporter,
|
2018-03-23 19:40:58 +00:00
|
|
|
provider.Object,
|
|
|
|
fileSystem);
|
2017-11-27 18:45:43 +00:00
|
|
|
|
2018-03-23 19:40:58 +00:00
|
|
|
environmentPath.AddPackageExecutablePathToUserPath();
|
2017-11-27 18:45:43 +00:00
|
|
|
|
2018-01-18 03:26:52 +00:00
|
|
|
reporter.Lines.Should().BeEmpty();
|
2018-03-23 19:40:58 +00:00
|
|
|
|
|
|
|
fileSystem
|
|
|
|
.Exists(OSXEnvironmentPath.DotnetCliToolsPathsDPath)
|
|
|
|
.Should()
|
|
|
|
.Be(false);
|
2017-11-27 18:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
2018-03-23 19:40:58 +00:00
|
|
|
public void GivenPathNotSetItAddsToEnvironment()
|
2017-11-27 18:45:43 +00:00
|
|
|
{
|
2018-01-18 03:26:52 +00:00
|
|
|
var reporter = new BufferedReporter();
|
2018-03-23 19:40:58 +00:00
|
|
|
var toolsPath = new BashPathUnderHomeDirectory("/home/user", ".dotnet/tools");
|
|
|
|
var pathValue = @"/usr/bin";
|
|
|
|
var provider = new Mock<IEnvironmentProvider>(MockBehavior.Strict);
|
|
|
|
var fileSystem = new FileSystemMockBuilder().Build().File;
|
|
|
|
|
|
|
|
provider
|
|
|
|
.Setup(p => p.GetEnvironmentVariable("PATH"))
|
|
|
|
.Returns(pathValue);
|
|
|
|
|
|
|
|
var environmentPath = new OSXEnvironmentPath(
|
|
|
|
toolsPath,
|
2018-01-18 03:26:52 +00:00
|
|
|
reporter,
|
2018-03-23 19:40:58 +00:00
|
|
|
provider.Object,
|
|
|
|
fileSystem);
|
2017-11-27 18:45:43 +00:00
|
|
|
|
2018-03-23 19:40:58 +00:00
|
|
|
environmentPath.AddPackageExecutablePathToUserPath();
|
2017-11-27 18:45:43 +00:00
|
|
|
|
2018-03-23 19:40:58 +00:00
|
|
|
reporter.Lines.Should().BeEmpty();
|
|
|
|
|
|
|
|
fileSystem
|
|
|
|
.ReadAllText(OSXEnvironmentPath.DotnetCliToolsPathsDPath)
|
|
|
|
.Should()
|
|
|
|
.Be(toolsPath.PathWithTilde);
|
2017-11-27 18:45:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|