Skip to content

Commit

Permalink
Port immediate window tests to the new framework
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Nov 3, 2023
1 parent 25e87ab commit 6eabb74
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 174 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Roslyn.VisualStudio.IntegrationTests;
using WindowsInput.Native;
using Xunit;

namespace Roslyn.VisualStudio.NewIntegrationTests.CSharp
{
public class CSharpImmediate : AbstractEditorTest
{
protected override string LanguageName => LanguageNames.CSharp;

public CSharpImmediate()
: base()
{
}

public override async Task InitializeAsync()
{
await base.InitializeAsync();

await TestServices.SolutionExplorer.CreateSolutionAsync(nameof(CSharpImmediate), HangMitigatingCancellationToken);
await TestServices.SolutionExplorer.AddProjectAsync("TestProj", WellKnownProjectTemplates.ConsoleApplication, LanguageNames.CSharp, HangMitigatingCancellationToken);
}

[IdeFact]
public async Task DumpLocalVariableValue()
{
await TestServices.Editor.SetTextAsync(@"
class Program
{
static void Main(string[] args)
{
int n1Var = 42;
int n2Var = 43;
}
}
", HangMitigatingCancellationToken);

await TestServices.Workspace.WaitForAsyncOperationsAsync(FeatureAttribute.Workspace, HangMitigatingCancellationToken);
await TestServices.Debugger.SetBreakpointAsync("Program.cs", "}", HangMitigatingCancellationToken);
await TestServices.Debugger.GoAsync(waitForBreakMode: true, HangMitigatingCancellationToken);
await TestServices.ImmediateWindow.ShowAsync(HangMitigatingCancellationToken);
await TestServices.ImmediateWindow.ClearAllAsync(HangMitigatingCancellationToken);
await TestServices.Input.SendWithoutActivateAsync("?n", HangMitigatingCancellationToken);
await TestServices.Workspace.WaitForAsyncOperationsAsync(FeatureAttribute.CompletionSet, HangMitigatingCancellationToken);
await TestServices.Input.SendWithoutActivateAsync(["1", VirtualKeyCode.TAB, VirtualKeyCode.RETURN], HangMitigatingCancellationToken);
Assert.Contains("?n1Var\r\n42", await TestServices.ImmediateWindow.GetTextAsync(HangMitigatingCancellationToken));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.VisualStudio.Extensibility.Testing;
using Microsoft.VisualStudio.Shell.Interop;

namespace Roslyn.VisualStudio.NewIntegrationTests.InProcess
{
[TestService]
internal partial class DebuggerInProcess
{
private async Task<EnvDTE100.Debugger5> GetDebuggerAsync(CancellationToken cancellationToken)
{
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

var dte = await GetRequiredGlobalServiceAsync<SDTE, EnvDTE.DTE>(cancellationToken);
return (EnvDTE100.Debugger5)dte.Debugger;
}

public Task SetBreakpointAsync(string fileName, string text, CancellationToken cancellationToken)
=> SetBreakpointAsync(fileName, text, charsOffset: 0, cancellationToken);

public async Task SetBreakpointAsync(string fileName, string text, int charsOffset, CancellationToken cancellationToken)
{
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

await TestServices.Editor.ActivateAsync(cancellationToken);
await TestServices.Editor.SelectTextInCurrentDocumentAsync(text, cancellationToken);

var caretPosition = await TestServices.Editor.GetCaretPositionAsync(cancellationToken);
caretPosition.BufferPosition.GetLineAndCharacter(out var lineNumber, out var characterIndex);
await SetBreakpointAsync(fileName, lineNumber, characterIndex + charsOffset, cancellationToken);
}

public async Task SetBreakpointAsync(string fileName, int lineNumber, int characterIndex, CancellationToken cancellationToken)
{
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

var debugger = await GetDebuggerAsync(cancellationToken);
// Need to increment the line number because editor line numbers starts from 0 but the debugger ones starts from 1.
debugger.Breakpoints.Add(File: fileName, Line: lineNumber + 1, Column: characterIndex);
}

public async Task GoAsync(bool waitForBreakMode, CancellationToken cancellationToken)
{
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

var debugger = await GetDebuggerAsync(cancellationToken);
debugger.Go(waitForBreakMode);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,36 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.VisualStudio.Shell;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Extensibility.Testing;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.TextManager.Interop;
using Roslyn.VisualStudio.IntegrationTests;

namespace Microsoft.VisualStudio.IntegrationTest.Utilities.InProcess
namespace Roslyn.VisualStudio.NewIntegrationTests.InProcess
{
internal class ImmediateWindow_InProc : InProcComponent
[TestService]
internal partial class ImmediateWindowInProcess
{
public static ImmediateWindow_InProc Create() => new ImmediateWindow_InProc();
public async Task ShowAsync(CancellationToken cancellationToken)
{
await TestServices.Shell.ExecuteCommandAsync(WellKnownCommands.Debug.Immediate, cancellationToken);
}

public void ShowImmediateWindow() => ExecuteCommand("Debug.Immediate");
public async Task ClearAllAsync(CancellationToken cancellationToken)
{
await ShowAsync(cancellationToken);
await TestServices.Shell.ExecuteCommandAsync(WellKnownCommands.Edit.ClearAll, cancellationToken);
}

public string GetText()
public async Task<string> GetTextAsync(CancellationToken cancellationToken)
{
var vsUIShell = (IVsUIShell)ServiceProvider.GlobalProvider.GetService(typeof(SVsUIShell));
var shell = await GetRequiredGlobalServiceAsync<SVsUIShell, IVsUIShell>(cancellationToken);
var immediateWindowGuid = VSConstants.StandardToolWindows.Immediate;
IVsWindowFrame immediateWindowFrame;
ErrorHandler.ThrowOnFailure(vsUIShell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fForceCreate, ref immediateWindowGuid, out immediateWindowFrame));
ErrorHandler.ThrowOnFailure(shell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fForceCreate, ref immediateWindowGuid, out immediateWindowFrame));
ErrorHandler.ThrowOnFailure(immediateWindowFrame.Show());
ErrorHandler.ThrowOnFailure(immediateWindowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out var docView));
var vsTextView = (IVsTextView)docView;
Expand All @@ -29,11 +41,5 @@ public string GetText()
ErrorHandler.ThrowOnFailure(vsTextLines.GetLineText(0, 0, lineCount - 1, lastLineLength, out var text));
return text;
}

public void ClearAll()
{
ShowImmediateWindow();
ExecuteCommand("Edit.ClearAll");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ internal partial class StateResetInProcess
private static readonly ImmutableHashSet<Guid> s_windowsToClose = ImmutableHashSet.Create(
FindReferencesWindowInProcess.FindReferencesWindowGuid,
new Guid(EnvDTE.Constants.vsWindowKindObjectBrowser),
new Guid(ToolWindowGuids80.CodedefinitionWindow));
new Guid(ToolWindowGuids80.CodedefinitionWindow),
VSConstants.StandardToolWindows.Immediate);

public async Task ResetGlobalOptionsAsync(CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Roslyn.VisualStudio.IntegrationTests;
using WindowsInput.Native;
using Xunit;

namespace Roslyn.VisualStudio.NewIntegrationTests.VisualBasic
{
public class BasicImmediate : AbstractEditorTest
{
protected override string LanguageName => LanguageNames.VisualBasic;

public BasicImmediate()
: base()
{
}

public override async Task InitializeAsync()
{
await base.InitializeAsync();

await TestServices.SolutionExplorer.CreateSolutionAsync(nameof(BasicImmediate), HangMitigatingCancellationToken);
await TestServices.SolutionExplorer.AddProjectAsync("TestProj", WellKnownProjectTemplates.ConsoleApplication, LanguageNames.VisualBasic, HangMitigatingCancellationToken);
}

[IdeFact]
public async Task DumpLocalVariableValue()
{
await TestServices.Editor.SetTextAsync(@"
Module Module1
Sub Main()
Dim n1Var As Integer = 42
Dim n2Var As Integer = 43
End Sub
End Module
", HangMitigatingCancellationToken);

await TestServices.Workspace.WaitForAsyncOperationsAsync(FeatureAttribute.Workspace, HangMitigatingCancellationToken);
await TestServices.Debugger.SetBreakpointAsync("Module1.vb", "End Sub", HangMitigatingCancellationToken);
await TestServices.Debugger.GoAsync(waitForBreakMode: true, HangMitigatingCancellationToken);
await TestServices.ImmediateWindow.ShowAsync(HangMitigatingCancellationToken);
await TestServices.ImmediateWindow.ClearAllAsync(HangMitigatingCancellationToken);
await TestServices.Input.SendWithoutActivateAsync("?", HangMitigatingCancellationToken);
await TestServices.Workspace.WaitForAsyncOperationsAsync(FeatureAttribute.CompletionSet, HangMitigatingCancellationToken);
await TestServices.Input.SendWithoutActivateAsync(["n1", VirtualKeyCode.TAB, VirtualKeyCode.RETURN], HangMitigatingCancellationToken);
Assert.Contains("?n1Var\r\n42", await TestServices.ImmediateWindow.GetTextAsync(HangMitigatingCancellationToken));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ namespace Roslyn.VisualStudio.IntegrationTests
{
internal static class WellKnownCommands
{
public static class Debug
{
public const VSConstants.VSStd97CmdID Immediate = VSConstants.VSStd97CmdID.ImmediateWindow;
}

public static class Edit
{
public const VSConstants.VSStd97CmdID ClearAll = VSConstants.VSStd97CmdID.ClearPane;

public static readonly CommandID GoToImplementation = new(Guids.RoslynGroupId, ID.RoslynCommands.GoToImplementation);
public static readonly CommandID RemoveAndSort = new(VSConstants.CMDSETID.CSharpGroup_guid, 6419);

Expand Down
Loading

0 comments on commit 6eabb74

Please sign in to comment.