Skip to content

Commit

Permalink
Initialize list arguments with non-null values (#652)
Browse files Browse the repository at this point in the history
  • Loading branch information
premun authored Jun 24, 2021
1 parent fed4184 commit 49b0eed
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
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)
{
}

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

0 comments on commit 49b0eed

Please sign in to comment.