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

Ivanbasov/integration tests #17885

Merged
merged 10 commits into from
Mar 16, 2017
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected AbstractInteractiveWindowTest(VisualStudioInstanceFactory instanceFact
protected void ClearInteractiveWindow()
{
InteractiveWindow.Initialize();
InteractiveWindow.ClearScreen();
InteractiveWindow.ShowWindow();
InteractiveWindow.Reset();
}
Expand All @@ -44,12 +45,37 @@ protected void Reset(bool waitForPrompt = true)
protected void SubmitText(string text, bool waitForPrompt = true)
=> InteractiveWindow.SubmitText(text, waitForPrompt);

protected void SendKeys(params object[] input)
{
VisualStudio.Instance.SendKeys.Send(input);
}

protected void InsertCode(string text)
=> InteractiveWindow.InsertCode(text);

protected void ExecuteCommand(string commandName)
{
VisualStudio.Instance.ExecuteCommand(commandName);
}

protected void VerifyLastReplOutput(string expectedReplOutput)
{
var lastReplOutput = InteractiveWindow.GetLastReplOutput();
Assert.Equal(expectedReplOutput, lastReplOutput);
}

protected void VerifyLastReplInput(string expectedReplInput)
{
var lastReplInput = InteractiveWindow.GetLastReplInput();
Assert.Equal(expectedReplInput, lastReplInput);
}

protected void VerifyCaretPosition(int expectedCaretPosition)
{
var position = InteractiveWindow.GetCaretPosition();
Assert.Equal(expectedCaretPosition, position);
}

protected void VerifyLastReplOutputContains(string expectedReplOutput)
{
var lastReplOutput = InteractiveWindow.GetLastReplOutput();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
using Xunit;

namespace Roslyn.VisualStudio.IntegrationTests.CSharp
{
[Collection(nameof(SharedIntegrationHostFixture))]
public class CSharpInteractiveCommands : AbstractInteractiveWindowTest
{
public CSharpInteractiveCommands(VisualStudioInstanceFactory instanceFactory)
: base(instanceFactory)
{
}

[Fact]
public void VerifyPreviousAndNextHistory()
{
SubmitText("1 + 2");
SubmitText("1.ToString()");
SendKeys(new KeyPress(VirtualKey.Up, ShiftState.Alt));
VerifyLastReplInput("1.ToString()");
SendKeys(VirtualKey.Enter);
WaitForReplOutput("\"1\"");
SendKeys(new KeyPress(VirtualKey.Up, ShiftState.Alt));
VerifyLastReplInput("1.ToString()");
SendKeys(new KeyPress(VirtualKey.Up, ShiftState.Alt));
VerifyLastReplInput("1 + 2");
SendKeys(VirtualKey.Enter);
WaitForReplOutput("3");
SendKeys(new KeyPress(VirtualKey.Down, ShiftState.Alt));
VerifyLastReplInput("1.ToString()");
SendKeys(VirtualKey.Enter);
WaitForReplOutput("\"1\"");
}

[Fact]
public void VerifyMaybeExecuteInput()
{
InsertCode("2 + 3");
SendKeys(VirtualKey.Enter);
WaitForReplOutput("5");
}

[Fact]
public void VerifyNewLineAndIndent()
{
InsertCode("3 + ");
SendKeys(VirtualKey.Enter);
InsertCode("4");
SendKeys(VirtualKey.Enter);
WaitForReplOutput("7");
}

[Fact]
public void VerifyExecuteInput()
{
SubmitText("1 + ");
VerifyLastReplOutputContains("CS1733");
}

[Fact]
public void VerifyForceNewLineAndIndent()
{
InsertCode("1 + 2");
SendKeys(VirtualKey.Enter);
SubmitText("+ 3");
VerifyReplPromptConsistency("<![CDATA[1 + 2 + 3]]>", "6");
}

[Fact]
public void VerifyCancelInput()
{
InsertCode("1 + 4");
SendKeys(new KeyPress(VirtualKey.Enter, ShiftState.Shift));
SendKeys(VirtualKey.Escape);
VerifyLastReplInput(string.Empty);
}

[Fact]
public void VerifyUndoAndRedo()
{
ClearReplText();
InsertCode(" 2 + 4 ");
SendKeys(new KeyPress(VirtualKey.Z, ShiftState.Ctrl));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: AbstractEditorTest provides a function for doing Ctrl(VirtualKey.Z): http://source.roslyn.io/#Roslyn.VisualStudio.IntegrationTests/AbstractEditorTest.cs,144, it would be nice if we could be consistent across the various tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Will update

VerifyReplPromptConsistency("< ![CDATA[]] >", string.Empty);
SendKeys(new KeyPress(VirtualKey.Y, ShiftState.Ctrl));
VerifyLastReplInput(" 2 + 4 ");
SendKeys(VirtualKey.Enter);
WaitForReplOutput("6");
}

[Fact]
public void CutDeletePasteSelectAll()
{
SendKeys("Text");
ExecuteCommand("Edit.LineStart");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: It would be nice if we had these commands centralized somewhere for general use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Will update

ExecuteCommand("Edit.LineEnd");
ExecuteCommand("Edit.LineStartExtend");
ExecuteCommand("Edit.SelectionCancel");
ExecuteCommand("Edit.LineEndExtend");
ExecuteCommand("Edit.SelectAll");
ExecuteCommand("Edit.SelectAll");
ExecuteCommand("Edit.Copy");
ExecuteCommand("Edit.Cut");
ExecuteCommand("Edit.Paste");
ExecuteCommand("Edit.Delete");
ExecuteCommand("Edit.LineUp");
ExecuteCommand("Edit.LineDown");
ExecuteCommand("Edit.Paste");
ExecuteCommand("Edit.Paste");
SendKeys(VirtualKey.Escape);
}

//<!-- Regression test for bug 13731.
// Unfortunately we don't have good unit-test infrastructure to test InteractiveWindow.cs.
// For now, since we don't have coverage of InteractiveWindow.IndentCurrentLine at all,
// I'd rather have a quick integration test scenario rather than no coverage at all.
// At some point when we start investing in Interactive work again, we'll go through some
// of these tests and convert them to unit-tests.
// -->
//<!-- TODO(https://github.com/dotnet/roslyn/issues/4235)
[Fact]
public void VerifyReturnIndentCurrentLine()
{
InteractiveWindow.ClearScreen();
SendKeys(" (");
SendKeys(")");
SendKeys(VirtualKey.Left);
SendKeys(VirtualKey.Enter);
VerifyCaretPosition(12);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<Compile Include="CSharp\CSharpIntelliSense.cs" />
<Compile Include="CSharp\CSharpInteractive.cs" />
<Compile Include="AbstractEditorTest.cs" />
<Compile Include="CSharp\CSharpInteractiveCommands.cs" />
<Compile Include="CSharp\CSharpSignatureHelp.cs" />
<Compile Include="CSharp\CSharpWinForms.cs" />
<Compile Include="CSharp\CSharpAddMissingReference.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Microsoft.VisualStudio.IntegrationTest.Utilities.InProcess
internal abstract class InteractiveWindow_InProc : InProcComponent
{
private const string ResetCommand = "InteractiveConsole.Reset";
private const string CleanScreenCommand = "InteractiveConsole.ClearScreen";
private const string ReplSubmissionText = ". ";
private const string ReplPromptText = "> ";

Expand Down Expand Up @@ -45,6 +46,9 @@ public bool IsInitializing
public string GetReplText()
=> _interactiveWindow.TextView.TextBuffer.CurrentSnapshot.GetText();

public int GetCaretPosition()
=> _interactiveWindow.TextView.Caret.Position.BufferPosition.Position;

/// <summary>
/// Gets the contents of the REPL window without the prompt text.
/// </summary>
Expand Down Expand Up @@ -99,6 +103,30 @@ public string GetLastReplOutput()
return replText.Substring(firstNewLineIndex, replText.Length - firstNewLineIndex);
}

/// <summary>
/// Gets the last input from the REPL.
/// </summary>
public string GetLastReplInput()
{
// TODO: This may be flaky if the last submission contains ReplPromptText
// TODO: ReplSubmissionText is not yet supported

var replText = GetReplText();
var lastPromptIndex = replText.LastIndexOf(ReplPromptText);

replText = replText.Substring(lastPromptIndex, replText.Length - lastPromptIndex);
replText = replText.Substring(ReplPromptText.Length);

var firstNewLineIndex = replText.IndexOf(Environment.NewLine);

if (firstNewLineIndex <= 0)
{
return replText;
}

return replText.Substring(0, firstNewLineIndex);
}

public void Reset(bool waitForPrompt = true)
{
ExecuteCommand(ResetCommand);
Expand Down Expand Up @@ -157,6 +185,16 @@ private async Task WaitForReplPromptAsync()
public void WaitForReplOutput(string outputText)
=> WaitForReplOutputAsync(outputText).Wait();

public void ClearScreen()
{
ExecuteCommand(CleanScreenCommand);
}

public void InsertCode(string text)
{
_interactiveWindow.InsertCode(text);
}

private async Task WaitForReplOutputAsync(string outputText)
{
while (!GetReplText().EndsWith(outputText + Environment.NewLine + ReplPromptText))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public void Initialize()
public string GetLastReplOutput()
=> _inProc.GetLastReplOutput();

/// <summary>
/// Gets the last input from the REPL.
/// </summary>
public string GetLastReplInput()
=> _inProc.GetLastReplInput();

public int GetCaretPosition()
=> _inProc.GetCaretPosition();

public string GetReplText()
=> _inProc.GetReplText();

Expand All @@ -52,7 +61,13 @@ public void WaitForReplOutput(string outputText)
public void WaitForReplOutputContains(string outputText)
=> _inProc.WaitForReplOutputContains(outputText);

public void CleanUpInteractiveWindow()
public void CloseInteractiveWindow()
=> _inProc.CloseWindow();

public void ClearScreen()
=> _inProc.ClearScreen();

public void InsertCode(string text)
=> _inProc.InsertCode(text);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void CleanUp()
VisualStudioWorkspace.CleanUpWaitingService();
VisualStudioWorkspace.CleanUpWorkspace();
SolutionExplorer.CleanUpOpenSolution();
CSharpInteractiveWindow.CleanUpInteractiveWindow();
CSharpInteractiveWindow.CloseInteractiveWindow();
}

public void Close(bool exitHostProcess = true)
Expand Down