Skip to content

Commit

Permalink
Improve triggering and validation for multi-project scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Jun 21, 2021
1 parent 5ccd285 commit 4431ec1
Show file tree
Hide file tree
Showing 13 changed files with 702 additions and 112 deletions.
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<MicrosoftCodeAnalysis2PrimaryTestVersion>2.6.1</MicrosoftCodeAnalysis2PrimaryTestVersion>
<MicrosoftCodeAnalysis3PrimaryTestVersion>3.9.0</MicrosoftCodeAnalysis3PrimaryTestVersion>
<MicrosoftCodeAnalysisTestingVersion>1.0.1-beta1.20374.2</MicrosoftCodeAnalysisTestingVersion>
<xunitassertVersion>$(xunitVersion)</xunitassertVersion>
<XunitCombinatorialVersion>1.2.7</XunitCombinatorialVersion>
<VsixTestingXunitVersion>0.1.49-beta</VsixTestingXunitVersion>
<!-- Analyzers -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,44 @@ protected static bool CodeActionExpected(SolutionState state)
|| state.AdditionalFilesFactories.Any();
}

protected static bool HasAnyChange(SolutionState oldState, SolutionState newState)
protected static bool HasAnyChange(ProjectState oldState, ProjectState newState, bool recursive)
{
return !oldState.Sources.SequenceEqual(newState.Sources, SourceFileEqualityComparer.Instance)
if (!oldState.Sources.SequenceEqual(newState.Sources, SourceFileEqualityComparer.Instance)
|| !oldState.GeneratedSources.SequenceEqual(newState.GeneratedSources, SourceFileEqualityComparer.Instance)
|| !oldState.AdditionalFiles.SequenceEqual(newState.AdditionalFiles, SourceFileEqualityComparer.Instance)
|| !oldState.AnalyzerConfigFiles.SequenceEqual(newState.AnalyzerConfigFiles, SourceFileEqualityComparer.Instance);
|| !oldState.AnalyzerConfigFiles.SequenceEqual(newState.AnalyzerConfigFiles, SourceFileEqualityComparer.Instance))
{
return true;
}

if (!recursive)
{
return false;
}

if (oldState is SolutionState oldSolutionState)
{
if (!(newState is SolutionState newSolutionState))
{
throw new ArgumentException("Unexpected mismatch of SolutionState with ProjectState.");
}

if (oldSolutionState.AdditionalProjects.Count != newSolutionState.AdditionalProjects.Count)
{
return true;
}

foreach (var oldAdditionalState in oldSolutionState.AdditionalProjects)
{
if (!newSolutionState.AdditionalProjects.TryGetValue(oldAdditionalState.Key, out var newAdditionalState)
|| HasAnyChange(oldAdditionalState.Value, newAdditionalState, recursive: true))
{
return true;
}
}
}

return false;
}

protected static CodeAction? TryGetCodeActionToApply(ImmutableArray<CodeAction> actions, int? codeActionIndex, string? codeActionEquivalenceKey, Action<CodeAction, IVerifier>? codeActionVerifier, IVerifier verifier)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

<ItemGroup>
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.CodeFix.Testing" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.CodeRefactoring.Testing" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.Testing.Verifiers.MSTest" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.Testing.Verifiers.NUnit" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.Testing.Verifiers.XUnit" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ static Microsoft.CodeAnalysis.Testing.AnalyzerVerifier<TAnalyzer, TTest, TVerifi
static Microsoft.CodeAnalysis.Testing.AnalyzerVerifier<TAnalyzer, TTest, TVerifier>.Diagnostic(string diagnosticId) -> Microsoft.CodeAnalysis.Testing.DiagnosticResult
static Microsoft.CodeAnalysis.Testing.AnalyzerVerifier<TAnalyzer, TTest, TVerifier>.VerifyAnalyzerAsync(string source, params Microsoft.CodeAnalysis.Testing.DiagnosticResult[] expected) -> System.Threading.Tasks.Task
static Microsoft.CodeAnalysis.Testing.CodeActionTest<TVerifier>.CodeActionExpected(Microsoft.CodeAnalysis.Testing.SolutionState state) -> bool
static Microsoft.CodeAnalysis.Testing.CodeActionTest<TVerifier>.HasAnyChange(Microsoft.CodeAnalysis.Testing.SolutionState oldState, Microsoft.CodeAnalysis.Testing.SolutionState newState) -> bool
static Microsoft.CodeAnalysis.Testing.CodeActionTest<TVerifier>.HasAnyChange(Microsoft.CodeAnalysis.Testing.ProjectState oldState, Microsoft.CodeAnalysis.Testing.ProjectState newState, bool recursive) -> bool
static Microsoft.CodeAnalysis.Testing.CodeActionTest<TVerifier>.TryGetCodeActionToApply(System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.CodeActions.CodeAction> actions, int? codeActionIndex, string codeActionEquivalenceKey, System.Action<Microsoft.CodeAnalysis.CodeActions.CodeAction, Microsoft.CodeAnalysis.Testing.IVerifier> codeActionVerifier, Microsoft.CodeAnalysis.Testing.IVerifier verifier) -> Microsoft.CodeAnalysis.CodeActions.CodeAction
static Microsoft.CodeAnalysis.Testing.DiagnosticResult.CompilerError(string identifier) -> Microsoft.CodeAnalysis.Testing.DiagnosticResult
static Microsoft.CodeAnalysis.Testing.DiagnosticResult.CompilerWarning(string identifier) -> Microsoft.CodeAnalysis.Testing.DiagnosticResult
Expand Down
Loading

0 comments on commit 4431ec1

Please sign in to comment.