-
Notifications
You must be signed in to change notification settings - Fork 388
/
Copy pathSkipOnOS.cs
34 lines (28 loc) · 1.06 KB
/
SkipOnOS.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright (c) Toni Solarin-Sodara
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Runtime.InteropServices;
namespace Coverlet.Tests.Xunit.Extensions
{
public enum OS
{
Linux,
MacOS,
Windows
}
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)]
public class SkipOnOSAttribute : Attribute, ITestCondition
{
private readonly OS _os;
private readonly string _reason;
public SkipOnOSAttribute(OS os, string reason = "") => (_os, _reason) = (os, reason);
public bool IsMet => _os switch
{
OS.Linux => !RuntimeInformation.IsOSPlatform(OSPlatform.Linux),
OS.MacOS => !RuntimeInformation.IsOSPlatform(OSPlatform.OSX),
OS.Windows => !RuntimeInformation.IsOSPlatform(OSPlatform.Windows),
_ => throw new NotSupportedException($"Not supported OS {_os}")
};
public string SkipReason => $"OS not supported{(string.IsNullOrEmpty(_reason) ? "" : $", {_reason}")}";
}
}