Skip to content
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
24 changes: 22 additions & 2 deletions src/Microsoft.DotNet.Helix/Sdk/CreateXHarnessAppleWorkItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static class MetadataNames
public const string Targets = "Targets";
public const string LaunchTimeout = "LaunchTimeout";
public const string IncludesTestRunner = "IncludesTestRunner";
public const string ResetSimulator = "ResetSimulator";
}

private const string EntryPointScript = "xharness-helix-job.apple.sh";
Expand Down Expand Up @@ -135,6 +136,15 @@ private async Task<ITaskItem> PrepareWorkItem(
Log.LogWarning("The ExpectedExitCode property is ignored in the `apple test` scenario");
}

bool resetSimulator = false;
if (appBundleItem.TryGetMetadata(MetadataNames.ResetSimulator, out string resetSimulatorRunnerProp))
{
if (resetSimulatorRunnerProp.ToLowerInvariant() == "true")
{
resetSimulator = true;
}
}

if (customCommands == null)
{
// In case user didn't specify custom commands, we use our default one
Expand All @@ -146,13 +156,14 @@ private async Task<ITaskItem> PrepareWorkItem(
(includesTestRunner
? $"--launch-timeout \"$launch_timeout\" "
: $"--expected-exit-code $expected_exit_code ") +
(resetSimulator ? $"--reset-simulator " : string.Empty) +
"--xcode \"$xcode_path\" " +
"-v " +
(!string.IsNullOrEmpty(AppArguments) ? "-- " + AppArguments : string.Empty);
}

string appName = fileSystem.GetFileName(appBundleItem.ItemSpec);
string helixCommand = GetHelixCommand(appName, targets, testTimeout, launchTimeout, includesTestRunner, expectedExitCode);
string helixCommand = GetHelixCommand(appName, targets, testTimeout, launchTimeout, includesTestRunner, expectedExitCode, resetSimulator);
string payloadArchivePath = await CreateZipArchiveOfFolder(zipArchiveManager, fileSystem, appFolderPath, customCommands);

Log.LogMessage($"Creating work item with properties Identity: {workItemName}, Payload: {appFolderPath}, Command: {helixCommand}");
Expand All @@ -166,13 +177,22 @@ private async Task<ITaskItem> PrepareWorkItem(
});
}

private string GetHelixCommand(string appName, string targets, TimeSpan testTimeout, TimeSpan launchTimeout, bool includesTestRunner, int expectedExitCode) =>
private string GetHelixCommand(
string appName,
string targets,
TimeSpan testTimeout,
TimeSpan launchTimeout,
bool includesTestRunner,
int expectedExitCode,
bool resetSimulator)
=>
$"chmod +x {EntryPointScript} && ./{EntryPointScript} " +
$"--app \"{appName}\" " +
$"--targets \"{targets}\" " +
$"--timeout \"{testTimeout}\" " +
$"--launch-timeout \"{launchTimeout}\" " +
(includesTestRunner ? "--includes-test-runner " : string.Empty) +
(resetSimulator ? "--reset-simulator" : string.Empty) +
$"--expected-exit-code \"{expectedExitCode}\" " +
(!string.IsNullOrEmpty(XcodeVersion) ? $" --xcode-version \"{XcodeVersion}\"" : string.Empty) +
(!string.IsNullOrEmpty(AppArguments) ? $" --app-arguments \"{AppArguments}\"" : string.Empty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ To execute .app bundles, declare one or more `XHarnessAppBundleToTest` items:
The `<Targets>` metadata is a required configuration that tells XHarness which kind of device/Simulator to target.
Use the XHarness CLI help command to find more (see the `--targets` option).

You can also specify some metadata that will help you configure the run better:
You can also specify some additional metadata that will help you configure the run better:

```xml
<ItemGroup>
Expand All @@ -89,6 +89,10 @@ You can also specify some metadata that will help you configure the run better:
<!-- Optional: For apps that don't contain unit tests, they can be run using the `apple run` command instead of `apple test` -->
<!-- Default is true -->
<IncludesTestRunner>false</IncludesTestRunner>

<!-- Optional: Before and after the run, erases all simulator data and resets it for a clean state -->
<!-- Default is false -->
<ResetSimulator>true</ResetSimulator>
</XHarnessAppBundleToTest>
</ItemGroup>
```
Expand Down Expand Up @@ -128,7 +132,7 @@ To execute .apks, declare one or more `XHarnessApkToTest` items:
</ItemGroup>
```

You can also specify some metadata that will help you configure the run better:
You can also specify some additional metadata that will help you configure the run better:

```xml
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ xcode_version=''
app_arguments=''
expected_exit_code=0
includes_test_runner=false
reset_simulator=false

while [[ $# -gt 0 ]]; do
opt="$(echo "$1" | tr "[:upper:]" "[:lower:]")"
Expand Down Expand Up @@ -59,6 +60,9 @@ while [[ $# -gt 0 ]]; do
--includes-test-runner)
includes_test_runner=true
;;
--reset-simulator)
reset_simulator=true
;;
esac
shift
done
Expand Down