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

Initialize list arguments with non-null values #652

Merged
merged 1 commit into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -15,9 +15,8 @@ namespace Microsoft.DotNet.XHarness.CLI.CommandArguments.Apple
/// </summary>
internal class MlaunchArgument : Argument<string>
{
public MlaunchArgument() : base("mlaunch=", "Path to the mlaunch binary")
public MlaunchArgument() : base("mlaunch=", "Path to the mlaunch binary", MacOSProcessManager.DetectMlaunchPath())
{
Value = MacOSProcessManager.DetectMlaunchPath();
}

public override void Action(string argumentValue) => Value = RootPath(argumentValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ namespace Microsoft.DotNet.XHarness.CLI.CommandArguments.Apple
/// </summary>
internal class TargetArgument : Argument<TestTargetOs>
{
public TargetArgument() : base("target=|targets=|t=", "Test target (device/simulator and OS)")
public TargetArgument() : base("target=|targets=|t=", "Test target (device/simulator and OS)", TestTargetOs.None)
{
Value = TestTargetOs.None;
}

public override void Action(string argumentValue)
Expand Down
15 changes: 6 additions & 9 deletions src/Microsoft.DotNet.XHarness.CLI/CommandArguments/Argument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public abstract class Argument<T> : Argument
{
public virtual T Value { get; protected set; }

protected Argument(string prototype, string description, T defaultValue = default!)
protected Argument(string prototype, string description, T defaultValue)
: base(prototype, description)
{
Value = defaultValue;
Expand All @@ -138,9 +138,8 @@ protected Argument(string prototype, string description, T defaultValue = defaul
public abstract class IntArgument : Argument<int>
{
public IntArgument(string prototype, string description, int defaultValue = 0)
: base(prototype, description)
: base(prototype, description, defaultValue)
{
Value = defaultValue;
}

public override void Action(string argumentValue)
Expand All @@ -158,7 +157,7 @@ public override void Action(string argumentValue)
public abstract class StringArgument : Argument<string?>
{
public StringArgument(string prototype, string description)
: base(prototype, description)
: base(prototype, description, null)
premun marked this conversation as resolved.
Show resolved Hide resolved
{
}

Expand Down Expand Up @@ -186,9 +185,8 @@ public override void Validate()
public abstract class TimeSpanArgument : Argument<TimeSpan>
{
protected TimeSpanArgument(string prototype, string description, TimeSpan defaultValue)
: base(prototype, description)
: base(prototype, description, defaultValue)
{
Value = defaultValue;
}

public override void Action(string argumentValue)
Expand Down Expand Up @@ -243,9 +241,8 @@ public abstract class SwitchArgument : Argument<bool>
private readonly bool _defaultValue;

public SwitchArgument(string prototype, string description, bool defaultValue)
: base(prototype, description)
: base(prototype, description, defaultValue)
{
Value = defaultValue;
_defaultValue = defaultValue;
}

Expand All @@ -271,7 +268,7 @@ public abstract class RepeatableArgument : Argument<IEnumerable<string>>
{
private readonly List<string> _values = new();

protected RepeatableArgument(string prototype, string description) : base(prototype, description + ". Can be used more than once")
protected RepeatableArgument(string prototype, string description) : base(prototype, description + ". Can be used more than once", Array.Empty<string>())
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;

namespace Microsoft.DotNet.XHarness.CLI.CommandArguments
{
internal class WebServerHttpEnvironmentVariables : Argument<IEnumerable<string>>
{
public WebServerHttpEnvironmentVariables()
: base("set-web-server-http-env=", "Comma separated list of environment variable names, which should be set to HTTP host and port, for the unit test, which use xharness as test web server")
: base(
"set-web-server-http-env=",
"Comma separated list of environment variable names, which should be set to HTTP host and port, for the unit test, which use xharness as test web server",
Array.Empty<string>())
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;

namespace Microsoft.DotNet.XHarness.CLI.CommandArguments
{
internal class WebServerHttpsEnvironmentVariables : Argument<IEnumerable<string>>
{
public WebServerHttpsEnvironmentVariables()
: base("set-web-server-https-env=", "Comma separated list of environment variable names, which should be set to HTTPS host and port, for the unit test, which use xharness as test web server")
: base(
"set-web-server-https-env=",
"Comma separated list of environment variable names, which should be set to HTTPS host and port, for the unit test, which use xharness as test web server",
Array.Empty<string>())
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ namespace Microsoft.DotNet.XHarness.CLI.CommandArguments
internal class WebServerMiddlewareArgument : Argument<List<(string path, string type)>>
{
public WebServerMiddlewareArgument()
: base("web-server-middleware=", "<path>,<typeName> to assembly and type which contains Kestrel middleware for local test server. Could be used multiple times to load multiple middlewares", new List<(string path, string type)>())
: base(
"web-server-middleware=",
"<path>,<typeName> to assembly and type which contains Kestrel middleware for local test server. Could be used multiple times to load multiple middlewares",
new List<(string path, string type)>())
{
}

Expand Down