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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ obj
*.nupkg
artifacts/
.packages/
.nuget/
2 changes: 1 addition & 1 deletion Xamarin.MacDev/RuntimeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public RuntimeService (ICustomLogger log)
/// </summary>
public List<SimulatorRuntimeInfo> List (bool availableOnly = false)
{
var json = simctl.Run ("list", "runtimes", "--json");
var json = simctl.RunJson ("list", "runtimes");
if (json is null)
return new List<SimulatorRuntimeInfo> ();

Expand Down
36 changes: 36 additions & 0 deletions Xamarin.MacDev/SimCtl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,40 @@ public SimCtl (ICustomLogger log)
return null;
}
}

/// <summary>
/// Runs <c>xcrun simctl {args}</c> with <c>--json --json-output=&lt;file&gt;</c>
/// so that structured JSON output is written to a temp file instead of stdout.
/// Returns the file contents, or null on failure.
/// This is intended for <c>simctl list</c> subcommands that support <c>--json-output</c>.
/// </summary>
public string? RunJson (params string [] args)
{
var tempPath = Path.GetTempFileName ();
try {
var jsonArgs = new string [args.Length + 2];
Array.Copy (args, jsonArgs, args.Length);
jsonArgs [args.Length] = "--json";
jsonArgs [args.Length + 1] = "--json-output=" + tempPath;

var result = Run (jsonArgs);
if (result is null)
return null;

if (!File.Exists (tempPath)) {
log.LogInfo ("simctl did not produce JSON output file at '{0}'.", tempPath);
return null;
}

var content = File.ReadAllText (tempPath);
if (string.IsNullOrWhiteSpace (content)) {
log.LogInfo ("simctl produced an empty JSON output file at '{0}'.", tempPath);
return null;
}

return content;
} finally {
try { if (File.Exists (tempPath)) File.Delete (tempPath); } catch { }
}
}
}
2 changes: 1 addition & 1 deletion Xamarin.MacDev/SimulatorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public SimulatorService (ICustomLogger log)
/// </summary>
public List<SimulatorDeviceInfo> List (bool availableOnly = false)
{
var json = simctl.Run ("list", "devices", "--json");
var json = simctl.RunJson ("list", "devices");
if (json is null)
return new List<SimulatorDeviceInfo> ();

Expand Down
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
<NUnitAnalyzersVersion>4.3.0</NUnitAnalyzersVersion>
<NUnitConsoleRunnerVersion>3.18.1</NUnitConsoleRunnerVersion>
<NUnit3TestAdapterVersion>5.0.0</NUnit3TestAdapterVersion>
<MicrosoftNETTestSdkVersion>17.12.0</MicrosoftNETTestSdkVersion>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion tests/SimctlOutputParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public void LiveSimctlList_ParsesWithoutExceptions ()
// with no exceptions logged — per rolfbjarne review feedback
var logger = new TestLogger ();
var simctl = new SimCtl (logger);
var json = simctl.Run ("list", "--json");
var json = simctl.RunJson ("list");
Assert.That (json, Is.Not.Null, "simctl list --json should return output");

var devices = SimctlOutputParser.ParseDevices (json, logger);
Expand Down
6 changes: 5 additions & 1 deletion tests/tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<IsShipping>false</IsShipping>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<!-- Explicit Microsoft.NET.Test.Sdk is needed for testhost.runtimeconfig.json;
suppress NETSDK1023 on SDKs that implicitly reference it. -->
<NoWarn>$(NoWarn);NETSDK1023;NU1504</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkVersion)" />
<PackageReference Include="NUnit" Version="$(NUnitVersion)" />
<PackageReference Include="NUnit.Analyzers" Version="$(NUnitAnalyzersVersion)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit.ConsoleRunner" Version="$(NUnitConsoleRunnerVersion)" />
<PackageReference Include="NUnit3TestAdapter" Version="$(NUnit3TestAdapterVersion)" />
</ItemGroup>
<ItemGroup>
Expand Down
Loading