Skip to content

Commit

Permalink
Verify expected documents if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt committed Apr 25, 2021
1 parent beea4f3 commit c54f877
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/Tests/Testing.Common/Testing/CodeVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,12 @@ internal static (Document document, ImmutableArray<ExpectedDocument> expectedDoc
for (int i = 0; i < additionalFiles.Length; i++)
{
Document additionalDocument = project.AddDocument(AppendNumberToFileName(options.DocumentName, i + 2), SourceText.From(additionalFiles[i].Source));
expectedDocuments.Add(new ExpectedDocument(additionalDocument.Id, additionalFiles[i].ExpectedSource));

string expectedSource = additionalFiles[i].ExpectedSource;

if (expectedSource != null)
expectedDocuments.Add(new ExpectedDocument(additionalDocument.Id, expectedSource));

project = additionalDocument.Project;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public async Task VerifyNoFixAsync(

using (Workspace workspace = new AdhocWorkspace())
{
(Document document, ImmutableArray<ExpectedDocument> expectedDocuments) = CreateDocument(workspace.CurrentSolution, data.Source, data.AdditionalFiles, options);
(Document document, ImmutableArray<ExpectedDocument> _) = CreateDocument(workspace.CurrentSolution, data.Source, data.AdditionalFiles, options);

Compilation compilation = await document.Project.GetCompilationAsync(cancellationToken);

Expand Down
7 changes: 5 additions & 2 deletions src/Tests/Testing.Common/Testing/DiagnosticVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public async Task VerifyDiagnosticAsync(
{
VerifyDiagnostics(data, analyzer, expectedDiagnostics, diagnostics, cancellationToken);
}

if (expectedDocuments.Any())
await VerifyAdditionalDocumentsAsync(document.Project, expectedDocuments, cancellationToken);
}

static IEnumerable<Diagnostic> FilterDiagnostics(
Expand Down Expand Up @@ -119,7 +122,7 @@ public async Task VerifyNoDiagnosticAsync(

using (Workspace workspace = new AdhocWorkspace())
{
(Document document, ImmutableArray<ExpectedDocument> expectedDocuments) = CreateDocument(workspace.CurrentSolution, data.Source, data.AdditionalFiles, options, data.Descriptor);
(Document document, ImmutableArray<ExpectedDocument> _) = CreateDocument(workspace.CurrentSolution, data.Source, data.AdditionalFiles, options, data.Descriptor);

SyntaxTree tree = await document.GetSyntaxTreeAsync();

Expand Down Expand Up @@ -342,7 +345,7 @@ private async Task VerifyNoFixAsync(

using (Workspace workspace = new AdhocWorkspace())
{
(Document document, ImmutableArray<ExpectedDocument> expectedDocuments) = CreateDocument(workspace.CurrentSolution, data.Source, data.AdditionalFiles, options, data.Descriptor);
(Document document, ImmutableArray<ExpectedDocument> _) = CreateDocument(workspace.CurrentSolution, data.Source, data.AdditionalFiles, options, data.Descriptor);

Compilation compilation = await document.Project.GetCompilationAsync(cancellationToken);

Expand Down
6 changes: 5 additions & 1 deletion src/Tests/Testing.Common/Testing/RefactoringVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
Expand Down Expand Up @@ -99,6 +100,9 @@ public async Task VerifyRefactoringAsync(
VerifyNoNewCompilerDiagnostics(compilerDiagnostics, newCompilerDiagnostics, options);

await VerifyExpectedDocument(expected, document, cancellationToken);

if (expectedDocuments.Any())
await VerifyAdditionalDocumentsAsync(document.Project, expectedDocuments, cancellationToken);
}
}
}
Expand Down Expand Up @@ -128,7 +132,7 @@ public async Task VerifyNoRefactoringAsync(

using (Workspace workspace = new AdhocWorkspace())
{
(Document document, ImmutableArray<ExpectedDocument> expectedDocuments) = CreateDocument(workspace.CurrentSolution, data.Source, data.AdditionalFiles, options);
(Document document, ImmutableArray<ExpectedDocument> _) = CreateDocument(workspace.CurrentSolution, data.Source, data.AdditionalFiles, options);

SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken);

Expand Down

0 comments on commit c54f877

Please sign in to comment.