Skip to content

Commit

Permalink
Fix platform fact/theory attributes.
Browse files Browse the repository at this point in the history
Throwing on `Skip` setter was causing all subsequent tests in class to be ignored.
  • Loading branch information
grokys committed Mar 13, 2023
1 parent e378bce commit 4c9bf8e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
13 changes: 11 additions & 2 deletions tests/Avalonia.IntegrationTests.Appium/PlatformFactAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal enum TestPlatforms
internal class PlatformFactAttribute : FactAttribute
{
private readonly string? _reason;
private string? _skip;

public PlatformFactAttribute(TestPlatforms platforms, string? reason = null)
{
Expand All @@ -28,8 +29,16 @@ public PlatformFactAttribute(TestPlatforms platforms, string? reason = null)

public override string? Skip
{
get => IsSupported() ? null : $"Ignored on {RuntimeInformation.OSDescription}" + (_reason is not null ? $" reason: \"{_reason}\"" : "");
set => throw new NotSupportedException();
get
{
if (_skip is not null)
return _skip;
if (!IsSupported())
return $"Ignored on {RuntimeInformation.OSDescription}" +
(_reason is not null ? $" reason: '{_reason}'" : "");
return null;
}
set => _skip = value;
}

private bool IsSupported()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ namespace Avalonia.IntegrationTests.Appium
{
internal class PlatformTheoryAttribute : TheoryAttribute
{
private string? _skip;

public PlatformTheoryAttribute(TestPlatforms platforms = TestPlatforms.All) => Platforms = platforms;

public TestPlatforms Platforms { get; }

public override string? Skip
{
get => IsSupported() ? null : $"Ignored on {RuntimeInformation.OSDescription}";
set => throw new NotSupportedException();
get
{
if (_skip is not null)
return _skip;
return !IsSupported() ? $"Ignored on {RuntimeInformation.OSDescription}" : null;
}
set => _skip = value;
}

private bool IsSupported()
Expand Down

0 comments on commit 4c9bf8e

Please sign in to comment.