|
1 | | -using System; |
| 1 | +#nullable enable |
| 2 | +using System; |
2 | 3 | using System.Collections.Generic; |
| 4 | +using System.Runtime.InteropServices; |
3 | 5 | using Microsoft.Extensions.Configuration; |
4 | | -using Xunit; |
5 | 6 |
|
6 | 7 | namespace Xunit; |
7 | 8 |
|
@@ -45,6 +46,78 @@ public CIFactAttribute() |
45 | 46 | } |
46 | 47 | } |
47 | 48 |
|
| 49 | +public class RuntimeFactAttribute : FactAttribute |
| 50 | +{ |
| 51 | + /// <summary> |
| 52 | + /// Use <c>nameof(OSPLatform.Windows|Linux|OSX|FreeBSD)</c> |
| 53 | + /// </summary> |
| 54 | + public RuntimeFactAttribute(string osPlatform) |
| 55 | + { |
| 56 | + if (osPlatform != null && !RuntimeInformation.IsOSPlatform(OSPlatform.Create(osPlatform))) |
| 57 | + Skip = $"Only running on {osPlatform}."; |
| 58 | + } |
| 59 | + |
| 60 | + public RuntimeFactAttribute(Architecture architecture) |
| 61 | + { |
| 62 | + if (RuntimeInformation.ProcessArchitecture != architecture) |
| 63 | + Skip = $"Requires {architecture} but was {RuntimeInformation.ProcessArchitecture}."; |
| 64 | + } |
| 65 | + |
| 66 | + /// <summary> |
| 67 | + /// Empty constructor for use in combination with RuntimeIdentifier property. |
| 68 | + /// </summary> |
| 69 | + public RuntimeFactAttribute() { } |
| 70 | + |
| 71 | + /// <summary> |
| 72 | + /// Sets the runtime identifier the test requires to run. |
| 73 | + /// </summary> |
| 74 | + public string? RuntimeIdentifier |
| 75 | + { |
| 76 | + get => RuntimeInformation.RuntimeIdentifier; |
| 77 | + set |
| 78 | + { |
| 79 | + if (value != null && RuntimeInformation.RuntimeIdentifier != value) |
| 80 | + Skip += $"Requires {value} but was {RuntimeInformation.RuntimeIdentifier}."; |
| 81 | + } |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +public class RuntimeTheoryAttribute : TheoryAttribute |
| 86 | +{ |
| 87 | + /// <summary> |
| 88 | + /// Use <c>nameof(OSPLatform.Windows|Linux|OSX|FreeBSD)</c> |
| 89 | + /// </summary> |
| 90 | + public RuntimeTheoryAttribute(string osPlatform) |
| 91 | + { |
| 92 | + if (osPlatform != null && !RuntimeInformation.IsOSPlatform(OSPlatform.Create(osPlatform))) |
| 93 | + Skip = $"Only running on {osPlatform}."; |
| 94 | + } |
| 95 | + |
| 96 | + public RuntimeTheoryAttribute(Architecture architecture) |
| 97 | + { |
| 98 | + if (RuntimeInformation.ProcessArchitecture != architecture) |
| 99 | + Skip = $"Requires {architecture} but was {RuntimeInformation.ProcessArchitecture}."; |
| 100 | + } |
| 101 | + |
| 102 | + /// <summary> |
| 103 | + /// Empty constructor for use in combination with RuntimeIdentifier property. |
| 104 | + /// </summary> |
| 105 | + public RuntimeTheoryAttribute() { } |
| 106 | + |
| 107 | + /// <summary> |
| 108 | + /// Sets the runtime identifier the test requires to run. |
| 109 | + /// </summary> |
| 110 | + public string? RuntimeIdentifier |
| 111 | + { |
| 112 | + get => RuntimeInformation.RuntimeIdentifier; |
| 113 | + set |
| 114 | + { |
| 115 | + if (value != null && RuntimeInformation.RuntimeIdentifier != value) |
| 116 | + Skip += $"Requires {value} but was {RuntimeInformation.RuntimeIdentifier}."; |
| 117 | + } |
| 118 | + } |
| 119 | +} |
| 120 | + |
48 | 121 | public class SecretsTheoryAttribute : TheoryAttribute |
49 | 122 | { |
50 | 123 | public SecretsTheoryAttribute(params string[] secrets) |
|
0 commit comments