From 0181c67bb0798bcf826c4d25602c1ef06d686965 Mon Sep 17 00:00:00 2001 From: Peter Huene Date: Tue, 3 Apr 2018 13:53:55 -0700 Subject: [PATCH] Fix validation of tool-path option for tool list and uninstall commands. This commit checks that the `--tool-path` option for the `tool list` and `tool uninstall` commands is a directory that exists. If the directory does not exist, an error and the command help is displayed. Fixes #8931. --- .../dotnet-tool/list/LocalizableStrings.resx | 3 ++ .../dotnet-tool/list/ToolListCommand.cs | 9 ++++ .../list/xlf/LocalizableStrings.cs.xlf | 5 ++ .../list/xlf/LocalizableStrings.de.xlf | 5 ++ .../list/xlf/LocalizableStrings.es.xlf | 5 ++ .../list/xlf/LocalizableStrings.fr.xlf | 5 ++ .../list/xlf/LocalizableStrings.it.xlf | 5 ++ .../list/xlf/LocalizableStrings.ja.xlf | 5 ++ .../list/xlf/LocalizableStrings.ko.xlf | 5 ++ .../list/xlf/LocalizableStrings.pl.xlf | 5 ++ .../list/xlf/LocalizableStrings.pt-BR.xlf | 5 ++ .../list/xlf/LocalizableStrings.ru.xlf | 5 ++ .../list/xlf/LocalizableStrings.tr.xlf | 5 ++ .../list/xlf/LocalizableStrings.zh-Hans.xlf | 5 ++ .../list/xlf/LocalizableStrings.zh-Hant.xlf | 5 ++ .../uninstall/LocalizableStrings.resx | 3 ++ .../uninstall/ToolUninstallCommand.cs | 24 ++++++--- .../uninstall/xlf/LocalizableStrings.cs.xlf | 5 ++ .../uninstall/xlf/LocalizableStrings.de.xlf | 5 ++ .../uninstall/xlf/LocalizableStrings.es.xlf | 5 ++ .../uninstall/xlf/LocalizableStrings.fr.xlf | 5 ++ .../uninstall/xlf/LocalizableStrings.it.xlf | 5 ++ .../uninstall/xlf/LocalizableStrings.ja.xlf | 5 ++ .../uninstall/xlf/LocalizableStrings.ko.xlf | 5 ++ .../uninstall/xlf/LocalizableStrings.pl.xlf | 5 ++ .../xlf/LocalizableStrings.pt-BR.xlf | 5 ++ .../uninstall/xlf/LocalizableStrings.ru.xlf | 5 ++ .../uninstall/xlf/LocalizableStrings.tr.xlf | 5 ++ .../xlf/LocalizableStrings.zh-Hans.xlf | 5 ++ .../xlf/LocalizableStrings.zh-Hant.xlf | 5 ++ .../CommandTests/ToolListCommandTests.cs | 26 +++++++++- .../CommandTests/ToolUninstallCommandTests.cs | 49 ++++++++++++++----- 32 files changed, 221 insertions(+), 23 deletions(-) diff --git a/src/dotnet/commands/dotnet-tool/list/LocalizableStrings.resx b/src/dotnet/commands/dotnet-tool/list/LocalizableStrings.resx index 852ca839b..0ae133e98 100644 --- a/src/dotnet/commands/dotnet-tool/list/LocalizableStrings.resx +++ b/src/dotnet/commands/dotnet-tool/list/LocalizableStrings.resx @@ -144,4 +144,7 @@ Commands + + Tool path '{0}' does not exist. + diff --git a/src/dotnet/commands/dotnet-tool/list/ToolListCommand.cs b/src/dotnet/commands/dotnet-tool/list/ToolListCommand.cs index df7616089..ca899c047 100644 --- a/src/dotnet/commands/dotnet-tool/list/ToolListCommand.cs +++ b/src/dotnet/commands/dotnet-tool/list/ToolListCommand.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.CommandLine; @@ -44,6 +45,14 @@ namespace Microsoft.DotNet.Tools.Tool.List DirectoryPath? toolPath = null; if (!string.IsNullOrWhiteSpace(toolPathOption)) { + if (!Directory.Exists(toolPathOption)) + { + throw new GracefulException( + string.Format( + LocalizableStrings.InvalidToolPathOption, + toolPathOption)); + } + toolPath = new DirectoryPath(toolPathOption); } diff --git a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.cs.xlf b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.cs.xlf index 2885762cc..6538e2d55 100644 --- a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.cs.xlf +++ b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.cs.xlf @@ -47,6 +47,11 @@ (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.de.xlf b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.de.xlf index 9eabad841..605712c16 100644 --- a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.de.xlf +++ b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.de.xlf @@ -47,6 +47,11 @@ (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.es.xlf b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.es.xlf index 2db3a8d08..db3185239 100644 --- a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.es.xlf +++ b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.es.xlf @@ -47,6 +47,11 @@ (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.fr.xlf b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.fr.xlf index c0beb0fef..a08c785e7 100644 --- a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.fr.xlf +++ b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.fr.xlf @@ -47,6 +47,11 @@ (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.it.xlf b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.it.xlf index 28e1a3014..d34aa319c 100644 --- a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.it.xlf +++ b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.it.xlf @@ -47,6 +47,11 @@ (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.ja.xlf b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.ja.xlf index b0e1114dc..cfce0ea6e 100644 --- a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.ja.xlf +++ b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.ja.xlf @@ -47,6 +47,11 @@ (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.ko.xlf b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.ko.xlf index 5829435dc..920f07070 100644 --- a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.ko.xlf +++ b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.ko.xlf @@ -47,6 +47,11 @@ (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.pl.xlf b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.pl.xlf index c6a02e125..17adc3e99 100644 --- a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.pl.xlf +++ b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.pl.xlf @@ -47,6 +47,11 @@ (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.pt-BR.xlf b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.pt-BR.xlf index e26992927..bbedbc460 100644 --- a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.pt-BR.xlf +++ b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.pt-BR.xlf @@ -47,6 +47,11 @@ (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.ru.xlf b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.ru.xlf index d8b7343e4..48fda0f94 100644 --- a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.ru.xlf +++ b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.ru.xlf @@ -47,6 +47,11 @@ (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.tr.xlf b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.tr.xlf index 0eca3acac..3827babc4 100644 --- a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.tr.xlf +++ b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.tr.xlf @@ -47,6 +47,11 @@ (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.zh-Hans.xlf b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.zh-Hans.xlf index 34e56573d..820dd0180 100644 --- a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.zh-Hans.xlf +++ b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.zh-Hans.xlf @@ -47,6 +47,11 @@ (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.zh-Hant.xlf b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.zh-Hant.xlf index 395b10be6..fe820253d 100644 --- a/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.zh-Hant.xlf +++ b/src/dotnet/commands/dotnet-tool/list/xlf/LocalizableStrings.zh-Hant.xlf @@ -47,6 +47,11 @@ (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/uninstall/LocalizableStrings.resx b/src/dotnet/commands/dotnet-tool/uninstall/LocalizableStrings.resx index a077fd0f8..226deca13 100644 --- a/src/dotnet/commands/dotnet-tool/uninstall/LocalizableStrings.resx +++ b/src/dotnet/commands/dotnet-tool/uninstall/LocalizableStrings.resx @@ -153,4 +153,7 @@ (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + Tool path '{0}' does not exist. + diff --git a/src/dotnet/commands/dotnet-tool/uninstall/ToolUninstallCommand.cs b/src/dotnet/commands/dotnet-tool/uninstall/ToolUninstallCommand.cs index 3347895e2..a559a644f 100644 --- a/src/dotnet/commands/dotnet-tool/uninstall/ToolUninstallCommand.cs +++ b/src/dotnet/commands/dotnet-tool/uninstall/ToolUninstallCommand.cs @@ -49,22 +49,30 @@ namespace Microsoft.DotNet.Tools.Tool.Uninstall var global = _options.ValueOrDefault("global"); var toolPath = _options.SingleArgumentOrDefault("tool-path"); - if (string.IsNullOrWhiteSpace(toolPath) && !global) + DirectoryPath? toolDirectoryPath = null; + if (!string.IsNullOrWhiteSpace(toolPath)) + { + if (!Directory.Exists(toolPath)) + { + throw new GracefulException( + string.Format( + LocalizableStrings.InvalidToolPathOption, + toolPath)); + } + + toolDirectoryPath = new DirectoryPath(toolPath); + } + + if (toolDirectoryPath == null && !global) { throw new GracefulException(LocalizableStrings.UninstallToolCommandNeedGlobalOrToolPath); } - if (!string.IsNullOrWhiteSpace(toolPath) && global) + if (toolDirectoryPath != null && global) { throw new GracefulException(LocalizableStrings.UninstallToolCommandInvalidGlobalAndToolPath); } - DirectoryPath? toolDirectoryPath = null; - if (!string.IsNullOrWhiteSpace(toolPath)) - { - toolDirectoryPath = new DirectoryPath(toolPath); - } - IToolPackageStore toolPackageStore = _createToolPackageStore(toolDirectoryPath); IShellShimRepository shellShimRepository = _createShellShimRepository(toolDirectoryPath); diff --git a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.cs.xlf b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.cs.xlf index a43c7063a..38a4243e3 100644 --- a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.cs.xlf +++ b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.cs.xlf @@ -62,6 +62,11 @@ Globální cesta a cesta k nástroji nemůžou být zadané současně. + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.de.xlf b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.de.xlf index f1b63122f..23e7ac66c 100644 --- a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.de.xlf +++ b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.de.xlf @@ -62,6 +62,11 @@ Die gleichzeitige Angabe von "global" und "tool-path" ist nicht möglich. + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.es.xlf b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.es.xlf index 0f64e95e5..5b67b28f9 100644 --- a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.es.xlf +++ b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.es.xlf @@ -62,6 +62,11 @@ No puede tener una ruta global y de herramienta como opinión al mismo tiempo." + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.fr.xlf b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.fr.xlf index 4cd67ae0a..e77c08f47 100644 --- a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.fr.xlf +++ b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.fr.xlf @@ -62,6 +62,11 @@ Impossible d'avoir une propriété opinion avec les paramètres global et tool-path en même temps." + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.it.xlf b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.it.xlf index 20cc84342..194300a65 100644 --- a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.it.xlf +++ b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.it.xlf @@ -62,6 +62,11 @@ Non è possibile specificare contemporaneamente global e tool-path come opzione." + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.ja.xlf b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.ja.xlf index 1ed94e4dd..08428d0f5 100644 --- a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.ja.xlf +++ b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.ja.xlf @@ -62,6 +62,11 @@ global と tool-path を意見として同時に指定することはできません。" + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.ko.xlf b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.ko.xlf index 5384141e0..1e905c485 100644 --- a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.ko.xlf +++ b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.ko.xlf @@ -62,6 +62,11 @@ 전역 및 도구 경로를 의견으로 동시에 사용할 수 없습니다." + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.pl.xlf b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.pl.xlf index d06a3abe9..31c2ed816 100644 --- a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.pl.xlf +++ b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.pl.xlf @@ -62,6 +62,11 @@ Nie można jednocześnie używać ścieżki globalnej i ścieżki narzędzia jako opinii. + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.pt-BR.xlf b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.pt-BR.xlf index 82a487078..e2b3b574b 100644 --- a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.pt-BR.xlf +++ b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.pt-BR.xlf @@ -62,6 +62,11 @@ Não é possível ter o caminho de ferramenta e o global como opinião ao mesmo tempo." + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.ru.xlf b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.ru.xlf index 0e1bfe321..0117b857d 100644 --- a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.ru.xlf +++ b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.ru.xlf @@ -62,6 +62,11 @@ Невозможно указать глобальный параметр и параметр tool-path в качестве оценки одновременно. + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.tr.xlf b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.tr.xlf index d57c84ab4..67781f177 100644 --- a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.tr.xlf +++ b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.tr.xlf @@ -62,6 +62,11 @@ Fikir olarak aynı anda hem genel yol hem de araç yolu kullanılamaz.” + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.zh-Hans.xlf b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.zh-Hans.xlf index 86f92fae5..3ae996650 100644 --- a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.zh-Hans.xlf +++ b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.zh-Hans.xlf @@ -62,6 +62,11 @@ 无法同时主张全局和工具路径。” + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.zh-Hant.xlf b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.zh-Hant.xlf index a0d7000d7..540670d07 100644 --- a/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.zh-Hant.xlf +++ b/src/dotnet/commands/dotnet-tool/uninstall/xlf/LocalizableStrings.zh-Hant.xlf @@ -62,6 +62,11 @@ 無法同時將全域與工具路徑作為選項。」 + + Tool path '{0}' does not exist. + Tool path '{0}' does not exist. + + \ No newline at end of file diff --git a/test/dotnet.Tests/CommandTests/ToolListCommandTests.cs b/test/dotnet.Tests/CommandTests/ToolListCommandTests.cs index d7aca4c96..57acbd87e 100644 --- a/test/dotnet.Tests/CommandTests/ToolListCommandTests.cs +++ b/test/dotnet.Tests/CommandTests/ToolListCommandTests.cs @@ -55,7 +55,8 @@ namespace Microsoft.DotNet.Tests.Commands { var store = new Mock(MockBehavior.Strict); - var command = CreateCommand(store.Object, "-g --tool-path /tools", "/tools"); + var toolPath = Path.GetTempPath(); + var command = CreateCommand(store.Object, $"-g --tool-path {toolPath}", toolPath); Action a = () => { command.Execute(); @@ -83,6 +84,26 @@ namespace Microsoft.DotNet.Tests.Commands _reporter.Lines.Should().Equal(EnumerateExpectedTableLines(store.Object)); } + [Fact] + public void GivenAnInvalidToolPathItThrowsException() + { + var store = new Mock(MockBehavior.Strict); + store + .Setup(s => s.EnumeratePackages()) + .Returns(new IToolPackage[0]); + + var toolPath = "tool-path-does-not-exist"; + var command = CreateCommand(store.Object, $"--tool-path {toolPath}", toolPath); + + Action a = () => command.Execute(); + + a.ShouldThrow() + .And + .Message + .Should() + .Be(string.Format(LocalizableStrings.InvalidToolPathOption, toolPath)); + } + [Fact] public void GivenAToolPathItPassesToolPathToStoreFactory() { @@ -91,7 +112,8 @@ namespace Microsoft.DotNet.Tests.Commands .Setup(s => s.EnumeratePackages()) .Returns(new IToolPackage[0]); - var command = CreateCommand(store.Object, "--tool-path /tools", "/tools"); + var toolPath = Path.GetTempPath(); + var command = CreateCommand(store.Object, $"--tool-path {toolPath}", toolPath); command.Execute().Should().Be(0); diff --git a/test/dotnet.Tests/CommandTests/ToolUninstallCommandTests.cs b/test/dotnet.Tests/CommandTests/ToolUninstallCommandTests.cs index a9440f0d8..2e47036ac 100644 --- a/test/dotnet.Tests/CommandTests/ToolUninstallCommandTests.cs +++ b/test/dotnet.Tests/CommandTests/ToolUninstallCommandTests.cs @@ -51,11 +51,11 @@ namespace Microsoft.DotNet.Tests.Commands Action a = () => command.Execute(); - a.ShouldThrow().And.Message - .Should().Contain( - string.Format( - LocalizableStrings.ToolNotInstalled, - packageId)); + a.ShouldThrow() + .And + .Message + .Should() + .Be(string.Format(LocalizableStrings.ToolNotInstalled, packageId)); } [Fact] @@ -131,9 +131,10 @@ namespace Microsoft.DotNet.Tests.Commands .Execute(); a.ShouldThrow() - .And.Message - .Should().Contain( - string.Format( + .And + .Message + .Should() + .Be(string.Format( CommonLocalizableStrings.FailedToUninstallToolPackage, PackageId, "simulated error")); @@ -145,12 +146,31 @@ namespace Microsoft.DotNet.Tests.Commands [Fact] public void WhenRunWithBothGlobalAndToolPathShowErrorMessage() { - var uninstallCommand = CreateUninstallCommand($"-g --tool-path /tmp/folder {PackageId}"); + var uninstallCommand = CreateUninstallCommand($"-g --tool-path {Path.GetTempPath()} {PackageId}"); Action a = () => uninstallCommand.Execute(); - a.ShouldThrow().And.Message - .Should().Contain(LocalizableStrings.UninstallToolCommandInvalidGlobalAndToolPath); + a.ShouldThrow() + .And + .Message + .Should() + .Be(LocalizableStrings.UninstallToolCommandInvalidGlobalAndToolPath); + } + + [Fact] + public void GivenAnInvalidToolPathItThrowsException() + { + var toolPath = "tool-path-does-not-exist"; + + var uninstallCommand = CreateUninstallCommand($"--tool-path {toolPath} {PackageId}"); + + Action a = () => uninstallCommand.Execute(); + + a.ShouldThrow() + .And + .Message + .Should() + .Be(string.Format(LocalizableStrings.InvalidToolPathOption, toolPath)); } [Fact] @@ -160,8 +180,11 @@ namespace Microsoft.DotNet.Tests.Commands Action a = () => uninstallCommand.Execute(); - a.ShouldThrow().And.Message - .Should().Contain(LocalizableStrings.UninstallToolCommandNeedGlobalOrToolPath); + a.ShouldThrow() + .And + .Message + .Should() + .Be(LocalizableStrings.UninstallToolCommandNeedGlobalOrToolPath); } private ToolInstallCommand CreateInstallCommand(string options)