dotnet6.0/dotnet-pull10652.patch
2021-03-19 20:37:30 +03:00

104 lines
4.3 KiB
Diff
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

From 49891b96c12567109d6086a23ca7c117dd40bdc7 Mon Sep 17 00:00:00 2001
From: sfoslund <sfoslund@microsoft.com>
Date: Fri, 14 Feb 2020 15:05:24 -0800
Subject: [PATCH] Resolving and adding test coverage for stack dump on dotnet
-d
---
.../LocalToolsCommandResolver.cs | 3 +-
src/Cli/dotnet/Program.cs | 4 +++
.../GivenALocalToolsCommandResolver.cs | 13 ++++++++
.../CommandTests/CommandIntegrationTests.cs | 31 +++++++++++++++++++
4 files changed, 50 insertions(+), 1 deletion(-)
create mode 100644 src/Tests/dotnet.Tests/CommandTests/CommandIntegrationTests.cs
diff --git a/src/dotnet/CommandFactory/CommandResolution/LocalToolsCommandResolver.cs b/src/dotnet/CommandFactory/CommandResolution/LocalToolsCommandResolver.cs
index fae180cbde..59af704755 100644
--- a/src/dotnet/CommandFactory/CommandResolution/LocalToolsCommandResolver.cs
+++ b/src/dotnet/CommandFactory/CommandResolution/LocalToolsCommandResolver.cs
@@ -57,7 +57,8 @@ public CommandSpec Resolve(CommandResolverArguments arguments)
return null;
}
- if (!arguments.CommandName.StartsWith(LeadingDotnetPrefix, StringComparison.OrdinalIgnoreCase))
+ if (!arguments.CommandName.StartsWith(LeadingDotnetPrefix, StringComparison.OrdinalIgnoreCase) ||
+ string.IsNullOrWhiteSpace(arguments.CommandName.Substring(LeadingDotnetPrefix.Length)))
{
return null;
}
diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs
index 8b9cccfe0b..67e784bbf3 100644
--- a/src/dotnet/Program.cs
+++ b/src/dotnet/Program.cs
@@ -216,6 +216,10 @@ internal static int ProcessArgs(string[] args, ITelemetry telemetryClient = null
exitCode = builtIn.Command(appArgs.ToArray());
}
+ else if (string.IsNullOrEmpty(topLevelCommandParserResult.Command))
+ {
+ exitCode = 0;
+ }
else
{
CommandResult result = CommandFactoryUsingResolver.Create(
diff --git a/test/Microsoft.DotNet.CommandFactory.Tests/GivenALocalToolsCommandResolver.cs b/test/Microsoft.DotNet.CommandFactory.Tests/GivenALocalToolsCommandResolver.cs
index 4235f2055e..07bd774c97 100644
--- a/test/Microsoft.DotNet.CommandFactory.Tests/GivenALocalToolsCommandResolver.cs
+++ b/test/Microsoft.DotNet.CommandFactory.Tests/GivenALocalToolsCommandResolver.cs
@@ -79,6 +79,19 @@ public void WhenResolveItCanFindToolExecutable(string toolCommand)
commandPath.Should().Be(fakeExecutable.Value);
}
+ [Fact]
+ public void WhenResolveWithNoArgumentsItReturnsNull()
+ {
+ (FilePath fakeExecutable, LocalToolsCommandResolver localToolsCommandResolver) = DefaultSetup("-d");
+
+ var result = localToolsCommandResolver.Resolve(new CommandResolverArguments()
+ {
+ CommandName = "-d",
+ });
+
+ result.Should().BeNull();
+ }
+
private (FilePath, LocalToolsCommandResolver) DefaultSetup(string toolCommand)
{
NuGetVersion packageVersionA = NuGetVersion.Parse("1.0.4");
diff --git a/test/dotnet.Tests/CommandTests/CommandIntegrationTests.cs b/test/dotnet.Tests/CommandTests/CommandIntegrationTests.cs
new file mode 100644
index 0000000000..30e5bfdbb7
--- /dev/null
+++ b/test/dotnet.Tests/CommandTests/CommandIntegrationTests.cs
@@ -0,0 +1,31 @@
+// 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 FluentAssertions;
+using Microsoft.NET.TestFramework;
+using Microsoft.NET.TestFramework.Commands;
+using Xunit;
+using Xunit.Abstractions;
+
+namespace Microsoft.DotNet.Tests.Commands
+{
+ public class CommandIntegrationTests : SdkTest
+ {
+ public CommandIntegrationTests(ITestOutputHelper log) : base(log) {}
+
+ [Fact]
+ public void GivenNoArgumentsProvided()
+ {
+ var cmd = new DotnetCommand(Log).Execute(string.Empty);
+ cmd.StdErr.Should().BeEmpty();
+ }
+
+ [Fact]
+ public void GivenOnlyArgumentProvidedIsDiagnosticsFlag()
+ {
+ var cmd = new DotnetCommand(Log).Execute("-d");
+ cmd.ExitCode.Should().Be(0);
+ cmd.StdErr.Should().BeEmpty();
+ }
+ }
+}