Skip to content

Commit

Permalink
Merge pull request #121 from unoplatform/dev/dr/2ndAppEn
Browse files Browse the repository at this point in the history
chore: Change compile constants confition to improve usability + rely…
  • Loading branch information
dr1rrb authored Nov 6, 2023
2 parents b0b1564 + 3aa80fe commit 580dd14
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
3 changes: 0 additions & 3 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
<AnalysisLevel>latest</AnalysisLevel>
<AnalysisModePerformance>AllEnabledByDefault</AnalysisModePerformance>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.0-preview1.22403.2" PrivateAssets="All" />
</ItemGroup>

<Choose>
<When Condition="'$(IsTestProject)' != 'true' and '$(SourceLinkEnabled)' != 'false' and '$(IsSampleProject)' != 'true'">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#if !UNO_RUNTIMETESTS_DISABLE_UI && (__SKIA__ || IS_SECONDARY_APP_SUPPORTED)
#if !UNO_RUNTIMETESTS_DISABLE_UI && HAS_UNO_WINUI // HAS_UNO_WINUI: exclude non net7 platforms
#nullable enable

#if !IS_UNO_RUNTIMETEST_PROJECT
#pragma warning disable
#endif
#pragma warning disable CA1848 // Log perf
#pragma warning disable CS1998 // No await
namespace Uno.UI.RuntimeTests.Internal.Helpers;

/// <summary>
Expand All @@ -14,6 +15,9 @@ namespace Uno.UI.RuntimeTests.Internal.Helpers;
/// This class is intended to be used only by the the test engine itself and should not be used by applications.
/// API contract is not guaranteed and might change in future releases.
/// </remarks>
[global::System.Runtime.Versioning.SupportedOSPlatform("windows")]
[global::System.Runtime.Versioning.SupportedOSPlatform("linux")]
[global::System.Runtime.Versioning.SupportedOSPlatform("freeBSD")]
internal sealed partial class DevServer : global::System.IAsyncDisposable
{
private static readonly global::Microsoft.Extensions.Logging.ILogger _log = global::Uno.Extensions.LogExtensionPoint.Log(typeof(DevServer));
Expand All @@ -28,7 +32,7 @@ internal sealed partial class DevServer : global::System.IAsyncDisposable
public static async global::System.Threading.Tasks.Task<DevServer> Start(global::System.Threading.CancellationToken ct)
{
#if !HAS_UNO_DEVSERVER
throw new NotSupportedException("Dev server has not been referenced.");
throw new global::System.NotSupportedException("Dev server has not been referenced.");
#else
var path = await GetDevServer(ct);
var port = GetTcpPort();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !UNO_RUNTIMETESTS_DISABLE_UI && (__SKIA__ || IS_SECONDARY_APP_SUPPORTED)
#if !UNO_RUNTIMETESTS_DISABLE_UI && HAS_UNO_WINUI // HAS_UNO_WINUI: exclude non net7 platforms
#nullable enable

#if !IS_UNO_RUNTIMETEST_PROJECT
Expand All @@ -24,6 +24,9 @@ namespace Uno.UI.RuntimeTests.Internal.Helpers;
/// This class is intended to be used only by the the test engine itself and should not be used by applications.
/// API contract is not guaranteed and might change in future releases.
/// </remarks>
[global::System.Runtime.Versioning.SupportedOSPlatform("windows")]
[global::System.Runtime.Versioning.SupportedOSPlatform("linux")]
[global::System.Runtime.Versioning.SupportedOSPlatform("freeBSD")]
internal static partial class ProcessHelper
{
public static async Task<string> ExecuteAsync(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#if !UNO_RUNTIMETESTS_DISABLE_UI
using System;

#if !UNO_RUNTIMETESTS_DISABLE_UI
#nullable enable

#if !IS_UNO_RUNTIMETEST_PROJECT
#pragma warning disable
#endif

#if __SKIA__
#define IS_SECONDARY_APP_SUPPORTED
#endif

namespace Uno.UI.RuntimeTests.Internal.Helpers;

/// <summary>
Expand All @@ -23,9 +21,9 @@ internal static partial class SecondaryApp
/// <summary>
/// Gets a boolean indicating if the current platform supports running tests in a secondary app.
/// </summary>
public static bool IsSupported => // Note: not as const to avoid "CS0162 unreachable code" warning
#if IS_SECONDARY_APP_SUPPORTED
true;
public static bool IsSupported =>
#if HAS_UNO_WINUI // HAS_UNO_WINUI: exclude non net7 platforms
global::System.OperatingSystem.IsWindows() || global::System.OperatingSystem.IsLinux() || global::System.OperatingSystem.IsFreeBSD();
#else
false;
#endif
Expand All @@ -39,9 +37,17 @@ internal static partial class SecondaryApp
/// <returns>The test results.</returns>
internal static async global::System.Threading.Tasks.Task<TestCaseResult[]> RunTest(UnitTestEngineConfig config, global::System.Threading.CancellationToken ct, bool isAppVisible = false)
{
#if !IS_SECONDARY_APP_SUPPORTED
throw new global::System.NotSupportedException("Secondary app is not supported on this platform.");
if (!IsSupported)
{
throw new global::System.NotSupportedException("Secondary app is not supported on this platform.");
}

#if !HAS_UNO_WINUI // HAS_UNO_WINUI: exclude non net7 platforms
#pragma warning disable CA1825 // Array.Empty not available on UWP
return new TestCaseResult[0]; // Non reachable code.
#pragma warning restore CA1825
#else
#pragma warning disable CA1416 // Validate platform compatibility => This is checked by the IsSupported property.
// First we fetch and start the dev-server (needed to HR tests for instance)
await using var devServer = await DevServer.Start(ct);

Expand Down Expand Up @@ -98,6 +104,7 @@ internal static partial class SecondaryApp
await childProcess.ExecuteAndLogAsync(typeof(SecondaryApp).CreateScopedLog($"CHILD_TEST_APP_{(global::System.Threading.Interlocked.Increment(ref _instance)):D2}"), ct);

return testOutput;
#pragma warning restore CA1416 // Validate platform compatibility
#endif
}
}
Expand Down

0 comments on commit 580dd14

Please sign in to comment.