2017-04-10 22:31:40 -07:00
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2016-12-15 16:55:52 -08:00
// 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 ;
2017-02-17 09:00:25 -08:00
using HelpActual = Microsoft . DotNet . Tools . Help ;
2016-12-15 16:55:52 -08:00
namespace Microsoft.DotNet.Help.Tests
{
public class GivenThatIWantToShowHelpForDotnetCommand : TestBase
{
private const string HelpText =
2018-04-30 13:42:47 -07:00
@ "Usage: dotnet [runtime-options] [path-to-application] [arguments]
Execute a . NET Core application .
runtime - options :
- - additionalprobingpath < path > Path containing probing policy and assemblies to probe for .
- - additional - deps < path > Path to additional deps . json file .
- - 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 .
2016-12-15 16:55:52 -08:00
2017-05-17 17:12:19 -07:00
path - to - application :
The path to an application . dll file to execute .
2018-04-30 13:42:47 -07:00
Usage : dotnet [ sdk - options ] [ command ] [ command - options ] [ arguments ]
2016-12-15 16:55:52 -08:00
2018-04-30 13:42:47 -07:00
Execute a . NET Core SDK command .
2016-12-15 16:55:52 -08:00
2017-06-29 18:34:56 -07:00
sdk - options :
2018-04-30 13:42:47 -07:00
- d | - - diagnostics Enable diagnostic output .
- h | - - help Show command line help .
- - info Display . NET Core information .
- - list - runtimes Display the installed runtimes .
- - list - sdks Display the installed SDKs .
- - version Display . NET Core SDK version in use .
2017-06-29 18:34:56 -07:00
2018-04-30 13:42:47 -07:00
SDK commands :
add Add a package or reference to a . NET project .
build Build a . NET project .
build - server Interact with servers started by a build .
clean Clean build outputs of a . NET project .
help Show command line help .
list List project references of a . NET project .
migrate Migrate a project . json project to an MSBuild project .
msbuild Run Microsoft Build Engine ( MSBuild ) commands .
new Create a new . NET project or file .
nuget Provides additional NuGet commands .
pack Create a NuGet package .
publish Publish a . NET project for deployment .
remove Remove a package or reference from a . NET project .
restore Restore dependencies specified in a . NET project .
run Build and run a . NET project output .
sln Modify Visual Studio solution files .
store Store the specified assemblies in the runtime package store .
test Run unit tests using the test runner specified in a . NET project .
tool Install or manage tools that extend the . NET experience .
vstest Run Microsoft Test Engine ( VSTest ) commands .
Additional commands from bundled tools :
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 .
2018-05-01 13:20:06 -07:00
2018-04-30 13:42:47 -07:00
Run ' dotnet [ command ] - - help ' for more information on a command . ";
2016-12-15 16:55:52 -08:00
[Theory]
[InlineData("--help")]
[InlineData("-h")]
2017-01-12 23:24:12 -10:00
[InlineData("-?")]
[InlineData("/?")]
2016-12-15 16:55:52 -08:00
public void WhenHelpOptionIsPassedToDotnetItPrintsUsage ( string helpArg )
{
var cmd = new DotnetCommand ( )
. ExecuteWithCapturedOutput ( $"{helpArg}" ) ;
2016-12-28 14:50:34 -08:00
cmd . Should ( ) . Pass ( ) ;
2017-06-13 19:24:30 -07:00
cmd . StdOut . Should ( ) . ContainVisuallySameFragmentIfNotLocalized ( HelpText ) ;
2016-12-15 16:55:52 -08:00
}
2017-02-17 09:00:25 -08:00
2017-04-05 11:30:45 -07:00
[Fact]
public void WhenHelpCommandIsPassedToDotnetItPrintsUsage ( )
{
var cmd = new HelpCommand ( )
. ExecuteWithCapturedOutput ( ) ;
cmd . Should ( ) . Pass ( ) ;
2017-06-13 19:24:30 -07:00
cmd . StdOut . Should ( ) . ContainVisuallySameFragmentIfNotLocalized ( HelpText ) ;
2017-04-05 11:30:45 -07:00
}
2017-02-17 09:00:25 -08:00
[Fact]
2017-03-15 07:24:00 -07:00
public void WhenInvalidCommandIsPassedToDotnetHelpItPrintsError ( )
2017-02-17 09:00:25 -08:00
{
var cmd = new DotnetCommand ( )
. ExecuteWithCapturedOutput ( "help invalid" ) ;
2017-04-05 11:30:45 -07:00
2017-02-17 09:00:25 -08:00
cmd . Should ( ) . Fail ( ) ;
2017-06-13 19:24:30 -07:00
cmd . StdErr . Should ( ) . Contain ( string . Format ( Tools . Help . LocalizableStrings . CommandDoesNotExist , "invalid" ) ) ;
cmd . StdOut . Should ( ) . ContainVisuallySameFragmentIfNotLocalized ( HelpText ) ;
2017-02-17 09:00:25 -08:00
}
2017-08-14 23:32:49 +02: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 ) ;
}
2017-02-17 09:00:25 -08:00
[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 ) ;
2017-04-05 11:30:45 -07:00
2017-02-17 09:00:25 -08:00
}
[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 ) ;
}
2016-12-15 16:55:52 -08:00
}
}