Add unit tests for dotnet complete
.
This commit adds a few simple unit tests to cover the `dotnet complete` command. It only checks the top-level output, integration with the `new` command from the templating engine, and the custom `nuget` command parser that is solely intended for use with `dotnet complete`.
This commit is contained in:
parent
089d8bfc1b
commit
b24e9f4cec
2 changed files with 205 additions and 1 deletions
|
@ -12,6 +12,16 @@ namespace Microsoft.DotNet.Cli
|
|||
{
|
||||
public static int Run(string[] args)
|
||||
{
|
||||
return RunWithReporter(args, Reporter.Output);
|
||||
}
|
||||
|
||||
public static int RunWithReporter(string [] args, IReporter reporter)
|
||||
{
|
||||
if (reporter == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(reporter));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
DebugHelper.HandleDebugSwitch(ref args);
|
||||
|
@ -28,7 +38,7 @@ namespace Microsoft.DotNet.Cli
|
|||
|
||||
foreach (var suggestion in suggestions)
|
||||
{
|
||||
Console.WriteLine(suggestion);
|
||||
reporter.WriteLine(suggestion);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
|
|
194
test/dotnet.Tests/CommandTests/CompleteCommandTests.cs
Normal file
194
test/dotnet.Tests/CommandTests/CompleteCommandTests.cs
Normal file
|
@ -0,0 +1,194 @@
|
|||
// 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.IO;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.Cli;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.DotNet.Tests.Commands
|
||||
{
|
||||
public class CompleteCommandTests : TestBase
|
||||
{
|
||||
[Fact]
|
||||
public void GivenOnlyDotnetItSuggestsTopLevelCommandsAndOptions()
|
||||
{
|
||||
var expected = new string[] {
|
||||
"--diagnostics",
|
||||
"--help",
|
||||
"--info",
|
||||
"--list-runtimes",
|
||||
"--list-sdks",
|
||||
"--version",
|
||||
"-d",
|
||||
"-h",
|
||||
"add",
|
||||
"build",
|
||||
"build-server",
|
||||
"clean",
|
||||
"help",
|
||||
"list",
|
||||
"migrate",
|
||||
"msbuild",
|
||||
"new",
|
||||
"nuget",
|
||||
"pack",
|
||||
"publish",
|
||||
"remove",
|
||||
"restore",
|
||||
"run",
|
||||
"sln",
|
||||
"store",
|
||||
"test",
|
||||
"tool",
|
||||
"vstest"
|
||||
};
|
||||
|
||||
var reporter = new BufferedReporter();
|
||||
CompleteCommand.RunWithReporter(new[] { "dotnet " }, reporter).Should().Be(0);
|
||||
reporter.Lines.Should().Equal(expected.OrderBy(c => c));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GivenASlashItSuggestsTopLevelOptions()
|
||||
{
|
||||
var expected = new string[] {
|
||||
"--diagnostics",
|
||||
"--help",
|
||||
"--info",
|
||||
"--list-runtimes",
|
||||
"--list-sdks",
|
||||
"--version",
|
||||
"-d",
|
||||
"-h",
|
||||
"build-server" // This should be removed when completion is based on "starts with" rather than "contains".
|
||||
// See https://github.com/dotnet/cli/issues/8958.
|
||||
};
|
||||
|
||||
var reporter = new BufferedReporter();
|
||||
CompleteCommand.RunWithReporter(new[] { "dotnet -" }, reporter).Should().Be(0);
|
||||
reporter.Lines.Should().Equal(expected.OrderBy(c => c));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GivenNewCommandItDisplaysCompletions()
|
||||
{
|
||||
var expected = new string[] {
|
||||
"--force",
|
||||
"--help",
|
||||
"--install",
|
||||
"--language",
|
||||
"--list",
|
||||
"--name",
|
||||
"--nuget-source",
|
||||
"--output",
|
||||
"--type",
|
||||
"--uninstall",
|
||||
"-h",
|
||||
"-i",
|
||||
"-l",
|
||||
"-lang",
|
||||
"-n",
|
||||
"-o",
|
||||
"-u"
|
||||
};
|
||||
|
||||
var reporter = new BufferedReporter();
|
||||
CompleteCommand.RunWithReporter(new[] { "dotnet new " }, reporter).Should().Be(0);
|
||||
reporter.Lines.Should().Equal(expected.OrderBy(c => c));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GivenNuGetCommandItDisplaysCompletions()
|
||||
{
|
||||
var expected = new string[] {
|
||||
"--help",
|
||||
"--verbosity",
|
||||
"--version",
|
||||
"-h",
|
||||
"-v",
|
||||
"delete",
|
||||
"locals",
|
||||
"push",
|
||||
};
|
||||
|
||||
var reporter = new BufferedReporter();
|
||||
CompleteCommand.RunWithReporter(new[] { "dotnet nuget " }, reporter).Should().Be(0);
|
||||
reporter.Lines.Should().Equal(expected.OrderBy(c => c));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GivenNuGetDeleteCommandItDisplaysCompletions()
|
||||
{
|
||||
var expected = new string[] {
|
||||
"--api-key",
|
||||
"--force-english-output",
|
||||
"--help",
|
||||
"--no-service-endpoint",
|
||||
"--non-interactive",
|
||||
"--source",
|
||||
"-h",
|
||||
"-k",
|
||||
"-s"
|
||||
};
|
||||
|
||||
var reporter = new BufferedReporter();
|
||||
CompleteCommand.RunWithReporter(new[] { "dotnet nuget delete " }, reporter).Should().Be(0);
|
||||
reporter.Lines.Should().Equal(expected.OrderBy(c => c));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GivenNuGetLocalsCommandItDisplaysCompletions()
|
||||
{
|
||||
var expected = new string[] {
|
||||
"--clear",
|
||||
"--force-english-output",
|
||||
"--help",
|
||||
"--list",
|
||||
"-c",
|
||||
"-h",
|
||||
"-l",
|
||||
"all",
|
||||
"global-packages",
|
||||
"http-cache",
|
||||
"temp"
|
||||
};
|
||||
|
||||
var reporter = new BufferedReporter();
|
||||
CompleteCommand.RunWithReporter(new[] { "dotnet nuget locals " }, reporter).Should().Be(0);
|
||||
reporter.Lines.Should().Equal(expected.OrderBy(c => c));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GivenNuGetPushCommandItDisplaysCompletions()
|
||||
{
|
||||
var expected = new string[] {
|
||||
"--api-key",
|
||||
"--disable-buffering",
|
||||
"--force-english-output",
|
||||
"--help",
|
||||
"--no-service-endpoint",
|
||||
"--no-symbols",
|
||||
"--source",
|
||||
"--symbol-api-key",
|
||||
"--symbol-source",
|
||||
"--timeout",
|
||||
"-d",
|
||||
"-h",
|
||||
"-k",
|
||||
"-n",
|
||||
"-s",
|
||||
"-sk",
|
||||
"-ss",
|
||||
"-t"
|
||||
};
|
||||
|
||||
var reporter = new BufferedReporter();
|
||||
CompleteCommand.RunWithReporter(new[] { "dotnet nuget push " }, reporter).Should().Be(0);
|
||||
reporter.Lines.Should().Equal(expected.OrderBy(c => c));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue