|
| 1 | +using System.Threading.Tasks; |
| 2 | +using Microsoft.CodeAnalysis.CSharp; |
| 3 | +using Microsoft.CodeAnalysis.Testing; |
| 4 | + |
| 5 | +public partial class CSharpVerifier<TAnalyzer> |
| 6 | +{ |
| 7 | + // ----- Multi-version ----- |
| 8 | + |
| 9 | + /// <summary> |
| 10 | + /// Runs code for analysis, against xUnit.net v2 and v3 Runner Utility, using C# 6. |
| 11 | + /// </summary> |
| 12 | + /// <param name="source">The code to verify</param> |
| 13 | + /// <param name="diagnostics">The expected diagnostics (pass none for code that |
| 14 | + /// should not trigger)</param> |
| 15 | + public static async Task VerifyAnalyzerRunnerUtility( |
| 16 | + string source, |
| 17 | + params DiagnosticResult[] diagnostics) |
| 18 | + { |
| 19 | + await VerifyAnalyzerV2RunnerUtility(LanguageVersion.CSharp6, [source], diagnostics); |
| 20 | + await VerifyAnalyzerV3RunnerUtility(LanguageVersion.CSharp6, [source], diagnostics); |
| 21 | + } |
| 22 | + |
| 23 | + /// <summary> |
| 24 | + /// Runs code for analysis, against xUnit.net v2 and v3 Runner Utility, using the provided version of C#. |
| 25 | + /// </summary> |
| 26 | + /// <param name="languageVersion">The language version to compile with</param> |
| 27 | + /// <param name="source">The code to verify</param> |
| 28 | + /// <param name="diagnostics">The expected diagnostics (pass none for code that |
| 29 | + /// should not trigger)</param> |
| 30 | + public static async Task VerifyAnalyzerRunnerUtility( |
| 31 | + LanguageVersion languageVersion, |
| 32 | + string source, |
| 33 | + params DiagnosticResult[] diagnostics) |
| 34 | + { |
| 35 | + await VerifyAnalyzerV2RunnerUtility(languageVersion, [source], diagnostics); |
| 36 | + await VerifyAnalyzerV3RunnerUtility(languageVersion, [source], diagnostics); |
| 37 | + } |
| 38 | + |
| 39 | + /// <summary> |
| 40 | + /// Runs code for analysis, against xUnit.net v2 and v3 Runner Utility, using C# 6. |
| 41 | + /// </summary> |
| 42 | + /// <param name="sources">The code to verify</param> |
| 43 | + /// <param name="diagnostics">The expected diagnostics (pass none for code that |
| 44 | + /// should not trigger)</param> |
| 45 | + public static async Task VerifyAnalyzerRunnerUtility( |
| 46 | + string[] sources, |
| 47 | + params DiagnosticResult[] diagnostics) |
| 48 | + { |
| 49 | + await VerifyAnalyzerV2RunnerUtility(LanguageVersion.CSharp6, sources, diagnostics); |
| 50 | + await VerifyAnalyzerV3RunnerUtility(LanguageVersion.CSharp6, sources, diagnostics); |
| 51 | + } |
| 52 | + |
| 53 | + /// <summary> |
| 54 | + /// Runs code for analysis, against xUnit.net v2 and v3 Runner Utility, using the provided version of C#. |
| 55 | + /// </summary> |
| 56 | + /// <param name="languageVersion">The language version to compile with</param> |
| 57 | + /// <param name="sources">The code to verify</param> |
| 58 | + /// <param name="diagnostics">The expected diagnostics (pass none for code that |
| 59 | + /// should not trigger)</param> |
| 60 | + public static async Task VerifyAnalyzerRunnerUtility( |
| 61 | + LanguageVersion languageVersion, |
| 62 | + string[] sources, |
| 63 | + params DiagnosticResult[] diagnostics) |
| 64 | + { |
| 65 | + await VerifyAnalyzerV2RunnerUtility(languageVersion, sources, diagnostics); |
| 66 | + await VerifyAnalyzerV3RunnerUtility(languageVersion, sources, diagnostics); |
| 67 | + } |
| 68 | + |
| 69 | + // ----- v2 ----- |
| 70 | + |
| 71 | + /// <summary> |
| 72 | + /// Runs code for analysis, against xUnit.net v2 Runner Utility, using C# 6. |
| 73 | + /// </summary> |
| 74 | + /// <param name="source">The code to verify</param> |
| 75 | + /// <param name="diagnostics">The expected diagnostics (pass none for code that |
| 76 | + /// should not trigger)</param> |
| 77 | + public static Task VerifyAnalyzerV2RunnerUtility( |
| 78 | + string source, |
| 79 | + params DiagnosticResult[] diagnostics) => |
| 80 | + VerifyAnalyzerV2RunnerUtility(LanguageVersion.CSharp6, [source], diagnostics); |
| 81 | + |
| 82 | + /// <summary> |
| 83 | + /// Runs code for analysis, against xUnit.net v2, using the provided version of C#. |
| 84 | + /// </summary> |
| 85 | + /// <param name="languageVersion">The language version to compile with</param> |
| 86 | + /// <param name="source">The code to verify</param> |
| 87 | + /// <param name="diagnostics">The expected diagnostics (pass none for code that |
| 88 | + /// should not trigger)</param> |
| 89 | + public static Task VerifyAnalyzerV2RunnerUtility( |
| 90 | + LanguageVersion languageVersion, |
| 91 | + string source, |
| 92 | + params DiagnosticResult[] diagnostics) => |
| 93 | + VerifyAnalyzerV2RunnerUtility(languageVersion, [source], diagnostics); |
| 94 | + |
| 95 | + /// <summary> |
| 96 | + /// Runs code for analysis, against xUnit.net v2 Runner Utility, using C# 6. |
| 97 | + /// </summary> |
| 98 | + /// <param name="sources">The code to verify</param> |
| 99 | + /// <param name="diagnostics">The expected diagnostics (pass none for code that |
| 100 | + /// should not trigger)</param> |
| 101 | + public static Task VerifyAnalyzerV2RunnerUtility( |
| 102 | + string[] sources, |
| 103 | + params DiagnosticResult[] diagnostics) => |
| 104 | + VerifyAnalyzerV2RunnerUtility(LanguageVersion.CSharp6, sources, diagnostics); |
| 105 | + |
| 106 | + /// <summary> |
| 107 | + /// Runs code for analysis, against xUnit.net v2, using the provided version of C#. |
| 108 | + /// </summary> |
| 109 | + /// <param name="languageVersion">The language version to compile with</param> |
| 110 | + /// <param name="sources">The code to verify</param> |
| 111 | + /// <param name="diagnostics">The expected diagnostics (pass none for code that |
| 112 | + /// should not trigger)</param> |
| 113 | + public static Task VerifyAnalyzerV2RunnerUtility( |
| 114 | + LanguageVersion languageVersion, |
| 115 | + string[] sources, |
| 116 | + params DiagnosticResult[] diagnostics) |
| 117 | + { |
| 118 | + var test = new TestV2RunnerUtility(languageVersion); |
| 119 | + |
| 120 | + foreach (var source in sources) |
| 121 | + test.TestState.Sources.Add(source); |
| 122 | + |
| 123 | + test.TestState.ExpectedDiagnostics.AddRange(diagnostics); |
| 124 | + return test.RunAsync(); |
| 125 | + } |
| 126 | + |
| 127 | + // ----- v3 ----- |
| 128 | + |
| 129 | + /// <summary> |
| 130 | + /// Runs code for analysis, against xUnit.net v3 Runner Utility, using C# 6. |
| 131 | + /// </summary> |
| 132 | + /// <param name="source">The code to verify</param> |
| 133 | + /// <param name="diagnostics">The expected diagnostics (pass none for code that |
| 134 | + /// should not trigger)</param> |
| 135 | + public static Task VerifyAnalyzerV3RunnerUtility( |
| 136 | + string source, |
| 137 | + params DiagnosticResult[] diagnostics) => |
| 138 | + VerifyAnalyzerV3RunnerUtility(LanguageVersion.CSharp6, [source], diagnostics); |
| 139 | + |
| 140 | + /// <summary> |
| 141 | + /// Runs code for analysis, against xUnit.net v3 Runner Utility, using the provided version of C#. |
| 142 | + /// </summary> |
| 143 | + /// <param name="languageVersion">The language version to compile with</param> |
| 144 | + /// <param name="source">The code to verify</param> |
| 145 | + /// <param name="diagnostics">The expected diagnostics (pass none for code that |
| 146 | + /// should not trigger)</param> |
| 147 | + public static Task VerifyAnalyzerV3RunnerUtility( |
| 148 | + LanguageVersion languageVersion, |
| 149 | + string source, |
| 150 | + params DiagnosticResult[] diagnostics) => |
| 151 | + VerifyAnalyzerV3RunnerUtility(languageVersion, [source], diagnostics); |
| 152 | + |
| 153 | + /// <summary> |
| 154 | + /// Runs code for analysis, against xUnit.net v3 Runner Utility, using C# 6. |
| 155 | + /// </summary> |
| 156 | + /// <param name="languageVersion">The language version to compile with</param> |
| 157 | + /// <param name="sources">The code to verify</param> |
| 158 | + /// <param name="diagnostics">The expected diagnostics (pass none for code that |
| 159 | + /// should not trigger)</param> |
| 160 | + public static Task VerifyAnalyzerV3RunnerUtility( |
| 161 | + string[] sources, |
| 162 | + params DiagnosticResult[] diagnostics) => |
| 163 | + VerifyAnalyzerV3RunnerUtility(LanguageVersion.CSharp6, sources, diagnostics); |
| 164 | + |
| 165 | + /// <summary> |
| 166 | + /// Runs code for analysis, against xUnit.net v3 Runner Utility, using the provided version of C#. |
| 167 | + /// </summary> |
| 168 | + /// <param name="languageVersion">The language version to compile with</param> |
| 169 | + /// <param name="sources">The code to verify</param> |
| 170 | + /// <param name="diagnostics">The expected diagnostics (pass none for code that |
| 171 | + /// should not trigger)</param> |
| 172 | + public static Task VerifyAnalyzerV3RunnerUtility( |
| 173 | + LanguageVersion languageVersion, |
| 174 | + string[] sources, |
| 175 | + params DiagnosticResult[] diagnostics) |
| 176 | + { |
| 177 | + var test = new TestV3RunnerUtility(languageVersion); |
| 178 | + |
| 179 | + foreach (var source in sources) |
| 180 | + test.TestState.Sources.Add(source); |
| 181 | + |
| 182 | + test.TestState.ExpectedDiagnostics.AddRange(diagnostics); |
| 183 | + return test.RunAsync(); |
| 184 | + } |
| 185 | +} |
0 commit comments