Skip to content

Commit 91ab11e

Browse files
Update help option in dotnet test (#47189)
Co-authored-by: Amaury Levé <[email protected]>
1 parent 268d124 commit 91ab11e

23 files changed

+1035
-118
lines changed

src/Cli/dotnet/commands/dotnet-test/CliConstants.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ namespace Microsoft.DotNet.Cli
66
internal static class CliConstants
77
{
88
public const string DotnetRunCommand = "dotnet run";
9-
public const string HelpOptionKey = "--help";
10-
public const string ShortHelpOptionKey = "-h";
9+
1110
public const string ServerOptionKey = "--server";
1211
public const string DotNetTestPipeOptionKey = "--dotnet-test-pipe";
1312
public const string FrameworkOptionKey = "--framework";

src/Cli/dotnet/commands/dotnet-test/LocalizableStrings.resx

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@
123123
<data name="AppDescription" xml:space="preserve">
124124
<value>Test Driver for the .NET Platform</value>
125125
</data>
126+
<data name="DotnetTestCommand" xml:space="preserve">
127+
<value>.NET Test Command</value>
128+
</data>
126129
<data name="CmdSettingsFile" xml:space="preserve">
127130
<value>SETTINGS_FILE</value>
128131
</data>
@@ -314,7 +317,8 @@ For MSTest before 2.2.4, the timeout is used for all testcases.</value>
314317
<comment>{0} - test message state</comment>
315318
</data>
316319
<data name="CmdUnsupportedVSTestTestApplicationsDescription" xml:space="preserve">
317-
<value>Test application(s) that support VSTest are not supported.</value>
320+
<value>Test projects that use both VSTest and Microsoft.Testing.Platform in the same solution are not supported.
321+
See https://aka.ms/dotnet-test/mtp for more information.</value>
318322
</data>
319323
<data name="Aborted" xml:space="preserve">
320324
<value>Aborted</value>
@@ -469,11 +473,22 @@ For MSTest before 2.2.4, the timeout is used for all testcases.</value>
469473
</data>
470474
<data name="HelpModuleIsMissingTheOptionsBelow" xml:space="preserve">
471475
<value>{0} is missing the options below</value>
476+
<comment>0 is name of the module, this string is followed by lined that list the options</comment>
477+
</data>
478+
<data name="HelpModulesAreMissingTheOptionBelow" xml:space="preserve">
479+
<value>{0} are missing the option below</value>
472480
<comment>0 is name of the module, this string is followed by lined that list the option</comment>
473481
</data>
482+
<data name="HelpModulesAreMissingTheOptionsBelow" xml:space="preserve">
483+
<value>{0} are missing the options below</value>
484+
<comment>0 is name of the module, this string is followed by lined that list the options</comment>
485+
</data>
474486
<data name="HelpOptions" xml:space="preserve">
475487
<value>Options:</value>
476488
</data>
489+
<data name="HelpPlatformOptions" xml:space="preserve">
490+
<value>Platform Options:</value>
491+
</data>
477492
<data name="HelpUnavailableExtensionOptions" xml:space="preserve">
478493
<value>Unavailable extension options:</value>
479494
</data>
@@ -483,4 +498,25 @@ For MSTest before 2.2.4, the timeout is used for all testcases.</value>
483498
<data name="HelpWaitingForOptionsAndExtensions" xml:space="preserve">
484499
<value>Waiting for options and extensions...</value>
485500
</data>
486-
</root>
501+
<data name="CmdHelpUsageTitle" xml:space="preserve">
502+
<value>Usage:</value>
503+
</data>
504+
<data name="CmdProjectPathName" xml:space="preserve">
505+
<value>PROJECT_PATH</value>
506+
</data>
507+
<data name="CmdSolutionPathName" xml:space="preserve">
508+
<value>SOLUTION_PATH</value>
509+
</data>
510+
<data name="CmdDirectoryPathName" xml:space="preserve">
511+
<value>DIRECTORY_PATH</value>
512+
</data>
513+
<data name="CmdExpressionName" xml:space="preserve">
514+
<value>EXPRESSION</value>
515+
</data>
516+
<data name="CmdRootPathName" xml:space="preserve">
517+
<value>ROOT_PATH</value>
518+
</data>
519+
<data name="CmdNumberName" xml:space="preserve">
520+
<value>NUMBER</value>
521+
</data>
522+
</root>

src/Cli/dotnet/commands/dotnet-test/Options.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Microsoft.DotNet.Cli
55
{
6-
internal record TestOptions(bool HasListTests, string Configuration, string Architecture, bool HasFilterMode, bool IsHelp);
6+
internal record TestOptions(string Configuration, string Architecture, bool HasFilterMode, bool IsHelp);
77

88
internal record PathOptions(string ProjectPath, string SolutionPath, string DirectoryPath);
99

src/Cli/dotnet/commands/dotnet-test/Terminal/TerminalTestReporter.cs

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Collections.Concurrent;
55
using System.Globalization;
66
using System.Text.RegularExpressions;
7-
using Microsoft.DotNet.Cli;
87
using Microsoft.Testing.Platform.Helpers;
98
using LocalizableStrings = Microsoft.DotNet.Tools.Test.LocalizableStrings;
109

@@ -1038,43 +1037,62 @@ public void TestInProgress(
10381037
_terminalWithProgress.UpdateWorker(asm.SlotIndex);
10391038
}
10401039

1041-
internal void WriteHelpOptions(ConcurrentDictionary<string, CommandLineOption> commandLineOptionNameToModuleNames, Dictionary<bool, List<DotNet.Cli.CommandLineOption>> allOptions, Dictionary<bool, List<(string, string[])>> moduleToMissingOptions)
1040+
public void WriteHeading(string? heading, string? description)
10421041
{
1043-
WriteOptionsToConsole(commandLineOptionNameToModuleNames, allOptions);
1044-
WriteModulesToMissingOptionsToConsole(moduleToMissingOptions);
1042+
if (!string.IsNullOrWhiteSpace(heading))
1043+
{
1044+
WriteMessage(heading);
1045+
}
1046+
1047+
if (!string.IsNullOrWhiteSpace(description))
1048+
{
1049+
int maxWidth = int.MaxValue - SingleIndentation.Length;
1050+
foreach (var part in WrapText(description!, maxWidth))
1051+
{
1052+
WriteMessage(SingleIndentation);
1053+
WriteMessage(part);
1054+
}
1055+
}
10451056
}
10461057

1047-
private void WriteOptionsToConsole(ConcurrentDictionary<string, CommandLineOption> commandLineOptionNameToModuleNames, Dictionary<bool, List<CommandLineOption>> options)
1058+
private static IEnumerable<string> WrapText(string text, int maxWidth)
10481059
{
1049-
int maxOptionNameLength = commandLineOptionNameToModuleNames.Keys.ToArray().Max(option => option.Length);
1050-
1051-
foreach (KeyValuePair<bool, List<CommandLineOption>> optionGroup in options)
1060+
if (string.IsNullOrWhiteSpace(text))
10521061
{
1053-
WriteMessage(string.Empty);
1054-
WriteMessage(optionGroup.Key ? LocalizableStrings.HelpOptions : LocalizableStrings.HelpExtensionOptions);
1062+
yield break;
1063+
}
10551064

1056-
foreach (CommandLineOption option in optionGroup.Value)
1065+
foreach (var part in text.Split(["\r\n", "\n"], StringSplitOptions.None))
1066+
{
1067+
for (int i = 0; i < part.Length; i += maxWidth)
10571068
{
1058-
WriteMessage($"{new string(' ', 2)}--{option.Name}{new string(' ', maxOptionNameLength - option.Name.Length)} {option.Description}");
1069+
int length = Math.Min(maxWidth, part.Length - i);
1070+
int lastSpace = part.LastIndexOf(' ', i + length, length);
1071+
if (lastSpace > i)
1072+
{
1073+
length = lastSpace - i + 1;
1074+
}
1075+
yield return part.Substring(i, length).TrimEnd();
10591076
}
10601077
}
10611078
}
10621079

1063-
private void WriteModulesToMissingOptionsToConsole(Dictionary<bool, List<(string, string[])>> modulesWithMissingOptions)
1080+
public void WriteModulesToMissingOptionsToConsole(Dictionary<bool, List<(string[], string[])>> modulesWithMissingOptions)
10641081
{
10651082
var yellow = new SystemConsoleColor { ConsoleColor = ConsoleColor.Yellow };
1066-
foreach (KeyValuePair<bool, List<(string, string[])>> groupedModules in modulesWithMissingOptions)
1083+
foreach (KeyValuePair<bool, List<(string[], string[])>> groupedModules in modulesWithMissingOptions)
10671084
{
10681085
WriteMessage(string.Empty);
10691086
WriteMessage(groupedModules.Key ? LocalizableStrings.HelpUnavailableOptions : LocalizableStrings.HelpUnavailableExtensionOptions, yellow);
10701087

1071-
foreach ((string module, string[] missingOptions) in groupedModules.Value)
1088+
foreach ((string[] modules, string[] missingOptions) in groupedModules.Value)
10721089
{
1073-
if (module.Length == 0)
1090+
if (modules.Length == 0)
10741091
{
10751092
continue;
10761093
}
10771094

1095+
string moduleList = string.Join("\n", modules);
10781096
StringBuilder line = new();
10791097
for (int i = 0; i < missingOptions.Length; i++)
10801098
{
@@ -1084,10 +1102,10 @@ private void WriteModulesToMissingOptionsToConsole(Dictionary<bool, List<(string
10841102
line.Append($"--{missingOptions[i]}\n");
10851103
}
10861104

1087-
string format = missingOptions.Length == 1
1088-
? LocalizableStrings.HelpModuleIsMissingTheOptionBelow
1089-
: LocalizableStrings.HelpModuleIsMissingTheOptionsBelow;
1090-
var missing = string.Format(format, module);
1105+
string format = modules.Length == 1
1106+
? (missingOptions.Length == 1 ? LocalizableStrings.HelpModuleIsMissingTheOptionBelow : LocalizableStrings.HelpModuleIsMissingTheOptionsBelow)
1107+
: (missingOptions.Length == 1 ? LocalizableStrings.HelpModulesAreMissingTheOptionBelow : LocalizableStrings.HelpModulesAreMissingTheOptionsBelow);
1108+
var missing = string.Format(format, moduleList);
10911109
WriteMessage($"{missing}\n{line}\n");
10921110
}
10931111
}

src/Cli/dotnet/commands/dotnet-test/TestApplication.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,9 @@ private string BuildArgsWithDotnetRun(TestOptions testOptions)
331331

332332
private void AppendCommonArgs(StringBuilder builder, TestOptions testOptions)
333333
{
334-
if (testOptions.HasListTests)
335-
{
336-
builder.Append($" {TestingPlatformOptions.ListTestsOption.Name}");
337-
}
338-
339334
if (testOptions.IsHelp)
340335
{
341-
builder.Append($" {CliConstants.HelpOptionKey} ");
336+
builder.Append($" {TestingPlatformOptions.HelpOption.Name} ");
342337
}
343338

344339
builder.Append(_args.Count != 0

src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,20 +217,19 @@ private static CliCommand ConstructCommand()
217217

218218
private static CliCommand GetTestingPlatformCliCommand()
219219
{
220-
var command = new TestingPlatformCommand("test");
220+
var command = new TestingPlatformCommand("test", LocalizableStrings.DotnetTestCommand);
221221
command.SetAction(parseResult => command.Run(parseResult));
222222
command.Options.Add(TestingPlatformOptions.ProjectOption);
223223
command.Options.Add(TestingPlatformOptions.SolutionOption);
224224
command.Options.Add(TestingPlatformOptions.DirectoryOption);
225225
command.Options.Add(TestingPlatformOptions.TestModulesFilterOption);
226226
command.Options.Add(TestingPlatformOptions.TestModulesRootDirectoryOption);
227-
command.Options.Add(TestingPlatformOptions.ListTestsOption);
228227
command.Options.Add(TestingPlatformOptions.MaxParallelTestModulesOption);
229228
command.Options.Add(CommonOptions.ArchitectureOption);
230229
command.Options.Add(TestingPlatformOptions.ConfigurationOption);
231230
command.Options.Add(TestingPlatformOptions.FrameworkOption);
232231
command.Options.Add(CommonOptions.OperatingSystemOption);
233-
command.Options.Add(CommonOptions.RuntimeOption);
232+
command.Options.Add(CommonOptions.RuntimeOption.WithHelpDescription(command, LocalizableStrings.RuntimeOptionDescription));
234233
command.Options.Add(CommonOptions.VerbosityOption);
235234
command.Options.Add(CommonOptions.NoRestoreOption);
236235
command.Options.Add(TestingPlatformOptions.NoBuildOption);

0 commit comments

Comments
 (0)