Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --? alias for --help #3522

Merged
merged 8 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public bool TryGetOptionArgumentList(string optionName, [NotNullWhen(true)] out

public Task<bool> IsEnabledAsync() => Task.FromResult(false);

public bool IsHelpInvoked() => IsOptionSet(PlatformCommandLineProvider.HelpOptionKey);
public bool IsHelpInvoked() => IsOptionSet(PlatformCommandLineProvider.HelpOptionKey) || IsOptionSet(PlatformCommandLineProvider.HelpOptionShortName);
engyebrahim marked this conversation as resolved.
Show resolved Hide resolved

public bool IsInfoInvoked() => IsOptionSet(PlatformCommandLineProvider.InfoOptionKey);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal CommandLineOption(string name, string description, ArgumentArity arity,

for (int i = 0; i < name.Length; i++)
{
ArgumentGuard.Ensure(char.IsLetter(name[i]) || name[i] == '-', nameof(name), string.Format(CultureInfo.InvariantCulture, PlatformResources.CommandLineInvalidOptionName, name));
ArgumentGuard.Ensure(char.IsLetter(name[i]) || name[i] == '-' || name[i] == '?', nameof(name), string.Format(CultureInfo.InvariantCulture, PlatformResources.CommandLineInvalidOptionName, name));
}

Name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Microsoft.Testing.Platform.CommandLine;
internal sealed class PlatformCommandLineProvider : ICommandLineOptionsProvider
{
public const string HelpOptionKey = "help";
public const string HelpOptionShortName = "?";
engyebrahim marked this conversation as resolved.
Show resolved Hide resolved
public const string InfoOptionKey = "info";
public const string DiagnosticOptionKey = "diagnostic";
public const string DiagnosticOutputFilePrefixOptionKey = "diagnostic-output-fileprefix";
Expand Down Expand Up @@ -57,6 +58,7 @@ internal sealed class PlatformCommandLineProvider : ICommandLineOptionsProvider
new(ExitOnProcessExitOptionKey, PlatformResources.PlatformCommandLineExitOnProcessExitOptionDescription, ArgumentArity.ExactlyOne, false, isBuiltIn: true),

// Hidden options
new(HelpOptionShortName, PlatformResources.PlatformCommandLineHelpOptionDescription, ArgumentArity.Zero, true, isBuiltIn: true),
new(ServerOptionKey, PlatformResources.PlatformCommandLineServerOptionDescription, ArgumentArity.ZeroOrOne, true, isBuiltIn: true),
new(PortOptionKey, PlatformResources.PlatformCommandLinePortOptionDescription, ArgumentArity.ExactlyOne, true, isBuiltIn: true),
new(ClientPortOptionKey, PlatformResources.PlatformCommandLineClientPortOptionDescription, ArgumentArity.ExactlyOne, true, isBuiltIn: true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,38 @@ Execute a .NET Test Application.
testHostResult.AssertOutputMatches(wildcardMatchPattern);
}

[ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))]
public async Task HelpShortName_WhenNoExtensionRegistered_OutputDefaultHelpContent(string tfm)
{
var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.NoExtensionAssetName, tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync("--?");

testHostResult.AssertExitCodeIs(ExitCodes.Success);

const string wildcardMatchPattern = $"""
.NET Testing Platform v*
Usage {TestAssetFixture.NoExtensionAssetName}* [option providers] [extension option providers]
MarcoRossignoli marked this conversation as resolved.
Show resolved Hide resolved
Execute a .NET Test Application.
Options:
--diagnostic Enable the diagnostic logging. The default log level is 'Trace'. The file will be written in the output directory with the name log_[MMddHHssfff].diag
--diagnostic-filelogger-synchronouswrite Force the built-in file logger to write the log synchronously. Useful for scenario where you don't want to lose any log (i.e. in case of crash). Note that this is slowing down the test execution.
--diagnostic-output-directory Output directory of the diagnostic logging, if not specified the file will be generated inside the default 'TestResults' directory.
--diagnostic-output-fileprefix Prefix for the log file name that will replace '[log]_.'
--diagnostic-verbosity Define the level of the verbosity for the --diagnostic. The available values are 'Trace', 'Debug', 'Information', 'Warning', 'Error', and 'Critical'
--exit-on-process-exit Exit the test process if dependent process exits. PID must be provided.
--help Show the command line help.
--ignore-exit-code Do not report non successful exit value for specific exit codes (e.g. '--ignore-exit-code 8;9' ignore exit code 8 and 9 and will return 0 in these case)
--info Display .NET test application information.
--list-tests List available tests.
--minimum-expected-tests Specifies the minimum number of tests that are expected to run.
--results-directory The directory where the test results are going to be placed. If the specified directory doesn't exist, it's created. The default is TestResults in the directory that contains the test application.
Extension options:
--treenode-filter Use a tree filter to filter down the tests to execute
""";

testHostResult.AssertOutputMatches(wildcardMatchPattern);
}

[ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))]
public async Task Help_WhenNoExtensionRegisteredAndUnknownOptionIsSpecified_OutputDefaultHelpContentAndUnknownOption(string tfm)
{
Expand Down Expand Up @@ -105,6 +137,10 @@ .NET Testing Platform v.+ \[.+\]
Version: .+
Description: Microsoft Testing Platform command line provider
Options:
--\?
Arity: 0
Hidden: True
Description: Show the command line help\.
--client-host
Arity: 1
Hidden: True
Expand Down Expand Up @@ -250,6 +286,50 @@ Execute a .NET Test Application.
testHostResult.AssertOutputMatches(wildcardPattern);
}

[ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))]
public async Task HelpShortName_WithAllExtensionsRegistered_OutputFullHelpContent(string tfm)
{
var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.AllExtensionsTargetAssetPath, TestAssetFixture.AllExtensionsAssetName, tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync("-?");

testHostResult.AssertExitCodeIs(ExitCodes.Success);

string wildcardPattern = $"""
.NET Testing Platform v*
Usage {TestAssetFixture.AllExtensionsAssetName}* [option providers] [extension option providers]
Execute a .NET Test Application.
Options:
--diagnostic Enable the diagnostic logging. The default log level is 'Trace'. The file will be written in the output directory with the name log_[MMddHHssfff].diag
--diagnostic-filelogger-synchronouswrite Force the built-in file logger to write the log synchronously. Useful for scenario where you don't want to lose any log (i.e. in case of crash). Note that this is slowing down the test execution.
--diagnostic-output-directory Output directory of the diagnostic logging, if not specified the file will be generated inside the default 'TestResults' directory.
--diagnostic-output-fileprefix Prefix for the log file name that will replace '[log]_.'
--diagnostic-verbosity Define the level of the verbosity for the --diagnostic. The available values are 'Trace', 'Debug', 'Information', 'Warning', 'Error', and 'Critical'
--exit-on-process-exit Exit the test process if dependent process exits. PID must be provided.
--help Show the command line help.
--ignore-exit-code Do not report non successful exit value for specific exit codes (e.g. '--ignore-exit-code 8;9' ignore exit code 8 and 9 and will return 0 in these case)
--info Display .NET test application information.
--list-tests List available tests.
--minimum-expected-tests Specifies the minimum number of tests that are expected to run.
--results-directory The directory where the test results are going to be placed. If the specified directory doesn't exist, it's created. The default is TestResults in the directory that contains the test application.
--retry-failed-tests Enable retry failed tests
--retry-failed-tests-max-percentage Disable retry mechanism if the percentage of failed tests is greater than the specified value
--retry-failed-tests-max-tests Disable retry mechanism if the number of failed tests is greater than the specified value
Extension options:
--crashdump [net6.0+ only] Generate a dump file if the test process crashes
--crashdump-filename Specify the name of the dump file
--crashdump-type Specify the type of the dump. Valid values are 'Mini', 'Heap', 'Triage' or 'Full'. Default type is 'Full'. For more information visit https://learn.microsoft.com/dotnet/core/diagnostics/collect-dumps-crash#types-of-mini-dumps
--hangdump Generate a dump file if the test process hangs
--hangdump-filename Specify the name of the dump file
--hangdump-timeout Specify the timeout after which the dump will be generated. The timeout value is specified in one of the following formats: 1.5h, 1.5hour, 1.5hours, 90m, 90min, 90minute, 90minutes 5400s, 5400sec, 5400second, 5400seconds. Default is 30m.
--hangdump-type Specify the type of the dump. Valid values are 'Mini', 'Heap', 'Triage' (only available in .NET 6+) or 'Full'. Default type is 'Full'
--report-trx Enable generating TRX report
--report-trx-filename The name of the generated TRX report
--treenode-filter Use a tree filter to filter down the tests to execute
""";

testHostResult.AssertOutputMatches(wildcardPattern);
}

[ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))]
public async Task Info_WithAllExtensionsRegistered_OutputFullInfoContent(string tfm)
{
Expand All @@ -271,6 +351,10 @@ .NET Testing Platform v* [*]
Version: *
Description: Microsoft Testing Platform command line provider
Options:
--?
Arity: 0
Hidden: True
Description: Show the command line help.
--client-host
Arity: 1
Hidden: True
Expand Down