forked from ElectronNET/Electron.NET
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIntegrationFactAttribute.cs
More file actions
101 lines (87 loc) · 2.74 KB
/
Copy pathIntegrationFactAttribute.cs
File metadata and controls
101 lines (87 loc) · 2.74 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
namespace ElectronNET.IntegrationTests.Common
{
using System.Runtime.InteropServices;
using Xunit.Sdk;
/// <summary>
/// Custom fact attribute with a default timeout of 20 seconds, allowing tests to be skipped on specific environments.
/// </summary>
/// <seealso cref="Xunit.FactAttribute" />
[AttributeUsage(AttributeTargets.Method)]
[XunitTestCaseDiscoverer("Xunit.Sdk.SkippableFactDiscoverer", "Xunit.SkippableFact")]
internal sealed class IntegrationFactAttribute : FactAttribute
{
private static readonly bool IsOnWsl;
private static readonly bool IsOnCI;
static IntegrationFactAttribute()
{
IsOnWsl = DetectWsl();
IsOnCI = DetectCI();
}
/// <summary>
/// Initializes a new instance of the <see cref="IntegrationFactAttribute" /> class.
/// </summary>
public IntegrationFactAttribute()
{
this.Timeout = 20_000;
}
public bool SkipOnWsl { get; set; }
public bool SkipOnCI { get; set; }
/// <summary>
/// Marks the test so that it will not be run, and gets or sets the skip reason
/// </summary>
public override string Skip {
get
{
if (IsOnWsl && this.SkipOnWsl)
{
return "Skipping test on WSL environment.";
}
if (IsOnCI && this.SkipOnCI)
{
return "Skipping test on CI environment.";
}
return base.Skip;
}
set
{
base.Skip = value;
}
}
private static bool DetectWsl()
{
try
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return false;
}
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WSL_DISTRO_NAME")) ||
!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WSL_INTEROP")))
{
return true;
}
return false;
}
catch
{
return false;
}
}
private static bool DetectCI()
{
try
{
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TF_BUILD")) ||
!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GITHUB_ACTIONS")))
{
return true;
}
return false;
}
catch
{
return false;
}
}
}
}