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

Implement --config for specifying testconfig.json file #4124

Merged
merged 10 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -31,6 +31,7 @@ internal sealed class PlatformCommandLineProvider : ICommandLineOptionsProvider
public const string MinimumExpectedTestsOptionKey = "minimum-expected-tests";
public const string TestHostControllerPIDOptionKey = "internal-testhostcontroller-pid";
public const string ExitOnProcessExitOptionKey = "exit-on-process-exit";
public const string ConfigOptionKey = "config";

public const string ServerOptionKey = "server";
public const string ClientPortOptionKey = "client-port";
Expand Down Expand Up @@ -59,6 +60,7 @@ internal sealed class PlatformCommandLineProvider : ICommandLineOptionsProvider
new(DiscoverTestsOptionKey, PlatformResources.PlatformCommandLineDiscoverTestsOptionDescription, ArgumentArity.Zero, false, isBuiltIn: true),
new(IgnoreExitCodeOptionKey, PlatformResources.PlatformCommandLineIgnoreExitCodeOptionDescription, ArgumentArity.ExactlyOne, false, isBuiltIn: true),
new(ExitOnProcessExitOptionKey, PlatformResources.PlatformCommandLineExitOnProcessExitOptionDescription, ArgumentArity.ExactlyOne, false, isBuiltIn: true),
new(ConfigOptionKey, PlatformResources.PlatformCommandLineConfigOptionDescription, ArgumentArity.ExactlyOne, false, isBuiltIn: true),
Youssef1313 marked this conversation as resolved.
Show resolved Hide resolved

// Hidden options
new(HelpOptionQuestionMark, PlatformResources.PlatformCommandLineHelpOptionDescription, ArgumentArity.Zero, true, isBuiltIn: true),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Testing.Platform.CommandLine;
using Microsoft.Testing.Platform.Helpers;
using Microsoft.Testing.Platform.Logging;
using Microsoft.Testing.Platform.Services;
Expand All @@ -9,10 +10,15 @@ namespace Microsoft.Testing.Platform.Configurations;

internal sealed partial class JsonConfigurationSource
{
internal sealed class JsonConfigurationProvider(ITestApplicationModuleInfo testApplicationModuleInfo, IFileSystem fileSystem, ILogger? logger) : IConfigurationProvider
internal sealed class JsonConfigurationProvider(
ITestApplicationModuleInfo testApplicationModuleInfo,
IFileSystem fileSystem,
CommandLineParseResult commandLineParseResult,
ILogger? logger) : IConfigurationProvider
{
private readonly ITestApplicationModuleInfo _testApplicationModuleInfo = testApplicationModuleInfo;
private readonly IFileSystem _fileSystem = fileSystem;
private readonly CommandLineParseResult _commandLineParseResult = commandLineParseResult;
private readonly ILogger? _logger = logger;
private Dictionary<string, string?>? _propertyToAllChildren;
private Dictionary<string, string?>? _singleValueData;
Expand All @@ -29,9 +35,12 @@ private async Task LogInformationAsync(string message)

public async Task LoadAsync()
{
string configFileName = $"{Path.Combine(
Path.GetDirectoryName(_testApplicationModuleInfo.GetCurrentTestApplicationFullPath())!,
Path.GetFileNameWithoutExtension(_testApplicationModuleInfo.GetCurrentTestApplicationFullPath()))}{PlatformConfigurationConstants.PlatformConfigSuffixFileName}";
string configFileName = _commandLineParseResult.TryGetOptionArgumentList(PlatformCommandLineProvider.ConfigOptionKey, out string[]? configOptions)
? Path.GetFullPath(configOptions[0])
: $"{Path.Combine(
Path.GetDirectoryName(_testApplicationModuleInfo.GetCurrentTestApplicationFullPath())!,
Path.GetFileNameWithoutExtension(_testApplicationModuleInfo.GetCurrentTestApplicationFullPath()))}{PlatformConfigurationConstants.PlatformConfigSuffixFileName}";

