A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

55 lines
1.5 KiB

#nullable enable
using System;
using System.Runtime.InteropServices;
using Xunit;
namespace Avalonia
{
[Flags]
internal enum TestPlatforms
{
Windows = 0x01,
MacOS = 0x02,
Linux = 0x04,
All = Windows | MacOS | Linux,
}
internal class PlatformFactAttribute : FactAttribute
{
private readonly string? _reason;
private string? _skip;
public PlatformFactAttribute(TestPlatforms platforms, string? reason = null)
{
_reason = reason;
Platforms = platforms;
}
public TestPlatforms Platforms { get; }
public override string? Skip
{
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()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return Platforms.HasFlag(TestPlatforms.Windows);
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
return Platforms.HasFlag(TestPlatforms.MacOS);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
return Platforms.HasFlag(TestPlatforms.Linux);
return false;
}
}
}