forked from dotnet/command-line-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add default values to HelpBuilder output (dotnet#898)
* add default values to HelpBuilder output * add ApprovalTests initial setup * Update naming for HelpBuilderTests * Add approval test to HelpBuilderTests
- Loading branch information
1 parent
425cf56
commit 1607aed
Showing
7 changed files
with
364 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,4 +151,7 @@ nCrunchTemp* | |
TestResults/ | ||
|
||
.fake | ||
.ionide | ||
.ionide | ||
|
||
# ApprovalTests | ||
*.received.txt |
9 changes: 9 additions & 0 deletions
9
src/System.CommandLine.Tests/ApprovalTests/ApprovalTests.Config.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using ApprovalTests.Reporters; | ||
using ApprovalTests.Reporters.TestFrameworks; | ||
|
||
// Use globally defined Reporter for ApprovalTests. Please see | ||
// https://github.com/approvals/ApprovalTests.Net/blob/master/docs/ApprovalTests/Reporters.md | ||
|
||
[assembly: UseReporter(typeof(FrameworkAssertReporter))] | ||
|
||
[assembly: ApprovalTests.Namers.UseApprovalSubdirectory("Approvals")] |
21 changes: 21 additions & 0 deletions
21
...BuilderTests.Help_describes_default_values_for_complex_root_command_scenario.approved.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
the-root-command: | ||
Test description | ||
|
||
Usage: | ||
the-root-command [options] <the-root-arg-no-description-no-default> [<the-root-arg-no-description-default> <the-root-arg-no-default> [<the-root-arg> [<the-root-arg-enum-default>]]] | ||
|
||
Arguments: | ||
<the-root-arg-no-description-no-default> | ||
<the-root-arg-no-description-default> [default: the-root-arg-no-description-default-value] | ||
<the-root-arg-no-default> the-root-arg-no-default-description | ||
<the-root-arg> the-root-arg-description [default: the-root-arg-one-value] | ||
<Read|ReadWrite|Write> the-root-arg-enum-default-description [default: Read] | ||
|
||
Options: | ||
-trna, --the-root-option-no-arg (REQUIRED) the-root-option-no-arg-description | ||
-trondda, --the-root-option-no-description-default-arg <the-root-option-no-description-default-arg> [default: the-root-option--no-description-default-arg-value] | ||
-tronda, --the-root-option-no-default-arg <the-root-option-arg-no-default-arg> (REQUIRED) the-root-option-no-default-description | ||
-troda, --the-root-option-default-arg <the-root-option-arg> the-root-option-default-arg-description [default: the-root-option-arg-value] | ||
-troea, --the-root-option-enum-arg <Read|ReadWrite|Write> the-root-option-description [default: Read] | ||
-trorea, --the-root-option-required-enum-arg <Read|ReadWrite|Write> (REQUIRED) the-root-option-description [default: Read] | ||
|
84 changes: 84 additions & 0 deletions
84
src/System.CommandLine.Tests/ApprovalTests/Help/HelpBuilderTests.Approval.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// 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 Xunit; | ||
using System.CommandLine.Help; | ||
using System.IO; | ||
using ApprovalTests; | ||
|
||
namespace System.CommandLine.Tests.Help | ||
{ | ||
public partial class HelpBuilderTests | ||
{ | ||
[Fact] | ||
public void Help_describes_default_values_for_complex_root_command_scenario() | ||
{ | ||
var command = new RootCommand(description: "Test description") | ||
{ | ||
new Argument<string>("the-root-arg-no-description-no-default"), | ||
new Argument<string>("the-root-arg-no-description-default", | ||
argResult => "the-root-arg-no-description-default-value", | ||
isDefault: true), | ||
new Argument<string>("the-root-arg-no-default") | ||
{ | ||
Description = "the-root-arg-no-default-description", | ||
}, | ||
new Argument<string>("the-root-arg", () => "the-root-arg-one-value") | ||
{ | ||
Description = "the-root-arg-description" | ||
}, | ||
new Argument<FileAccess>("the-root-arg-enum-default", () => FileAccess.Read) | ||
{ | ||
Description = "the-root-arg-enum-default-description", | ||
ArgumentType = typeof(FileAccess) | ||
}, | ||
new Option(aliases: new string[] {"--the-root-option-no-arg", "-trna"}) { | ||
Description = "the-root-option-no-arg-description", | ||
Required = true | ||
}, | ||
new Option<string>( | ||
aliases: new string[] {"--the-root-option-no-description-default-arg", "-trondda"}, | ||
parseArgument: _ => "the-root-option--no-description-default-arg-value", | ||
isDefault: true | ||
), | ||
new Option(aliases: new string[] {"--the-root-option-no-default-arg", "-tronda"}) { | ||
Description = "the-root-option-no-default-description", | ||
Argument = new Argument<string>("the-root-option-arg-no-default-arg") | ||
{ | ||
Description = "the-root-option-arg-no-default-description" | ||
}, | ||
Required = true | ||
}, | ||
new Option(aliases: new string[] {"--the-root-option-default-arg", "-troda"}) { | ||
Description = "the-root-option-default-arg-description", | ||
Argument = new Argument<string>("the-root-option-arg", () => "the-root-option-arg-value") | ||
{ | ||
Description = "the-root-option-arg-description" | ||
}, | ||
}, | ||
new Option(aliases: new string[] {"--the-root-option-enum-arg", "-troea"}) { | ||
Description = "the-root-option-description", | ||
Argument = new Argument<FileAccess>("the-root-option-arg", () => FileAccess.Read) | ||
{ | ||
Description = "the-root-option-arg-description", | ||
}, | ||
}, | ||
new Option(aliases: new string[] {"--the-root-option-required-enum-arg", "-trorea"}) { | ||
Description = "the-root-option-description", | ||
Argument = new Argument<FileAccess>("the-root-option-arg", () => FileAccess.Read) | ||
{ | ||
Description = "the-root-option-arg-description", | ||
}, | ||
Required = true | ||
} | ||
}; | ||
command.Name = "the-root-command"; | ||
|
||
HelpBuilder helpBuilder = GetHelpBuilder(LargeMaxWidth); | ||
helpBuilder.Write(command); | ||
var output = _console.Out.ToString(); | ||
Approvals.Verify(output); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.