dotnet-installer/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs

144 lines
6 KiB
C#
Raw Normal View History

2017-04-11 05:31:40 +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.IO;
using Microsoft.Build.Construction;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
using FluentAssertions;
using HelpActual = Microsoft.DotNet.Tools.Help;
namespace Microsoft.DotNet.Help.Tests
{
public class GivenThatIWantToShowHelpForDotnetCommand : TestBase
{
private const string HelpText =
@"Usage: dotnet [runtime-options] [path-to-application]
Usage: dotnet [sdk-options] [command] [arguments] [command-options]
path-to-application:
The path to an application .dll file to execute.
SDK commands:
new Initialize .NET projects.
restore Restore dependencies specified in the .NET project.
run Compiles and immediately executes a .NET project.
build Builds a .NET project.
publish Publishes a .NET project for deployment (including the runtime).
test Runs unit tests using the test runner specified in the project.
pack Creates a NuGet package.
migrate Migrates a project.json based project to a msbuild based project.
clean Clean build output(s).
sln Modify solution (SLN) files.
add Add reference to the project.
remove Remove reference from the project.
list List references of a .NET project.
nuget Provides additional NuGet commands.
msbuild Runs Microsoft Build Engine (MSBuild).
vstest Runs Microsoft Test Execution Command Line Tool.
2017-08-29 09:48:53 +00:00
store Stores the specified assemblies in the runtime store.
2018-04-16 17:51:43 +00:00
tool Install or work with tools that extend the .NET experience.
build-server Interact with servers started by a build.
help Show help.
Common options:
-v|--verbosity Set the verbosity level of the command. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic].
-h|--help Show help.
Run 'dotnet COMMAND --help' for more information on a command.
sdk-options:
--version Display .NET Core SDK version in use.
--info Display .NET Core information.
--list-sdks Display the installed SDKs.
--list-runtimes Display the installed runtimes.
-d|--diagnostics Enable diagnostic output.
runtime-options:
--additionalprobingpath <path> Path containing probing policy and assemblies to probe for.
--fx-version <version> Version of the installed Shared Framework to use to run the application.
--roll-forward-on-no-candidate-fx Roll forward on no candidate shared framework is enabled.
2018-05-01 20:20:06 +00:00
--additional-deps <path> Path to additional deps.json file.
Additional tools ('dotnet [tool-name] --help' for more information):
dev-certs Create and manage development certificates.
ef Entity Framework Core command-line tools.
sql-cache SQL Server cache command-line tools.
user-secrets Manage development user secrets.
watch Start a file watcher that runs a command when files change.
";
[Theory]
[InlineData("--help")]
[InlineData("-h")]
[InlineData("-?")]
[InlineData("/?")]
public void WhenHelpOptionIsPassedToDotnetItPrintsUsage(string helpArg)
{
var cmd = new DotnetCommand()
.ExecuteWithCapturedOutput($"{helpArg}");
2016-12-28 22:50:34 +00:00
cmd.Should().Pass();
cmd.StdOut.Should().ContainVisuallySameFragmentIfNotLocalized(HelpText);
}
[Fact]
public void WhenHelpCommandIsPassedToDotnetItPrintsUsage()
{
var cmd = new HelpCommand()
.ExecuteWithCapturedOutput();
cmd.Should().Pass();
cmd.StdOut.Should().ContainVisuallySameFragmentIfNotLocalized(HelpText);
}
[Fact]
2017-03-15 14:24:00 +00:00
public void WhenInvalidCommandIsPassedToDotnetHelpItPrintsError()
{
var cmd = new DotnetCommand()
.ExecuteWithCapturedOutput("help invalid");
cmd.Should().Fail();
cmd.StdErr.Should().Contain(string.Format(Tools.Help.LocalizableStrings.CommandDoesNotExist, "invalid"));
cmd.StdOut.Should().ContainVisuallySameFragmentIfNotLocalized(HelpText);
}
2017-08-14 21:32:49 +00:00
[Theory]
[InlineData("complete")]
[InlineData("parse")]
public void WhenCommandWithoutDocLinkIsPassedToDotnetHelpItPrintsError(string command)
{
var cmd = new DotnetCommand()
.ExecuteWithCapturedOutput($"help {command}");
cmd.Should().Fail();
cmd.StdErr.Should().Contain(string.Format(Tools.Help.LocalizableStrings.CommandDoesNotExist, command));
cmd.StdOut.Should().ContainVisuallySameFragmentIfNotLocalized(HelpText);
}
[WindowsOnlyFact]
public void WhenRunOnWindowsDotnetHelpCommandShouldContainProperProcessInformation()
{
var proc = HelpActual.HelpCommand.ConfigureProcess("https://aka.ms/dotnet-build");
Assert.Equal("cmd", proc.StartInfo.FileName);
Assert.Equal("/c start https://aka.ms/dotnet-build", proc.StartInfo.Arguments);
}
[LinuxOnlyFact]
public void WhenRunOnLinuxDotnetHelpCommandShouldContainProperProcessInformation()
{
var proc = HelpActual.HelpCommand.ConfigureProcess("https://aka.ms/dotnet-build");
Assert.Equal("xdg-open", proc.StartInfo.FileName);
Assert.Equal("https://aka.ms/dotnet-build", proc.StartInfo.Arguments);
}
[MacOsOnlyFact]
public void WhenRunOnMacOsDotnetHelpCommandShouldContainProperProcessInformation()
{
var proc = HelpActual.HelpCommand.ConfigureProcess("https://aka.ms/dotnet-build");
Assert.Equal("open", proc.StartInfo.FileName);
Assert.Equal("https://aka.ms/dotnet-build", proc.StartInfo.Arguments);
}
}
}