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

Remove unneeded tests methods #73162

Merged
merged 3 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ internal static class SolutionTestHelpers
public static Workspace CreateWorkspace(Type[]? additionalParts = null, TestHost testHost = TestHost.InProcess)
=> new AdhocWorkspace(FeaturesTestCompositions.Features.AddParts(additionalParts).WithTestHostParts(testHost).GetHostServices());

public static Workspace CreateWorkspaceWithNormalText()
=> CreateWorkspace();

public static Workspace CreateWorkspaceWithRecoverableText()
=> CreateWorkspace();

public static Workspace CreateWorkspaceWithPartialSemantics(TestHost testHost = TestHost.InProcess)
=> WorkspaceTestUtilities.CreateWorkspaceWithPartialSemantics(testHost: testHost);

Expand Down
2 changes: 1 addition & 1 deletion src/Workspaces/CoreTest/SolutionTests/SolutionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2651,7 +2651,7 @@ public void TestDocumentChangedOnDiskIsNotObserved()
var file = Temp.CreateFile().WriteAllText(text1, Encoding.UTF8);

// create a solution that evicts from the cache immediately.
using var workspace = CreateWorkspaceWithRecoverableText();
using var workspace = CreateWorkspace();
var sol = workspace.CurrentSolution;

var pid = ProjectId.CreateNewId();
Expand Down
50 changes: 23 additions & 27 deletions src/Workspaces/CoreTest/SyntaxReferenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,26 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Linq;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Test.Utilities;
using Xunit;
using Microsoft.CodeAnalysis.Shared.Extensions;
using CS = Microsoft.CodeAnalysis.CSharp;
using VB = Microsoft.CodeAnalysis.VisualBasic;
using System.Threading.Tasks;
using System.Threading;