if (!_fileSystem.Exists(configFileName))
{
await LogInformationAsync($"Config file '{configFileName}' not found.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ internal sealed partial class JsonConfigurationSource(ITestApplicationModuleInfo
public Task<bool> IsEnabledAsync() => Task.FromResult(true);

public Task<IConfigurationProvider> BuildAsync(CommandLineParseResult commandLineParseResult)
=> Task.FromResult((IConfigurationProvider)new JsonConfigurationProvider(_testApplicationModuleInfo, _fileSystem, _fileLoggerProvider?.CreateLogger(typeof(JsonConfigurationProvider).ToString())));
=> Task.FromResult((IConfigurationProvider)new JsonConfigurationProvider(_testApplicationModuleInfo, _fileSystem, commandLineParseResult, _fileLoggerProvider?.CreateLogger(typeof(JsonConfigurationProvider).ToString())));
}
Original file line number Diff line number Diff line change
Expand Up @@ -662,4 +662,7 @@ Takes one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is
<value>Failed to read response file '{0}'. {1}.</value>
<comment>{1} is the exception</comment>
</data>
<data name="PlatformCommandLineConfigOptionDescription" xml:space="preserve">
<value>Specifies a testconfig.json file.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@
<target state="translated">Zadejte port klienta.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineConfigOptionDescription">
<source>Specifies a testconfig.json file.</source>
<target state="new">Specifies a testconfig.json file.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@
<target state="translated">Geben Sie den Port des Clients an.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineConfigOptionDescription">
<source>Specifies a testconfig.json file.</source>
<target state="new">Specifies a testconfig.json file.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@
<target state="translated">Especifique el puerto del cliente.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineConfigOptionDescription">
<source>Specifies a testconfig.json file.</source>
<target state="new">Specifies a testconfig.json file.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@
<target state="translated">Spécifier le port du client.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineConfigOptionDescription">
<source>Specifies a testconfig.json file.</source>
<target state="new">Specifies a testconfig.json file.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@
<target state="translated">Specifica la porta del client.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineConfigOptionDescription">
<source>Specifies a testconfig.json file.</source>
<target state="new">Specifies a testconfig.json file.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@
<target state="translated">クライアントのポートを指定します。</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineConfigOptionDescription">
<source>Specifies a testconfig.json file.</source>
<target state="new">Specifies a testconfig.json file.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@
<target state="translated">클라이언트의 포트를 지정합니다.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineConfigOptionDescription">
<source>Specifies a testconfig.json file.</source>
<target state="new">Specifies a testconfig.json file.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@
<target state="translated">Określ port klienta.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineConfigOptionDescription">
<source>Specifies a testconfig.json file.</source>
<target state="new">Specifies a testconfig.json file.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@
<target state="translated">Especifique a porta do cliente.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineConfigOptionDescription">
<source>Specifies a testconfig.json file.</source>
<target state="new">Specifies a testconfig.json file.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@
<target state="translated">Укажите порт клиента.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineConfigOptionDescription">
<source>Specifies a testconfig.json file.</source>
<target state="new">Specifies a testconfig.json file.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@
<target state="translated">İstemcinin bağlantı noktasını belirtir.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineConfigOptionDescription">
<source>Specifies a testconfig.json file.</source>
<target state="new">Specifies a testconfig.json file.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@
<target state="translated">指定客户端的端口。</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineConfigOptionDescription">
<source>Specifies a testconfig.json file.</source>
<target state="new">Specifies a testconfig.json file.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@
<target state="translated">指定用戶端的連接埠。</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineConfigOptionDescription">
<source>Specifies a testconfig.json file.</source>
<target state="new">Specifies a testconfig.json file.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public async Task Help_WhenMSTestExtensionRegistered_OutputHelpContentOfRegister
Usage {AssetName}* [option providers] [extension option providers]
Execute a .NET Test Application.
Options:
--config
Specifies a testconfig.json file.
--diagnostic
Enable the diagnostic logging. The default log level is 'Trace'.
The file will be written in the output directory with the name log_[yyMMddHHmmssfff].diag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ .NET Testing Platform v*
Usage {TestAssetFixture.NoExtensionAssetName}* [option providers] [extension option providers]
Execute a .NET Test Application.
Options:
--config
Youssef1313 marked this conversation as resolved.
Show resolved Hide resolved
Specifies a testconfig.json file.
--diagnostic
Enable the diagnostic logging. The default log level is 'Trace'.
The file will be written in the output directory with the name log_[yyMMddHHmmssfff].diag
Expand Down Expand Up @@ -150,6 +152,10 @@ .NET Testing Platform v.+ \[.+\]
Arity: 1
Hidden: True
Description: Specify the port of the client\.
--config
Arity: 1
Hidden: False
Description: Specifies a testconfig\.json file\.
--diagnostic
Arity: 0
Hidden: False
Expand Down Expand Up @@ -283,6 +289,8 @@ .NET Testing Platform v*
Usage {TestAssetFixture.AllExtensionsAssetName}* [option providers] [extension option providers]
Execute a .NET Test Application.
Options:
--config
Specifies a testconfig.json file.
--diagnostic
Enable the diagnostic logging. The default log level is 'Trace'.
The file will be written in the output directory with the name log_[yyMMddHHmmssfff].diag
Expand Down Expand Up @@ -418,6 +426,10 @@ .NET Testing Platform v* [*]
Arity: 1
Hidden: True
Description: Specify the port of the client.
--config
Arity: 1
Hidden: False
Description: Specifies a testconfig.json file.
--diagnostic
Arity: 0
Hidden: False
Expand Down
Loading