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

feat: Improve hot-realod testing reliability #133

Merged
merged 4 commits into from
Nov 9, 2023
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
14 changes: 14 additions & 0 deletions src/TestApp/shared/FilterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ public class FilterTests
[DataRow("abc ; g.h.i", "g.h", false)]
[DataRow("abc ; g.h.i", "g.h.i", true)]
[DataRow("abc ; g.h.i", "abc.def.g.h.i", true)]

[DataRow("!abc", "abc.def.g.h.i", false)]
[DataRow("abc & !def", "abc.def.g.h.i", false)]
[DataRow("!abc & def", "abc.def.g.h.i", false)]
[DataRow("abc & !defg", "abc.def.g.h.i", true)]
[DataRow("!abc & defg", "abc.def.g.h.i", false)]
[DataRow("abcd & !def", "abc.def.g.h.i", false)]
[DataRow("!abcd & def", "abc.def.g.h.i", true)]
[DataRow("abc | !def", "abc.def.g.h.i", true)]
[DataRow("!abc | def", "abc.def.g.h.i", true)]
[DataRow("abc | !defg", "abc.def.g.h.i", true)]
[DataRow("!abc | defg", "abc.def.g.h.i", false)]
[DataRow("abcd | !def", "abc.def.g.h.i", false)]
[DataRow("!abcd | def", "abc.def.g.h.i", true)]
public void When_ParseAndMatch(string filter, string method, bool expectedResult)
{
UnitTestFilter sut = filter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private static async Task RunTestsAndExit(string testsConfigRaw, string outputPa
#pragma warning restore CA1416 // Validate platform compatibility

// Wait for the app to init it-self
await Task.Delay(500, ct.Token).ConfigureAwait(false);
await Task.Delay(2000, ct.Token).ConfigureAwait(false);
for (var i = 0; Window.Current is null && i < 100; i++)
{
await Task.Delay(50, ct.Token).ConfigureAwait(false);
Expand Down
4 changes: 4 additions & 0 deletions src/Uno.UI.RuntimeTests.Engine.Library/Engine/TestCase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#nullable enable

#if !IS_UNO_RUNTIMETEST_PROJECT
#pragma warning disable
#endif

using System;
using System.Linq;
using Windows.Devices.Input;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#nullable enable

#if !IS_UNO_RUNTIMETEST_PROJECT
#pragma warning disable
#endif

using System;
using System.Linq;

Expand Down
6 changes: 5 additions & 1 deletion src/Uno.UI.RuntimeTests.Engine.Library/Engine/TestResult.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System;
#if !IS_UNO_RUNTIMETEST_PROJECT
#pragma warning disable
# endif

using System;
using System.Linq;

namespace Uno.UI.RuntimeTests;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#if !UNO_RUNTIMETESTS_DISABLE_UI

#if !IS_UNO_RUNTIMETEST_PROJECT
#pragma warning disable
#endif

using System;
using System.Collections.Generic;
using System.IO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#if !UNO_RUNTIMETESTS_DISABLE_UI

#if !IS_UNO_RUNTIMETEST_PROJECT
#pragma warning disable
#endif

public sealed partial class UnitTestsControl
{
private class TestRun
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#if !UNO_RUNTIMETESTS_DISABLE_UI

#nullable enable

#if !IS_UNO_RUNTIMETEST_PROJECT
#pragma warning disable
#endif
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously

using System;
Expand Down Expand Up @@ -129,8 +133,10 @@
#endif
}

#pragma warning disable CA2201 // Do not raise reserved exception types
static void FailCore(string stackTrace, string message, string detailMessage, string errorSource)
=> throw new Exception($"{message} ({detailMessage}) {stackTrace}");
#pragma warning restore CA2201

public bool IsRunningOnCI
{
Expand Down Expand Up @@ -321,7 +327,7 @@
Text = $"{testClass.Name} ({testClass.Assembly.GetName().Name})",
Foreground = new SolidColorBrush(Colors.White),
FontSize = 16d,
IsTextSelectionEnabled = true

Check warning on line 330 in src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/UnitTestsControl.cs

View workflow job for this annotation

GitHub Actions / build

Microsoft.UI.Xaml.Controls.TextBlock.IsTextSelectionEnabled is not implemented in Uno (https://aka.platform.uno/notimplemented?m=Microsoft.UI.Xaml.Controls.TextBlock.IsTextSelectionEnabled) (https://aka.platform.uno/notimplemented)

Check warning on line 330 in src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/UnitTestsControl.cs

View workflow job for this annotation

GitHub Actions / build

Microsoft.UI.Xaml.Controls.TextBlock.IsTextSelectionEnabled is not implemented in Uno (https://aka.platform.uno/notimplemented?m=Microsoft.UI.Xaml.Controls.TextBlock.IsTextSelectionEnabled) (https://aka.platform.uno/notimplemented)
};

testResults.Children.Add(testResultBlock);
Expand Down Expand Up @@ -377,7 +383,7 @@
FontFamily = new FontFamily("Courier New"),
Margin = new Thickness(8, 0, 0, 0),
Foreground = new SolidColorBrush(Colors.LightGray),
IsTextSelectionEnabled = true

Check warning on line 386 in src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/UnitTestsControl.cs

View workflow job for this annotation

GitHub Actions / build

Microsoft.UI.Xaml.Controls.TextBlock.IsTextSelectionEnabled is not implemented in Uno (https://aka.platform.uno/notimplemented?m=Microsoft.UI.Xaml.Controls.TextBlock.IsTextSelectionEnabled) (https://aka.platform.uno/notimplemented)

Check warning on line 386 in src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/UnitTestsControl.cs

View workflow job for this annotation

GitHub Actions / build

Microsoft.UI.Xaml.Controls.TextBlock.IsTextSelectionEnabled is not implemented in Uno (https://aka.platform.uno/notimplemented?m=Microsoft.UI.Xaml.Controls.TextBlock.IsTextSelectionEnabled) (https://aka.platform.uno/notimplemented)
};

var retriesText = _currentRun.CurrentRepeatCount != 0 ? $" (Retried {_currentRun.CurrentRepeatCount} time(s))" : "";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#nullable enable

#if !IS_UNO_RUNTIMETEST_PROJECT
#pragma warning disable
#endif

using System;
using System.ComponentModel;
using System.Diagnostics;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#if !UNO_RUNTIMETESTS_DISABLE_UI

#if !IS_UNO_RUNTIMETEST_PROJECT
#pragma warning disable
#endif

using System;
using System.Collections.Generic;
using System.Text;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#nullable enable

#if !IS_UNO_RUNTIMETEST_PROJECT
#pragma warning disable
#endif

using System;
using System.Linq;
using System.Reflection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#nullable enable

#if !IS_UNO_RUNTIMETEST_PROJECT
#pragma warning disable
#endif

using System;
using System.Linq;

Expand Down
55 changes: 42 additions & 13 deletions src/Uno.UI.RuntimeTests.Engine.Library/Engine/UnitTestFilter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#if !UNO_RUNTIMETESTS_DISABLE_UI || !UNO_RUNTIMETESTS_DISABLE_EMBEDDEDRUNNER

#if !IS_UNO_RUNTIMETEST_PROJECT
#pragma warning disable
#endif

using System;
using System.Linq;
using System.Reflection;
Expand All @@ -8,7 +13,7 @@ namespace Uno.UI.RuntimeTests;
public record UnitTestFilter
{
private readonly IUnitTestEngineFilter _filter;
private static readonly char[] _separators = { '(', ')', '&', '|', ';' };
private static readonly char[] _separators = { '(', ')', '&', '|', ';', '!' };

private UnitTestFilter(IUnitTestEngineFilter filter)
{
Expand Down Expand Up @@ -44,36 +49,42 @@ private static IUnitTestEngineFilter Parse(string? syntax)
else
{
var index = 0;
return Parse(ref index, syntax.AsSpan());
var pending = default(IUnitTestEngineFilter?);
var stx = syntax.AsSpan();
do
{
pending = ReadToken(pending, ref index, stx);
} while (index < syntax.Length);

return pending;
}
}

private static IUnitTestEngineFilter Parse(ref int index, ReadOnlySpan<char> syntax)
private static IUnitTestEngineFilter ReadToken(IUnitTestEngineFilter? pending, ref int index, ReadOnlySpan<char> syntax)
{
// Simple syntax parser ... that does not have any operator priority!

var pending = default(IUnitTestEngineFilter?);
for (; index < syntax.Length; index++)
{
switch (syntax[index])
{
case '(':
index++;
pending = Parse(ref index, syntax);
pending = ReadToken(null, ref index, syntax);
break;

//case ' ':
// break;
case ' ':
break;

case '&' when pending is not null:
index++;
pending = new AndFilter(pending, Parse(ref index, syntax));
pending = new AndFilter(pending, ReadToken(null, ref index, syntax));
break;

case ';' when pending is not null: // Legacy support
case '|' when pending is not null:
index++;
pending = new OrFilter(pending, Parse(ref index, syntax));
pending = new OrFilter(pending, ReadToken(null, ref index, syntax));
break;

case ')' when pending is not null:
Expand All @@ -82,13 +93,25 @@ private static IUnitTestEngineFilter Parse(ref int index, ReadOnlySpan<char> syn
case ')':
return new NullFilter();

case '!':
index++;
pending = new NotFilter(ReadToken(null, ref index, syntax));
break;

default:
{
var j = index;
for (; j < syntax.Length && !_separators.Contains(syntax[j]); j++) { }
pending = new TextFilter(syntax.Slice(index, j - index).ToString().Trim());
index = j - 1;
break;
for (; j < syntax.Length; j++)
{
if (_separators.Contains(syntax[j]))
{
j--;
break;
}
}
var text = syntax.Slice(index, j - index).ToString().TrimEnd();
index = j;
return text is { Length: > 0 } ? new TextFilter(text) : default(NullFilter);
}
}
}
Expand All @@ -113,6 +136,12 @@ private readonly record struct OrFilter(IUnitTestEngineFilter Left, IUnitTestEng
public override string ToString() => $"({Left} | {Right})";
}

private readonly record struct NotFilter(IUnitTestEngineFilter Filter) : IUnitTestEngineFilter
{
public bool IsMatch(string methodFullname) => !Filter.IsMatch(methodFullname);
public override string ToString() => $"!({Filter})";
}

private readonly record struct TextFilter(string Text) : IUnitTestEngineFilter
{
public bool IsMatch(string methodFullname) => methodFullname.Contains(Text, StringComparison.InvariantCultureIgnoreCase);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#if !UNO_RUNTIMETESTS_DISABLE_UI

#nullable enable
#if !IS_UNO_RUNTIMETEST_PROJECT
#pragma warning disable
#endif

using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#nullable enable

#if !IS_UNO_RUNTIMETEST_PROJECT
#pragma warning disable
#endif

using System;

namespace Uno.UI.RuntimeTests;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#nullable enable

#if !IS_UNO_RUNTIMETEST_PROJECT
#pragma warning disable
#endif

using System;

namespace Uno.UI.RuntimeTests;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#nullable enable

#if !IS_UNO_RUNTIMETEST_PROJECT
#pragma warning disable
#endif

using System;

namespace Uno.UI.RuntimeTests;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#nullable enable

#if !IS_UNO_RUNTIMETEST_PROJECT
#pragma warning disable
#endif

using System;

namespace Uno.UI.RuntimeTests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<Pack>true</Pack>
<PackagePath>build</PackagePath>
</Content>
<Content Include="buildTransitive\*.*">
<Pack>true</Pack>
<PackagePath>buildTransitive</PackagePath>
</Content>
<Content Include="..\Uno.UI.RuntimeTests.Engine.Library\**\*.cs">
<Pack>true</Pack>
<Visible>false</Visible>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,4 @@
<Error Text="The Uno.UI or Uno.WinUI packages must be referenced in order to use the Uno.UI.RuntimeTests.Engine package"
Condition="'$(PkgUno_WinUI)'=='' and '$(PkgUno_UI)'==''"/>
</Target>

<PropertyGroup Condition="'$(PkgUno_UI_DevServer)' != '' OR '$(PkgUno_WinUI_DevServer)' != ''">
<DefineConstants >$(DefineConstants);HAS_UNO_DEVSERVER</DefineConstants>
<UnoDevServer_IncludeProjectConfiguration>true</UnoDevServer_IncludeProjectConfiguration>
<UnoDevServer_IncludeServerProcessorsConfiguration>true</UnoDevServer_IncludeServerProcessorsConfiguration>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>
<PropertyGroup Condition="'$(PkgUno_UI_DevServer)' != '' OR '$(PkgUno_WinUI_DevServer)' != ''">
<DefineConstants >$(DefineConstants);HAS_UNO_DEVSERVER</DefineConstants>
<UnoForceHotReloadCodeGen>true</UnoForceHotReloadCodeGen>
<UnoForceIncludeProjectConfiguration>true</UnoForceIncludeProjectConfiguration>
<UnoForceIncludeServerProcessorsConfiguration>true</UnoForceIncludeServerProcessorsConfiguration>
</PropertyGroup>
</Project>
Loading