namespace Microsoft.CodeAnalysis.UnitTests
{
[UseExportProvider]
[Trait(Traits.Feature, Traits.Features.Workspace)]
public class SyntaxReferenceTests : TestBase
public sealed class SyntaxReferenceTests : TestBase
{
private static Workspace CreateWorkspace(Type[] additionalParts = null)
=> new AdhocWorkspace(FeaturesTestCompositions.Features.AddParts(additionalParts).GetHostServices());

private static Workspace CreateWorkspaceWithRecoverableSyntaxTrees()
=> CreateWorkspace();
private static Workspace CreateWorkspace()
=> new AdhocWorkspace(FeaturesTestCompositions.Features.GetHostServices());

private static Solution AddSingleFileCSharpProject(Solution solution, string source)
{
Expand All @@ -48,16 +44,16 @@ private static Solution AddSingleFileVisualBasicProject(Solution solution, strin
}

[Fact]
public void TestCSharpReferenceToZeroWidthNode()
public async Task TestCSharpReferenceToZeroWidthNode()
{
using var workspace = CreateWorkspaceWithRecoverableSyntaxTrees();
using var workspace = CreateWorkspace();
var solution = AddSingleFileCSharpProject(workspace.CurrentSolution, @"
public class C<>
{
}
");

var tree = solution.Projects.First().Documents.First().GetSyntaxTreeAsync().Result;
var tree = await solution.Projects.First().Documents.First().GetRequiredSyntaxTreeAsync(CancellationToken.None);

// this is an expected TypeParameterSyntax with a missing identifier token (it is zero-length w/ an error attached to it)
var node = tree.GetRoot().DescendantNodes().OfType<CS.Syntax.TypeParameterSyntax>().Single();
Expand All @@ -71,15 +67,15 @@ public class C<>
}

[Fact]
public void TestVisualBasicReferenceToZeroWidthNode()
public async Task TestVisualBasicReferenceToZeroWidthNode()
{
using var workspace = CreateWorkspaceWithRecoverableSyntaxTrees();
using var workspace = CreateWorkspace();
var solution = AddSingleFileVisualBasicProject(workspace.CurrentSolution, @"
Public Class C(Of )
End Class
");

var tree = solution.Projects.First().Documents.First().GetSyntaxTreeAsync().Result;
var tree = await solution.Projects.First().Documents.First().GetRequiredSyntaxTreeAsync(CancellationToken.None);

// this is an expected TypeParameterSyntax with a missing identifier token (it is zero-length w/ an error attached to it)
var node = tree.GetRoot().DescendantNodes().OfType<VB.Syntax.TypeParameterSyntax>().Single();
Expand All @@ -93,17 +89,17 @@ End Class
}

[Fact]
public void TestCSharpReferenceToNodeInStructuredTrivia()
public async Task TestCSharpReferenceToNodeInStructuredTrivia()
{
using var workspace = CreateWorkspaceWithRecoverableSyntaxTrees();
using var workspace = CreateWorkspace();
var solution = AddSingleFileCSharpProject(workspace.CurrentSolution, @"
#if true || true
public class C
{
}
#endif
");
var tree = solution.Projects.First().Documents.First().GetSyntaxTreeAsync().Result;
var tree = await solution.Projects.First().Documents.First().GetRequiredSyntaxTreeAsync(CancellationToken.None);

// find binary node that is part of #if directive
var node = tree.GetRoot().DescendantNodes(descendIntoTrivia: true).OfType<CS.Syntax.BinaryExpressionSyntax>().First();
Expand All @@ -116,17 +112,17 @@ public class C
}

[Fact]
public void TestVisualBasicReferenceToNodeInStructuredTrivia()
public async Task TestVisualBasicReferenceToNodeInStructuredTrivia()
{
using var workspace = CreateWorkspaceWithRecoverableSyntaxTrees();
using var workspace = CreateWorkspace();
var solution = AddSingleFileVisualBasicProject(workspace.CurrentSolution, @"
#If True Or True Then
Public Class C
End Class
#End If
");

var tree = solution.Projects.First().Documents.First().GetSyntaxTreeAsync().Result;
var tree = await solution.Projects.First().Documents.First().GetRequiredSyntaxTreeAsync(CancellationToken.None);

// find binary node that is part of #if directive
var node = tree.GetRoot().DescendantNodes(descendIntoTrivia: true).OfType<VB.Syntax.BinaryExpressionSyntax>().First();
Expand All @@ -139,9 +135,9 @@ End Class
}

[Fact]
public void TestCSharpReferenceToZeroWidthNodeInStructuredTrivia()
public async Task TestCSharpReferenceToZeroWidthNodeInStructuredTrivia()
{
using var workspace = CreateWorkspaceWithRecoverableSyntaxTrees();
using var workspace = CreateWorkspace();
var solution = AddSingleFileCSharpProject(workspace.CurrentSolution, @"
#if true ||
public class C
Expand All @@ -150,7 +146,7 @@ public class C
#endif
");

var tree = solution.Projects.First().Documents.First().GetSyntaxTreeAsync().Result;
var tree = await solution.Projects.First().Documents.First().GetRequiredSyntaxTreeAsync(CancellationToken.None);

// find binary node that is part of #if directive
var binary = tree.GetRoot().DescendantNodes(descendIntoTrivia: true).OfType<CS.Syntax.BinaryExpressionSyntax>().First();
Expand All @@ -169,15 +165,15 @@ public class C
[Fact]
public async System.Threading.Tasks.Task TestVisualBasicReferenceToZeroWidthNodeInStructuredTriviaAsync()
{
using var workspace = CreateWorkspaceWithRecoverableSyntaxTrees();
using var workspace = CreateWorkspace();
var solution = AddSingleFileVisualBasicProject(workspace.CurrentSolution, @"
#If (True Or ) Then
Public Class C
End Class
#End If
");

var tree = await solution.Projects.First().Documents.First().GetSyntaxTreeAsync();
var tree = await solution.Projects.First().Documents.First().GetRequiredSyntaxTreeAsync(CancellationToken.None);

// find binary node that is part of #if directive
var binary = tree.GetRoot().DescendantNodes(descendIntoTrivia: true).OfType<VB.Syntax.BinaryExpressionSyntax>().First();
Expand Down
Loading