Skip to content

Commit e9aff57

Browse files
authored
Merge pull request #1166 from MattKotsenas/bugfix/readme-custom-verifier
Fix compliation errors in Testing README sample custom verifier
2 parents 6eb4858 + fa0788a commit e9aff57

File tree

1 file changed

+4
-74
lines changed

1 file changed

+4
-74
lines changed

src/Microsoft.CodeAnalysis.Testing/README.md

+4-74
Original file line numberDiff line numberDiff line change
@@ -198,77 +198,7 @@ verifier and test types. For example, [Microsoft/vs-threading](https://github.co
198198
Additional Files and metadata references in most of its tests, so it uses custom verifier and test types to allow the
199199
use of "basic use cases" for test scenarios that would otherwise be considered advanced.
200200

201-
```csharp
202-
public static class CSharpAnalyzerVerifier<TAnalyzer>
203-
where TAnalyzer : DiagnosticAnalyzer, new()
204-
{
205-
public static DiagnosticResult Diagnostic(string diagnosticId = null)
206-
=> CSharpAnalyzerVerifier<TAnalyzer, DefaultVerifier>.Diagnostic(diagnosticId);
207-
208-
public static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor)
209-
=> new DiagnosticResult(descriptor);
210-
211-
public static Task VerifyAnalyzerAsync(string source, params DiagnosticResult[] expected)
212-
{
213-
var test = new Test { TestCode = source };
214-
test.ExpectedDiagnostics.AddRange(expected);
215-
return test.RunAsync();
216-
}
217-
218-
// Code fix tests support both analyzer and code fix testing. This test class is derived from the code fix test
219-
// to avoid the need to maintain duplicate copies of the customization work.
220-
public class Test : CSharpCodeFixVerifier.Test<TAnalyzer, EmptyCodeFixProvider>
221-
{
222-
}
223-
}
224-
225-
public static class CSharpCodeFixVerifier<TAnalyzer, TCodeFix>
226-
where TAnalyzer : DiagnosticAnalyzer, new()
227-
where TCodeFix : CodeFixProvider, new()
228-
{
229-
public static DiagnosticResult Diagnostic(string diagnosticId = null)
230-
=> CSharpCodeFixVerifier<TAnalyzer, TCodeFix, DefaultVerifier>.Diagnostic(diagnosticId);
231-
232-
public static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor)
233-
=> new DiagnosticResult(descriptor);
234-
235-
public static Task VerifyAnalyzerAsync(string source, params DiagnosticResult[] expected)
236-
{
237-
var test = new CSharpAnalyzerVerifier<TAnalyzer>.Test { TestCode = source };
238-
test.ExpectedDiagnostics.AddRange(expected);
239-
return test.RunAsync();
240-
}
241-
242-
public static Task VerifyCodeFixAsync(string source, string fixedSource)
243-
=> VerifyCodeFixAsync(source, DiagnosticResult.EmptyDiagnosticResults, fixedSource);
244-
245-
public static Task VerifyCodeFixAsync(string source, DiagnosticResult expected, string fixedSource)
246-
=> VerifyCodeFixAsync(source, new[] { expected }, fixedSource);
247-
248-
public static Task VerifyCodeFixAsync(string source, DiagnosticResult[] expected, string fixedSource)
249-
{
250-
var test = new Test
251-
{
252-
TestCode = source,
253-
FixedCode = fixedSource,
254-
};
255-
256-
test.ExpectedDiagnostics.AddRange(expected);
257-
return test.RunAsync();
258-
}
259-
260-
public class Test : CSharpCodeFixTest<TAnalyzer, TCodeFix, DefaultVerifier>
261-
where TAnalyzer : DiagnosticAnalyzer, new()
262-
where TCodeFix : CodeFixProvider, new()
263-
{
264-
public CSharpCodeFixTest()
265-
{
266-
// Custom initialization logic here
267-
}
268-
269-
// Custom analyzers and/or code fix properties here
270-
}
271-
}
272-
273-
```
274-
201+
To create a custom verifier, add your test setup or configuration to the corresponding `Test` class provided by the
202+
[analyzer template](../VisualStudio.Roslyn.SDK/Roslyn.SDK/ProjectTemplates/CSharp/Diagnostic/Test/Verifiers). See
203+
https://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/tutorials/how-to-write-csharp-analyzer-code-fix for
204+
instructions on using the analyzer template.

0 commit comments

Comments
 (0)