Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When setting up a multi-project scenarios for a CodeRefactoringTest, the invocation location is only allowed in the initial project. #806

Closed
CyrusNajmabadi opened this issue Apr 29, 2021 · 0 comments
Assignees
Labels
Area-MS.CA.Testing Microsoft.CodeAnalysis.Testing

Comments

@CyrusNajmabadi
Copy link
Member

Example, i tried to setup this config:

            var test = new VerifyCS.Test
            {
                CodeActionIndex = 3,
                TestHost = host,
                TestState =
                {
                    Sources = { text2 },
                    AdditionalProjects =
                    {
                        ["DependencyProject"] =
                        {
                            Sources = { text1 },
                        }
                    },
                    AdditionalProjectReferences = { "DependencyProject" },
                },
                FixedState =
                {
                    Sources = { expected2 },
                    AdditionalProjects =
                    {
                        ["DependencyProject"] =
                        {
                            Sources = { expected1 },
                        }
                    },
                    AdditionalProjectReferences = { "DependencyProject" },
                }
            };
            test.Options.AddRange(PreferImplicitTypeWithInfo());
            await test.RunAsync();

Where the starting location was in text1. This crashed here as the engine was trying to found that location in a tree, but then looked up that tree in the main "TestProject" instance, not teh additional-project instance.

I was able to work around that, but it would be nice to support this.

>    Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringContext.CodeRefactoringContext(Microsoft.CodeAnalysis.Document document, Microsoft.CodeAnalysis.Text.TextSpan span, System.Action<Microsoft.CodeAnalysis.CodeActions.CodeAction, Microsoft.CodeAnalysis.Text.TextSpan?> registerRefactoring, bool isBlocking, System.Threading.CancellationToken cancellationToken) Line 60    C#
     Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringContext.CodeRefactoringContext(Microsoft.CodeAnalysis.Document document, Microsoft.CodeAnalysis.Text.TextSpan span, System.Action<Microsoft.CodeAnalysis.CodeActions.CodeAction> registerRefactoring, System.Threading.CancellationToken cancellationToken) Line 45    C#
     Microsoft.CodeAnalysis.CodeRefactoring.Testing.dll!Microsoft.CodeAnalysis.Testing.CodeRefactoringTest<Microsoft.CodeAnalysis.Testing.Verifiers.XUnitVerifier>.ApplyRefactoringAsync(Microsoft.CodeAnalysis.Testing.DiagnosticResult triggerSpan, System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringProvider> codeRefactoringProviders, int? codeActionIndex, string codeActionEquivalenceKey, System.Action<Microsoft.CodeAnalysis.CodeActions.CodeAction, Microsoft.CodeAnalysis.Testing.IVerifier> codeActionVerifier, Microsoft.CodeAnalysis.Project project, int numberOfIterations, Microsoft.CodeAnalysis.Testing.IVerifier verifier, System.Threading.CancellationToken cancellationToken) Line 218    C#
     Microsoft.CodeAnalysis.CodeRefactoring.Testing.dll!Microsoft.CodeAnalysis.Testing.CodeRefactoringTest<Microsoft.CodeAnalysis.Testing.Verifiers.XUnitVerifier>.VerifyRefactoringAsync(string language, Microsoft.CodeAnalysis.Testing.DiagnosticResult triggerSpan, System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringProvider> codeRefactoringProviders, Microsoft.CodeAnalysis.Testing.SolutionState oldState, Microsoft.CodeAnalysis.Testing.SolutionState newState, int numberOfIterations, System.Func<Microsoft.CodeAnalysis.Testing.DiagnosticResult, System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringProvider>, int?, string, System.Action<Microsoft.CodeAnalysis.CodeActions.CodeAction, Microsoft.CodeAnalysis.Testing.IVerifier>, Microsoft.CodeAnalysis.Project, int, Microsoft.CodeAnalysis.Testing.IVerifier, System.Threading.CancellationToken, System.Threading.Tasks.Task<(Microsoft.CodeAnalysis.Project project, System.Runtime.ExceptionServices.ExceptionDispatchInfo iterationCountFailure)>> getFixedProject, Microsoft.CodeAnalysis.Testing.IVerifier verifier, System.Threading.CancellationToken cancellationToken) Line 157    C#
     Microsoft.CodeAnalysis.CodeRefactoring.Testing.dll!Microsoft.CodeAnalysis.Testing.CodeRefactoringTest<Microsoft.CodeAnalysis.Testing.Verifiers.XUnitVerifier>.VerifyRefactoringAsync(Microsoft.CodeAnalysis.Testing.SolutionState testState, Microsoft.CodeAnalysis.Testing.SolutionState fixedState, Microsoft.CodeAnalysis.Testing.DiagnosticResult triggerSpan, Microsoft.CodeAnalysis.Testing.IVerifier verifier, System.Threading.CancellationToken cancellationToken) Line 139    C#
     Microsoft.CodeAnalysis.CodeRefactoring.Testing.dll!Microsoft.CodeAnalysis.Testing.CodeRefactoringTest<Microsoft.CodeAnalysis.Testing.Verifiers.XUnitVerifier>.RunAsync(System.Threading.CancellationToken cancellationToken) Line 87    C#
                    var context = new CodeRefactoringContext(project.GetDocument(location.SourceTree), location.SourceSpan, actions.Add, cancellationToken);

Here project.GetDocument is returning null as this is the wrong project instance for that source-tree.

@sharwell sharwell added the Area-MS.CA.Testing Microsoft.CodeAnalysis.Testing label Apr 29, 2021
@sharwell sharwell changed the title When setting up a multi-project scenarios for a COdeRefactoringTest, the invocation location is only allowed in the initial project. When setting up a multi-project scenarios for a CodeRefactoringTest, the invocation location is only allowed in the initial project. Apr 29, 2021
sharwell added a commit to sharwell/roslyn-sdk that referenced this issue Jun 21, 2021
sharwell added a commit to sharwell/roslyn-sdk that referenced this issue Jun 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-MS.CA.Testing Microsoft.CodeAnalysis.Testing
Projects
None yet
Development

No branches or pull requests

2 participants