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

Stop accepting multiple test targets #618

Merged
merged 3 commits into from
Jun 1, 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ To run an iOS/tvOS app bundle on a 64bit iPhone Simulator:
xharness apple test \
--app=/path/to/an.app \
--output-directory=out \
--targets=ios-simulator-64
--target=ios-simulator-64
```

or the same can be achieved via the shorthand versions of the same options:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ public string OutputDirectory
set => _outputDirectory = value;
}

/// <summary>
/// List of targets where the app will be run
/// </summary>
public virtual IReadOnlyCollection<string> Targets { get; protected set; } = Array.Empty<string>();

/// <summary>
/// How long XHarness should wait until a test execution completes before clean up (kill running apps, uninstall, etc)
/// </summary>
Expand All @@ -53,10 +48,6 @@ public string OutputDirectory
"output-directory=|o=", "Directory where logs and results will be saved",
v => OutputDirectory = RootPath(v)
},
{
"targets=|t=", "Comma-delimited list of targets to test for",
v => Targets = v.Split(',')
},
{
"timeout=", "Time span in the form of \"00:00:00\" or number of seconds to wait for instrumentation to complete",
v =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.DotNet.XHarness.Common.CLI;
using Microsoft.DotNet.XHarness.Common.Execution;
using Microsoft.DotNet.XHarness.iOS.Shared;
Expand Down Expand Up @@ -48,44 +47,35 @@ internal abstract class AppleAppRunArguments : AppRunCommandArguments
/// </summary>
public bool ResetSimulator { get; set; }

public override IReadOnlyCollection<string> Targets
{
get => RunTargets.Select(t => t.AsString()).ToArray();
protected set
{
var testTargets = new List<TestTargetOs>();

foreach (var targetName in value ?? throw new ArgumentException("Targets cannot be empty"))
{
try
{
testTargets.Add(targetName.ParseAsAppRunnerTargetOs());
}
catch (ArgumentOutOfRangeException)
{
throw new ArgumentException(
$"Failed to parse test target '{targetName}'. Available targets are:" +
GetAllowedValues(t => t.AsString(), invalidValues: TestTarget.None) +
Environment.NewLine + Environment.NewLine +
"You can also specify desired iOS/tvOS/WatchOS version. Example: ios-simulator-64_13.4");
}
}

RunTargets = testTargets;
}
}

/// <summary>
/// Parsed strong-typed targets.
/// Test target.
/// </summary>
public IReadOnlyCollection<TestTargetOs> RunTargets { get; private set; } = Array.Empty<TestTargetOs>();
public TestTargetOs Target { get; private set; } = TestTargetOs.None;

protected override OptionSet GetCommandOptions()
{
var options = base.GetCommandOptions();

var runOptions = new OptionSet
{
{
"target=|targets=|t=", "Test target (device/simulator and OS)",
v =>
{
try
{
Target = v.ParseAsAppRunnerTargetOs();
}
catch (ArgumentOutOfRangeException)
{
throw new ArgumentException(
$"Failed to parse test target '{v}'. Available targets are:" +
GetAllowedValues(t => t.AsString(), invalidValues: TestTarget.None) +
Environment.NewLine + Environment.NewLine +
"You can also specify desired OS version, e.g. ios-simulator-64_13.4");
}
}
},
{
"xcode=", "Path where Xcode is installed",
v => XcodeRoot = RootPath(v)
Expand All @@ -108,7 +98,8 @@ protected override OptionSet GetCommandOptions()
},
{
"set-env=", "Environmental variable to set for the application in format key=value. Can be used multiple times",
v => {
v =>
{
var position = v.IndexOf('=');
if (position == -1)
{
Expand Down Expand Up @@ -139,13 +130,9 @@ public override void Validate()
throw new ArgumentException($"Failed to find the app bundle at {AppPackagePath}");
}

if (RunTargets.Count == 0)
if (Target == TestTargetOs.None)
{
throw new ArgumentException(
"No targets specified. At least one target must be provided. Available targets are:" +
GetAllowedValues(t => t.AsString(), invalidValues: TestTarget.None) +
Environment.NewLine + Environment.NewLine +
"You can also specify desired iOS/tvOS/WatchOS version. Example: ios-simulator-64_13.4");
throw new ArgumentException("No test target specified");
}

if (!File.Exists(MlaunchPath))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,9 @@ public override void Validate()
throw new ArgumentException($"Failed to find the app bundle at {AppPackagePath}");
}

if (RunTargets.Count == 0)
if (Target == null)
premun marked this conversation as resolved.
Show resolved Hide resolved
{
throw new ArgumentException(
"No targets specified. At least one target must be provided. Available targets are:" +
GetAllowedValues(t => t.AsString(), invalidValues: TestTarget.None) +
Environment.NewLine + Environment.NewLine +
"You can also specify desired iOS/tvOS/WatchOS version. Example: ios-simulator-64_13.4");
throw new ArgumentException("No test target specified");
}

if (!File.Exists(MlaunchPath))
Expand Down
33 changes: 16 additions & 17 deletions src/Microsoft.DotNet.XHarness.CLI/Commands/Apple/AppleAppCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,23 @@ protected sealed override async Task<ExitCode> InvokeInternal(Extensions.Logging

var exitCode = ExitCode.SUCCESS;

foreach (var target in AppleAppArguments.RunTargets)
var targetName = AppleAppArguments.Target.AsString();

logger.LogInformation($"Preparing run for {targetName}{ (AppleAppArguments.DeviceName != null ? " targeting " + AppleAppArguments.DeviceName : null) }");

// Create main log file for the run
string logFileName = $"{Name}-{targetName}{(AppleAppArguments.DeviceName != null ? "-" + AppleAppArguments.DeviceName : null)}.log";
IFileBackedLog mainLog = logs.Create(logFileName, LogType.ExecutionLog.ToString(), timestamp: true);

// Pipe the execution log to the debug output of XHarness effectively making "-v" turn this on
CallbackLog debugLog = new(message => logger.LogDebug(message.Trim()));
mainLog = Log.CreateReadableAggregatedLog(mainLog, debugLog);
mainLog.Timestamp = true;

var exitCodeForRun = await InvokeInternal(processManager, appBundleInformationParser, deviceFinder, logger, AppleAppArguments.Target, logs, mainLog, cts.Token);
if (exitCodeForRun != ExitCode.SUCCESS)
{
logger.LogInformation($"Preparing run for {target.AsString()}{ (AppleAppArguments.DeviceName != null ? " targeting " + AppleAppArguments.DeviceName : null) }");

// Create main log file for the run
string logFileName = $"{Name}-{target.AsString()}{(AppleAppArguments.DeviceName != null ? "-" + AppleAppArguments.DeviceName : null)}.log";
IFileBackedLog mainLog = logs.Create(logFileName, LogType.ExecutionLog.ToString(), timestamp: true);

// Pipe the execution log to the debug output of XHarness effectively making "-v" turn this on
CallbackLog debugLog = new(message => logger.LogDebug(message.Trim()));
mainLog = Log.CreateReadableAggregatedLog(mainLog, debugLog);
mainLog.Timestamp = true;

var exitCodeForRun = await InvokeInternal(processManager, appBundleInformationParser, deviceFinder, logger, target, logs, mainLog, cts.Token);
if (exitCodeForRun != ExitCode.SUCCESS)
{
exitCode = exitCodeForRun;
}
exitCode = exitCodeForRun;
}

return exitCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal class AppleInstallCommand : AppleAppCommand<AppleInstallCommandArgument

protected override AppleInstallCommandArguments AppleAppArguments { get; } = new();

protected override string CommandUsage { get; } = "apple install --app=... --output-directory=... --targets=... [OPTIONS] [-- [RUNTIME ARGUMENTS]]";
protected override string CommandUsage { get; } = "apple install --app=... --output-directory=... --target=... [OPTIONS] [-- [RUNTIME ARGUMENTS]]";
protected override string CommandDescription { get; } = CommandHelp;

public AppleInstallCommand() : base("install", false, CommandHelp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class AppleJustRunCommand : AppleAppCommand<AppleJustRunCommandArgument
private const string CommandHelp = "Runs an already installed iOS/tvOS/watchOS/MacCatalyst test application containing a TestRunner " +
"in a target device/simulator and tries to detect the exit code.";

protected override string CommandUsage { get; } = "apple just-run --app=... --output-directory=... --targets=... [OPTIONS] [-- [RUNTIME ARGUMENTS]]";
protected override string CommandUsage { get; } = "apple just-run --app=... --output-directory=... --target=... [OPTIONS] [-- [RUNTIME ARGUMENTS]]";
protected override string CommandDescription { get; } = CommandHelp;
protected override AppleJustRunCommandArguments AppleAppArguments { get; } = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal class AppleJustTestCommand : AppleAppCommand<AppleJustTestCommandArgume
{
private const string CommandHelp = "Runs an already installed iOS/tvOS/watchOS/MacCatalyst test application containing a TestRunner in a target device/simulator.";

protected override string CommandUsage { get; } = "apple just-test --app=... --output-directory=... --targets=... [OPTIONS] [-- [RUNTIME ARGUMENTS]]";
protected override string CommandUsage { get; } = "apple just-test --app=... --output-directory=... --target=... [OPTIONS] [-- [RUNTIME ARGUMENTS]]";
protected override string CommandDescription { get; } = CommandHelp;
protected override AppleJustTestCommandArguments AppleAppArguments { get; } = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal class AppleRunCommand : AppleAppCommand<AppleRunCommandArguments>
"in a target device/simulator and tries to detect the exit code.";

protected override AppleRunCommandArguments AppleAppArguments { get; } = new();
protected override string CommandUsage { get; } = "apple run --app=... --output-directory=... --targets=... [OPTIONS] [-- [RUNTIME ARGUMENTS]]";
protected override string CommandUsage { get; } = "apple run --app=... --output-directory=... --target=... [OPTIONS] [-- [RUNTIME ARGUMENTS]]";
protected override string CommandDescription { get; } = CommandHelp;

public AppleRunCommand() : base("run", false, CommandHelp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal class AppleTestCommand : AppleAppCommand<AppleTestCommandArguments>
private const string CommandHelp = "Installs, runs and uninstalls a given iOS/tvOS/watchOS/MacCatalyst test application bundle containing TestRunner " +
"in a target device/simulator.";

protected override string CommandUsage { get; } = "apple test --app=... --output-directory=... --targets=... [OPTIONS] [-- [RUNTIME ARGUMENTS]]";
protected override string CommandUsage { get; } = "apple test --app=... --output-directory=... --target=... [OPTIONS] [-- [RUNTIME ARGUMENTS]]";
protected override string CommandDescription { get; } = CommandHelp;
protected override AppleTestCommandArguments AppleAppArguments { get; } = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class AppleUninstallCommand : AppleAppCommand<AppleUninstallCommandArgu
private const string CommandHelp = "Uninstalls a given iOS/tvOS/watchOS/MacCatalyst application bundle from a target device/simulator";

protected override AppleUninstallCommandArguments AppleAppArguments { get; } = new();
protected override string CommandUsage { get; } = "apple uninstall --app=... --output-directory=... --targets=... [OPTIONS] [-- [RUNTIME ARGUMENTS]]";
protected override string CommandUsage { get; } = "apple uninstall --app=... --output-directory=... --target=... [OPTIONS] [-- [RUNTIME ARGUMENTS]]";
protected override string CommandDescription { get; } = CommandHelp;

public AppleUninstallCommand() : base("uninstall", false, CommandHelp)
Expand Down
2 changes: 2 additions & 0 deletions src/Microsoft.DotNet.XHarness.iOS.Shared/TestTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public enum TestTarget

public class TestTargetOs
{
public static readonly TestTargetOs None = new(TestTarget.None, null);

/// <summary>
/// Platform, i.e. Simulator iOS x64
/// </summary>
Expand Down