From 61878615c204b92d619661e522350e0ab653e4df Mon Sep 17 00:00:00 2001 From: John Beisner Date: Wed, 10 Oct 2018 17:37:10 -0700 Subject: [PATCH] Updating the help messages; modifying tests. (dotnet/core-setup#4632) https://github.com/dotnet/core-setup/issues/3344 Commit migrated from https://github.com/dotnet/core-setup/commit/156e0c5feb3439998a2026059d67948a2fccfe6a --- src/installer/corehost/cli/fxr/fx_muxer.cpp | 6 +-- src/installer/corehost/cli/fxr/sdk_resolver.cpp | 12 +++-- .../GivenThatICareAboutMultilevelSDKLookup.cs | 62 +++++++++++++++++++--- 3 files changed, 67 insertions(+), 13 deletions(-) diff --git a/src/installer/corehost/cli/fxr/fx_muxer.cpp b/src/installer/corehost/cli/fxr/fx_muxer.cpp index fb40f30..51a3de8 100644 --- a/src/installer/corehost/cli/fxr/fx_muxer.cpp +++ b/src/installer/corehost/cli/fxr/fx_muxer.cpp @@ -1344,7 +1344,9 @@ int fx_muxer_t::handle_cli( { assert(argc > 1); if (pal::strcasecmp(_X("-h"), argv[1]) == 0 || - pal::strcasecmp(_X("--help"), argv[1]) == 0) + pal::strcasecmp(_X("--help"), argv[1]) == 0 || + pal::strcasecmp(_X("-?"), argv[1]) == 0 || + pal::strcasecmp(_X("/?"), argv[1]) == 0) { muxer_usage(false); return StatusCode::InvalidArgFailure; @@ -1355,8 +1357,6 @@ int fx_muxer_t::handle_cli( return StatusCode::Success; } - trace::error(_X("Did you mean to run dotnet SDK commands? Please install dotnet SDK from:")); - trace::error(_X(" %s"), DOTNET_CORE_GETTING_STARTED_URL); return StatusCode::LibHostSdkFindFailure; } diff --git a/src/installer/corehost/cli/fxr/sdk_resolver.cpp b/src/installer/corehost/cli/fxr/sdk_resolver.cpp index 86e01ea..399f76f 100644 --- a/src/installer/corehost/cli/fxr/sdk_resolver.cpp +++ b/src/installer/corehost/cli/fxr/sdk_resolver.cpp @@ -7,6 +7,7 @@ #include "fx_ver.h" #include "trace.h" #include "utils.h" +#include "sdk_info.h" typedef web::json::value json_value; typedef web::json::object json_object; @@ -272,13 +273,16 @@ bool sdk_resolver_t::resolve_sdk_dotnet_path( return true; } - if (global_cli_version.empty()) + if (!global_cli_version.empty()) { - trace::verbose(_X("It was not possible to find any SDK version")); + trace::error(_X("A compatible installed dotnet SDK for global.json version: [%s] from [%s] was not found"), global_cli_version.c_str(), global.c_str()); + trace::error(_X("Please install the [%s] SDK or update [%s] with an installed dotnet SDK:"), global_cli_version.c_str(), global.c_str()); } - else + if (global_cli_version.empty() || !sdk_info::print_all_sdks(dotnet_root, _X(" "))) { - trace::error(_X("A compatible SDK version for global.json version: [%s] from [%s] was not found"), global_cli_version.c_str(), global.c_str()); + trace::error(_X(" It was not possible to find any installed dotnet SDKs")); + trace::error(_X(" Did you mean to run dotnet SDK commands? Please install dotnet SDK from:")); + trace::error(_X(" %s"), DOTNET_CORE_GETTING_STARTED_URL); } return false; } diff --git a/src/installer/test/HostActivationTests/GivenThatICareAboutMultilevelSDKLookup.cs b/src/installer/test/HostActivationTests/GivenThatICareAboutMultilevelSDKLookup.cs index e3702b5..18a473d 100644 --- a/src/installer/test/HostActivationTests/GivenThatICareAboutMultilevelSDKLookup.cs +++ b/src/installer/test/HostActivationTests/GivenThatICareAboutMultilevelSDKLookup.cs @@ -122,6 +122,26 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSDKLookup // Set specified CLI version = 9999.3.4-global-dummy SetGlobalJsonVersion("SingleDigit-global.json"); + // Specified CLI version: 9999.3.4-global-dummy + // CWD: empty + // User: empty + // Exe: empty + // Expected: no compatible version and a specific error messages + dotnet.Exec("help") + .WorkingDirectory(_currentWorkingDir) + .WithUserProfile(_userDir) + .Environment(s_DefaultEnvironment) + .EnvironmentVariable("DOTNET_MULTILEVEL_LOOKUP", "0") + .CaptureStdOut() + .CaptureStdErr() + .Execute(fExpectedToFail: true) + .Should() + .Fail() + .And + .HaveStdErrContaining("A compatible installed dotnet SDK for global.json version") + .And + .HaveStdErrContaining("It was not possible to find any installed dotnet SDKs"); + // Add some dummy versions AddAvailableSdkVersions(_exeSdkBaseDir, "9999.4.1", "9999.3.4-dummy"); @@ -141,7 +161,9 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSDKLookup .Should() .Fail() .And - .HaveStdErrContaining("A compatible SDK version for global.json version"); + .HaveStdErrContaining("A compatible installed dotnet SDK for global.json version") + .And + .NotHaveStdErrContaining("It was not possible to find any installed dotnet SDKs"); // Add specified CLI version AddAvailableSdkVersions(_exeSdkBaseDir, "9999.3.3"); @@ -162,7 +184,9 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSDKLookup .Should() .Fail() .And - .HaveStdErrContaining("A compatible SDK version for global.json version"); + .HaveStdErrContaining("A compatible installed dotnet SDK for global.json version") + .And + .NotHaveStdErrContaining("It was not possible to find any installed dotnet SDKs"); // Add specified CLI version AddAvailableSdkVersions(_exeSdkBaseDir, "9999.3.4"); @@ -284,6 +308,26 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSDKLookup // Set specified CLI version = 9999.3.304-global-dummy SetGlobalJsonVersion("TwoPart-global.json"); + // Specified CLI version: 9999.3.304-global-dummy + // CWD: empty + // User: empty + // Exe: empty + // Expected: no compatible version and a specific error messages + dotnet.Exec("help") + .WorkingDirectory(_currentWorkingDir) + .WithUserProfile(_userDir) + .Environment(s_DefaultEnvironment) + .EnvironmentVariable("DOTNET_MULTILEVEL_LOOKUP", "0") + .CaptureStdOut() + .CaptureStdErr() + .Execute(fExpectedToFail: true) + .Should() + .Fail() + .And + .HaveStdErrContaining("A compatible installed dotnet SDK for global.json version") + .And + .HaveStdErrContaining("It was not possible to find any installed dotnet SDKs"); + // Add some dummy versions AddAvailableSdkVersions(_exeSdkBaseDir, "9999.3.57", "9999.3.4-dummy"); @@ -303,7 +347,9 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSDKLookup .Should() .Fail() .And - .HaveStdErrContaining("A compatible SDK version for global.json version"); + .HaveStdErrContaining("A compatible installed dotnet SDK for global.json version") + .And + .NotHaveStdErrContaining("It was not possible to find any installed dotnet SDKs"); // Add specified CLI version AddAvailableSdkVersions(_exeSdkBaseDir, "9999.3.300", "9999.7.304-global-dummy"); @@ -324,7 +370,9 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSDKLookup .Should() .Fail() .And - .HaveStdErrContaining("A compatible SDK version for global.json version"); + .HaveStdErrContaining("A compatible installed dotnet SDK for global.json version") + .And + .NotHaveStdErrContaining("It was not possible to find any installed dotnet SDKs"); // Add specified CLI version AddAvailableSdkVersions(_exeSdkBaseDir, "9999.3.304"); @@ -458,7 +506,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSDKLookup // CWD: empty // User: empty // Exe: -1.-1.-1 - // Expected: no compatible version and a specific error message + // Expected: no compatible version and a specific error messages dotnet.Exec("help") .WorkingDirectory(_currentWorkingDir) .WithUserProfile(_userDir) @@ -470,7 +518,9 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSDKLookup .Should() .Fail() .And - .HaveStdErrContaining("It was not possible to find any SDK version"); + .HaveStdErrContaining("It was not possible to find any installed dotnet SDKs") + .And + .HaveStdErrContaining("Did you mean to run dotnet SDK commands? Please install dotnet SDK from"); // Add specified CLI version AddAvailableSdkVersions(_exeSdkBaseDir, "9999.0.4"); -- 2.7.4