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 =
2017-05-17 17:12:19 -07:00
@ "Usage: dotnet [runtime-options] [path-to-application]
2017-06-29 18:34:56 -07:00
Usage : dotnet [ sdk - options ] [ command ] [ arguments ] [ command - options ]
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 .
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 .
2018-02-21 18:34:25 -08:00
list List project references or installed tools .
2017-05-17 17:12:19 -07:00
nuget Provides additional NuGet commands .
msbuild Runs Microsoft Build Engine ( MSBuild ) .
vstest Runs Microsoft Test Execution Command Line Tool .
2017-08-29 11:48:53 +02:00
store Stores the specified assemblies in the runtime store .
2018-03-21 19:12:32 -07:00
tool Modify tools .
2017-08-20 00:57:32 +02:00
help Show help .
2016-12-15 16:55:52 -08:00
Common options :
2017-05-24 22:03:43 -07:00
- 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 .
2016-12-15 16:55:52 -08:00
2017-05-17 17:12:19 -07:00
Run ' dotnet COMMAND - - help ' for more information on a command .
2016-12-15 16:55:52 -08:00
2017-06-29 18:34:56 -07:00
sdk - options :
2018-03-26 18:16:56 -07:00
- - version Display . NET Core SDK version in use .
2017-06-29 18:34:56 -07:00
- - info Display . NET Core information .
2018-01-03 15:49:41 -06:00
- - list - sdks Display the installed SDKs .
- - list - runtimes Display the installed runtimes .
2017-06-29 18:34:56 -07:00
- d | - - diagnostics Enable diagnostic output .
2017-05-17 17:12:19 -07:00
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 .
2017-08-13 17:48:27 -07:00
- - additional - deps < path > Path to additional deps . json file . ";
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
}
}