Skip to content

Commit 8b66fb9

Browse files
CopilotYoussef1313
andauthored
Implement global --config-file and --diagnostic-output-directory options for dotnet test MTP (#50136)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Youssef1313 <[email protected]> Co-authored-by: Youssef Victor <[email protected]>
1 parent debc2f5 commit 8b66fb9

19 files changed

+344
-4
lines changed

src/Cli/dotnet/Commands/CliCommandStrings.resx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,19 @@ This is equivalent to deleting project.assets.json.</value>
565565
<value>The directory where the test results will be placed.
566566
The specified directory will be created if it does not exist.</value>
567567
</data>
568+
<data name="CmdConfigFileDescription" xml:space="preserve">
569+
<value>Specifies a testconfig.json file.</value>
570+
</data>
571+
<data name="CmdConfigFilePath" xml:space="preserve">
572+
<value>CONFIG_FILE</value>
573+
</data>
574+
<data name="CmdDiagnosticOutputDirectoryDescription" xml:space="preserve">
575+
<value>Output directory of the diagnostic logging.
576+
If not specified the file will be generated inside the default 'TestResults' directory.</value>
577+
</data>
578+
<data name="CmdDiagnosticOutputDirectoryPath" xml:space="preserve">
579+
<value>DIAGNOSTIC_DIR</value>
580+
</data>
568581
<data name="CmdRootPathName" xml:space="preserve">
569582
<value>ROOT_PATH</value>
570583
</data>

src/Cli/dotnet/Commands/Test/MSBuildUtility.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,28 @@ public static BuildOptions GetBuildOptions(ParseResult parseResult, int degreeOf
6969
string? resultsDirectory = parseResult.GetValue(TestingPlatformOptions.ResultsDirectoryOption);
7070
if (resultsDirectory is not null)
7171
{
72-
resultsDirectory = Path.Combine(Directory.GetCurrentDirectory(), resultsDirectory);
72+
resultsDirectory = Path.GetFullPath(resultsDirectory);
73+
}
74+
75+
string? configFile = parseResult.GetValue(TestingPlatformOptions.ConfigFileOption);
76+
if (configFile is not null)
77+
{
78+
configFile = Path.GetFullPath(configFile);
79+
}
80+
81+
string? diagnosticOutputDirectory = parseResult.GetValue(TestingPlatformOptions.DiagnosticOutputDirectoryOption);
82+
if (diagnosticOutputDirectory is not null)
83+
{
84+
diagnosticOutputDirectory = Path.GetFullPath(diagnosticOutputDirectory);
7385
}
7486

7587
PathOptions pathOptions = new(
7688
parseResult.GetValue(TestingPlatformOptions.ProjectOption),
7789
parseResult.GetValue(TestingPlatformOptions.SolutionOption),
7890
parseResult.GetValue(TestingPlatformOptions.DirectoryOption),
79-
resultsDirectory);
91+
resultsDirectory,
92+
configFile,
93+
diagnosticOutputDirectory);
8094

8195
return new BuildOptions(
8296
pathOptions,

src/Cli/dotnet/Commands/Test/Options.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Microsoft.DotNet.Cli.Commands.Test;
55

66
internal record TestOptions(bool HasFilterMode, bool IsHelp);
77

8-
internal record PathOptions(string? ProjectPath, string? SolutionPath, string? DirectoryPath, string? ResultsDirectoryPath);
8+
internal record PathOptions(string? ProjectPath, string? SolutionPath, string? DirectoryPath, string? ResultsDirectoryPath, string? ConfigFilePath, string? DiagnosticOutputDirectoryPath);
99

1010
internal record BuildOptions(
1111
PathOptions PathOptions,
@@ -14,5 +14,6 @@ internal record BuildOptions(
1414
Utils.VerbosityOptions? Verbosity,
1515
bool NoLaunchProfile,
1616
bool NoLaunchProfileArguments,
17-
int DegreeOfParallelism, List<string> UnmatchedTokens,
17+
int DegreeOfParallelism,
18+
List<string> UnmatchedTokens,
1819
IEnumerable<string> MSBuildArgs);

src/Cli/dotnet/Commands/Test/TestApplication.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ private string GetArguments(TestOptions testOptions)
115115
builder.Append($" {TestingPlatformOptions.ResultsDirectoryOption.Name} {ArgumentEscaper.EscapeSingleArg(resultsDirectoryPath)}");
116116
}
117117

118+
if (_buildOptions.PathOptions.ConfigFilePath is { } configFilePath)
119+
{
120+
builder.Append($" {TestingPlatformOptions.ConfigFileOption.Name} {ArgumentEscaper.EscapeSingleArg(configFilePath)}");
121+
}
122+
123+
if (_buildOptions.PathOptions.DiagnosticOutputDirectoryPath is { } diagnosticOutputDirectoryPath)
124+
{
125+
builder.Append($" {TestingPlatformOptions.DiagnosticOutputDirectoryOption.Name} {ArgumentEscaper.EscapeSingleArg(diagnosticOutputDirectoryPath)}");
126+
}
127+
118128
foreach (var arg in _buildOptions.UnmatchedTokens)
119129
{
120130
builder.Append($" {ArgumentEscaper.EscapeSingleArg(arg)}");

src/Cli/dotnet/Commands/Test/TestCommandParser.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ private static Command GetTestingPlatformCliCommand()
236236
command.Options.Add(TestingPlatformOptions.TestModulesFilterOption);
237237
command.Options.Add(TestingPlatformOptions.TestModulesRootDirectoryOption);
238238
command.Options.Add(TestingPlatformOptions.ResultsDirectoryOption);
239+
command.Options.Add(TestingPlatformOptions.ConfigFileOption);
240+
command.Options.Add(TestingPlatformOptions.DiagnosticOutputDirectoryOption);
239241
command.Options.Add(TestingPlatformOptions.MaxParallelTestModulesOption);
240242
command.Options.Add(CommonOptions.ArchitectureOption);
241243
command.Options.Add(CommonOptions.PropertiesOption);

src/Cli/dotnet/Commands/Test/TestingPlatformOptions.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@ internal static class TestingPlatformOptions
5050
Arity = ArgumentArity.ExactlyOne
5151
};
5252

53+
public static readonly Option<string> ConfigFileOption = new("--config-file")
54+
{
55+
Description = CliCommandStrings.CmdConfigFileDescription,
56+
HelpName = CliCommandStrings.CmdConfigFilePath,
57+
Arity = ArgumentArity.ExactlyOne
58+
};
59+
60+
public static readonly Option<string> DiagnosticOutputDirectoryOption = new("--diagnostic-output-directory")
61+
{
62+
Description = CliCommandStrings.CmdDiagnosticOutputDirectoryDescription,
63+
HelpName = CliCommandStrings.CmdDiagnosticOutputDirectoryPath,
64+
Arity = ArgumentArity.ExactlyOne
65+
};
66+
5367
public static readonly Option<string> MaxParallelTestModulesOption = new("--max-parallel-test-modules")
5468
{
5569
Description = CliCommandStrings.CmdMaxParallelTestModulesDescription,

src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)