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 System.Collections.Generic;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
using FluentAssertions;
|
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;
|
|
|
|
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 LinuxEnvironmentPathTests
|
|
|
|
{
|
|
|
|
[Fact]
|
|
|
|
public void GivenEnvironmentAndReporterItCanPrintOutInstructionToAddPath()
|
|
|
|
{
|
2018-01-18 03:26:52 +00:00
|
|
|
var reporter = new BufferedReporter();
|
2017-11-27 18:45:43 +00:00
|
|
|
var linuxEnvironmentPath = new LinuxEnvironmentPath(
|
2017-12-04 22:13:24 +00:00
|
|
|
new BashPathUnderHomeDirectory("/myhome", "executable/path"),
|
2018-01-18 03:26:52 +00:00
|
|
|
reporter,
|
2017-11-27 18:45:43 +00:00
|
|
|
new FakeEnvironmentProvider(
|
|
|
|
new Dictionary<string, string>
|
|
|
|
{
|
|
|
|
{"PATH", ""}
|
|
|
|
}),
|
|
|
|
FakeFile.Empty);
|
|
|
|
|
|
|
|
linuxEnvironmentPath.PrintAddPathInstructionIfPathDoesNotExist();
|
|
|
|
|
|
|
|
// similar to https://code.visualstudio.com/docs/setup/mac
|
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.EnvironmentPathLinuxManualInstructions,
|
|
|
|
"/myhome/executable/path"));
|
2017-11-27 18:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void GivenEnvironmentAndReporterItPrintsNothingWhenenvironmentExists()
|
|
|
|
{
|
2018-01-18 03:26:52 +00:00
|
|
|
var reporter = new BufferedReporter();
|
2017-11-27 18:45:43 +00:00
|
|
|
var linuxEnvironmentPath = new LinuxEnvironmentPath(
|
2017-12-04 22:13:24 +00:00
|
|
|
new BashPathUnderHomeDirectory("/myhome", "executable/path"),
|
2018-01-18 03:26:52 +00:00
|
|
|
reporter,
|
2017-11-27 18:45:43 +00:00
|
|
|
new FakeEnvironmentProvider(
|
|
|
|
new Dictionary<string, string>
|
|
|
|
{
|
2017-12-04 22:13:24 +00:00
|
|
|
{"PATH", @"/myhome/executable/path"}
|
2017-11-27 18:45:43 +00:00
|
|
|
}),
|
|
|
|
FakeFile.Empty);
|
|
|
|
|
|
|
|
linuxEnvironmentPath.PrintAddPathInstructionIfPathDoesNotExist();
|
|
|
|
|
2018-01-18 03:26:52 +00:00
|
|
|
reporter.Lines.Should().BeEmpty();
|
2017-11-27 18:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void GivenAddPackageExecutablePathToUserPathJustRunItPrintsInstructionToLogout()
|
|
|
|
{
|
2018-01-18 03:26:52 +00:00
|
|
|
var reporter = new BufferedReporter();
|
2017-11-27 18:45:43 +00:00
|
|
|
var linuxEnvironmentPath = new LinuxEnvironmentPath(
|
2017-12-04 22:13:24 +00:00
|
|
|
new BashPathUnderHomeDirectory("/myhome", "executable/path"),
|
2018-01-18 03:26:52 +00:00
|
|
|
reporter,
|
2017-11-27 18:45:43 +00:00
|
|
|
new FakeEnvironmentProvider(
|
|
|
|
new Dictionary<string, string>
|
|
|
|
{
|
|
|
|
{"PATH", @""}
|
|
|
|
}),
|
|
|
|
FakeFile.Empty);
|
|
|
|
linuxEnvironmentPath.AddPackageExecutablePathToUserPath();
|
|
|
|
|
|
|
|
linuxEnvironmentPath.PrintAddPathInstructionIfPathDoesNotExist();
|
|
|
|
|
2018-01-18 03:26:52 +00:00
|
|
|
reporter.Lines.Should()
|
|
|
|
.Equal(CommonLocalizableStrings.EnvironmentPathLinuxNeedLogout);
|
2017-11-27 18:45:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|