Skip to content

Commit

Permalink
Test layering fixes (#76749)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat authored Jan 15, 2025
1 parent 3b6df3e commit 81afe92
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,10 @@
<IsTestUtilityProject>true</IsTestUtilityProject>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
<ProjectReference Include="..\..\Compilers\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.csproj" />
<ProjectReference Include="..\..\Compilers\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.vbproj" />
<ProjectReference Include="..\..\Features\Core\Portable\Microsoft.CodeAnalysis.Features.csproj" />
<ProjectReference Include="..\..\Features\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.Features.csproj" />
<ProjectReference Include="..\..\Features\DiagnosticsTestUtilities\Microsoft.CodeAnalysis.Features.DiagnosticsTests.Utilities.csproj" />
<ProjectReference Include="..\..\LanguageServer\Protocol\Microsoft.CodeAnalysis.LanguageServer.Protocol.csproj" />
<ProjectReference Include="..\..\Features\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.Features.vbproj" />
<ProjectReference Include="..\..\Compilers\Test\Core\Microsoft.CodeAnalysis.Test.Utilities.csproj" />
<ProjectReference Include="..\..\Workspaces\CoreTestUtilities\Microsoft.CodeAnalysis.Workspaces.Test.Utilities.csproj" />
<ProjectReference Include="..\TestUtilities\Microsoft.CodeAnalysis.EditorFeatures.Test.Utilities.csproj" />
<ProjectReference Include="..\..\Workspaces\Core\Portable\Microsoft.CodeAnalysis.Workspaces.csproj">
<Aliases>global,WORKSPACES</Aliases>
</ProjectReference>
<ProjectReference Include="..\..\Workspaces\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.Workspaces.csproj" />
<ProjectReference Include="..\..\Workspaces\Remote\Core\Microsoft.CodeAnalysis.Remote.Workspaces.csproj" />
<ProjectReference Include="..\..\Workspaces\Remote\ServiceHub\Microsoft.CodeAnalysis.Remote.ServiceHub.csproj" />
<ProjectReference Include="..\..\Workspaces\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.Workspaces.vbproj" />
<ProjectReference Include="..\Core\Microsoft.CodeAnalysis.EditorFeatures.csproj" />
<ProjectReference Include="..\Core.Wpf\Microsoft.CodeAnalysis.EditorFeatures.Wpf.csproj" />
<ProjectReference Include="..\CSharp\Microsoft.CodeAnalysis.CSharp.EditorFeatures.csproj" />
<ProjectReference Include="..\Text\Microsoft.CodeAnalysis.EditorFeatures.Text.csproj" />
<ProjectReference Include="..\Core.Wpf\Microsoft.CodeAnalysis.EditorFeatures.Wpf.csproj" />
<ProjectReference Include="..\VisualBasic\Microsoft.CodeAnalysis.VisualBasic.EditorFeatures.vbproj" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/EditorFeatures/Test2/GoToBase/GoToBaseTestsBase.vb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToBase
testHost:=TestHost.InProcess,
Async Function(document As Document, position As Integer, context As SimpleFindUsagesContext)
Dim gotoBaseService = document.GetLanguageService(Of IGoToBaseService)
Dim options = New TestOptionsProvider(Of ClassificationOptions)(ClassificationOptions.Default)
Dim options = TestOptionsProvider.Create(ClassificationOptions.Default)
Await gotoBaseService.FindBasesAsync(context, document, position, options, CancellationToken.None)
End Function,
shouldSucceed, metadataDefinitions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToImplementation
host,
Async Function(document As Document, position As Integer, context As SimpleFindUsagesContext) As Task
Dim findUsagesService = document.GetLanguageService(Of IFindUsagesService)
Dim options = New TestOptionsProvider(Of ClassificationOptions)(ClassificationOptions.Default)
Dim options = TestOptionsProvider.Create(ClassificationOptions.Default)
Await findUsagesService.FindImplementationsAsync(context, document, position, options, CancellationToken.None).ConfigureAwait(False)
End Function,
shouldSucceed,
Expand Down
23 changes: 23 additions & 0 deletions src/EditorFeatures/TestUtilities/Workspaces/EditorTestWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.UnitTests;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Host;
Expand Down Expand Up @@ -193,6 +195,27 @@ public void OpenSourceGeneratedDocument(DocumentId documentId)
testDocument.GetOpenTextContainer();
}

public TServiceInterface GetService<TServiceInterface>(string contentType)
{
var values = ExportProvider.GetExports<TServiceInterface, ContentTypeMetadata>();
return values.Single(value => value.Metadata.ContentTypes.Contains(contentType)).Value;
}

public TServiceInterface GetService<TServiceInterface>(string contentType, string name)
{
var values = ExportProvider.GetExports<TServiceInterface, OrderableContentTypeMetadata>();
return values.Single(value => value.Metadata.Name == name && value.Metadata.ContentTypes.Contains(contentType)).Value;
}

internal override bool CanAddProjectReference(ProjectId referencingProject, ProjectId referencedProject)
{
// VisualStudioWorkspace asserts the main thread for this call, so do the same thing here to catch tests
// that fail to account for this possibility.
var threadingContext = ExportProvider.GetExportedValue<IThreadingContext>();
Contract.ThrowIfFalse(threadingContext.HasMainThread && threadingContext.JoinableTaskContext.IsOnMainThread);
return true;
}

/// <summary>
/// Creates a TestHostDocument backed by a projection buffer. The surface buffer is
/// described by a markup string with {|name:|} style pointers to annotated spans that can
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Features\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.Features.csproj" />
<ProjectReference Include="..\..\LanguageServer\Protocol.TestUtilities\Microsoft.CodeAnalysis.LanguageServer.Protocol.Test.Utilities.csproj" />
<ProjectReference Include="..\..\Features\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.Features.vbproj" />
<ProjectReference Include="..\..\Features\TestUtilities\Microsoft.CodeAnalysis.Features.Test.Utilities.csproj" />
<ProjectReference Include="..\..\Workspaces\Core\Portable\Microsoft.CodeAnalysis.Workspaces.csproj">
Expand Down
Loading

0 comments on commit 81afe92

Please sign in to comment.