Skip to content

Commit

Permalink
Merge pull request #168 from unoplatform/dev/dr/unoSupport
Browse files Browse the repository at this point in the history
Avoid secondary app init if test class has been ignored
  • Loading branch information
dr1rrb committed Feb 12, 2024
2 parents 0d96706 + 1a43cdd commit 102871c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/TestApp/shared/FilterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class FilterTests
[DataRow("!abcd | def", "abc.def.g.h.i", true)]
public void When_ParseAndMatch(string filter, string method, bool expectedResult)
{
UnitTestFilter sut = filter;
UnitTestFilter sut = filter;
var result = sut.IsMatch(method);

Assert.AreEqual(expectedResult, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ private DevServer(global::System.Diagnostics.Process process, int port)
dir,
log);

return GetConfigurationValue(data, "RemoteControlHostPath") is { Length: > 0 } path
? path
return GetConfigurationValue(data, "RemoteControlHostPath") is { Length: > 0 } path
? path
: throw new global::System.InvalidOperationException("Failed to get remote control host path");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ private static Color GetTestResultColor(TestResult testResult)

public async Task RunTestsForInstance(object testClassInstance)
{
#pragma warning disable CA1849
Interlocked.Exchange(ref _cts, new CancellationTokenSource())?.Cancel(); // cancel any previous CTS

testResults.Children.Clear();
Expand Down Expand Up @@ -718,11 +719,9 @@ private async Task ExecuteTestsForInstance(
? ConsoleOutputRecorder.Start()
: default;

var tests = (config.Filter is null
? testClassInfo.Tests
: testClassInfo.Tests.Where(test => config.Filter.IsMatch(test)))
.Select(method => new UnitTestMethodInfo(instance, method))
.ToArray();
var tests = config.Filter is null
? testClassInfo.Tests
: testClassInfo.Tests.Where(test => config.Filter.IsMatch(test.Method)).ToArray();

if (tests.Length <= 0 || testClassInfo.Type == null)
{
Expand All @@ -732,7 +731,9 @@ private async Task ExecuteTestsForInstance(
ReportTestClass(testClassInfo.Type.GetTypeInfo());
_ = ReportMessage($"Running {tests.Length} test methods");

if (testClassInfo.RunsInSecondaryApp is { } secondaryApp && !IsSecondaryApp)
if (testClassInfo.RunsInSecondaryApp is { } secondaryApp
&& !IsSecondaryApp
&& (config.IsRunningIgnored || testClassInfo.Tests.Any(test => !test.IsIgnored(out _))))
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public partial class UnitTestDispatcherCompat

#if WINDOWS_WINUI || HAS_UNO_WINUI

private readonly Windows.UI.Core.CoreDispatcher? _dispatcher;
public UnitTestDispatcherCompat(_Impl impl, Windows.UI.Core.CoreDispatcher? dispatcher = null)
private readonly Windows.UI.Core.CoreDispatcher? _dispatcher;
public UnitTestDispatcherCompat(_Impl impl, Windows.UI.Core.CoreDispatcher? dispatcher = null)
{
this._impl = impl;
this._dispatcher = dispatcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public UnitTestClassInfo(
{
Type = type;
TestClassName = Type?.Name ?? "(null)";
Tests = tests ?? Array.Empty<MethodInfo>();
Tests = tests?.Select(test => new UnitTestMethodInfo(test)).ToArray() ?? Array.Empty<UnitTestMethodInfo>();
Initialize = initialize;
Cleanup = cleanup;

Expand All @@ -33,7 +33,7 @@ public UnitTestClassInfo(

public Type? Type { get; }

public MethodInfo[] Tests { get; }
public UnitTestMethodInfo[] Tests { get; }

public MethodInfo? Initialize { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

namespace Uno.UI.RuntimeTests;

internal record UnitTestMethodInfo
public record UnitTestMethodInfo
{
private readonly List<ITestDataSource> _casesParameters;
private readonly IList<PointerDeviceType> _injectedPointerTypes;

public UnitTestMethodInfo(object testClassInstance, MethodInfo method)
public UnitTestMethodInfo(MethodInfo method)
{
Method = method;
RunsOnUIThread =
Expand All @@ -36,7 +36,7 @@ public UnitTestMethodInfo(object testClassInstance, MethodInfo method)
.SingleOrDefault()
?.ExceptionType;

_casesParameters = method
_casesParameters = method
.GetCustomAttributes()
.Where(x => x is ITestDataSource)
.Cast<ITestDataSource>()
Expand Down Expand Up @@ -80,7 +80,7 @@ public bool IsIgnored(out string ignoreMessage)
return false;
}

public IEnumerable<TestCase> GetCases(CancellationToken ct)
internal IEnumerable<TestCase> GetCases(CancellationToken ct)
{
List<TestCase> cases = new();

Expand All @@ -98,7 +98,7 @@ public IEnumerable<TestCase> GetCases(CancellationToken ct)
.GetData(Method)
.Select(caseData => new TestCase
{
Parameters = caseData,
Parameters = caseData,
DisplayName = testCaseSource.GetDisplayName(Method, caseData)
});

Expand Down

0 comments on commit 102871c

Please sign in to comment.