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

Adding Unit tests for IfStatement #18060

Merged
merged 4 commits into from
Mar 30, 2017
Merged

Conversation

jinujoseph
Copy link
Contributor

@jinujoseph jinujoseph commented Mar 22, 2017

Fixes #17601 This adds couple of unit tests for Ifstatements

On the VB side i don't get Ioperation for IfStatment, There seems to be an ioperation for SingleLineIfStatement and MultiLineIfBlock.

Issues discovered
#18300
#18303

Tagging @dotnet/analyzer-ioperation @AlekseyTs for review.

private void M()
/*<bind>*/{
bool condition=false;
if (true)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can probably make the test more targeted by just binding the if statement instead of entire method body.

IInvocationExpression (static void System.Console.WriteLine(System.String value)) (OperationKind.InvocationExpression, Type: System.Void)
IArgument (Matching Parameter: value) (OperationKind.Argument)
ILiteralExpression (OperationKind.LiteralExpression, Type: System.String, Constant: Result1)
IIfStatement (OperationKind.IfStatement)
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems to be the case where if... elseif.. else has been converted into if... else (if... else) due to lowering.

Copy link
Contributor

@AlekseyTs AlekseyTs Mar 22, 2017

Choose a reason for hiding this comment

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

Does IOperation allow to represent this in a different form? #Closed

Partial Public Class IOperationTests
Inherits SemanticModelTestBase

<Fact(), WorkItem(17601, "https://github.com/dotnet/roslyn/issues/17601")>
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also port the C# tests where you have a constant expression for the if condition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes , will do once we figure out the mutiblock issue


VerifyOperationTreeForTest(Of SingleLineIfStatementSyntax)(source, expectedOperationTree)
End Sub

Copy link
Contributor

Choose a reason for hiding this comment

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

Please port the test for ElseIf from C# to VB.

As a general guideline, it is recommended that you try to port all the C# tests to VB or vice versa for equivalent features.


namespace Microsoft.CodeAnalysis.CSharp.UnitTests
{
public partial class IOperationTests : SemanticModelTestBase
Copy link
Contributor

@AlekseyTs AlekseyTs Mar 22, 2017

Choose a reason for hiding this comment

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

IOperationTests [](start = 25, length = 15)

Consider also testing scenarios:

  • with embedded statements that are not blocks;
  • with conditions declaring variables (out or pattern);
  • with embedded statements declaring variables (out or pattern). #Closed

@jinujoseph jinujoseph changed the title [WIP] Adding Unit tests for IfStatement Adding Unit tests for IfStatement Mar 24, 2017
Copy link
Contributor

@mavasani mavasani left a comment

Choose a reason for hiding this comment

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

@jinujoseph I still don't see the unit test with constant if condition ported over. Apart from that, LGTM.

@jinujoseph
Copy link
Contributor Author

thanks manish, i added few constant checks

private void M()
{
bool condition=false;
/*<bind>*/if (true)
Copy link
Contributor

Choose a reason for hiding this comment

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

can you test whether binding all nodes belong to if statement works? like condition, body and etc.

";
string expectedOperationTree = @"
IIfStatement (OperationKind.IfStatement)
Condition: IOperation: (OperationKind.None)
Copy link
Contributor

Choose a reason for hiding this comment

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

not supported C# 7 feature yet I guess?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes , we have a workitem tracking that

@heejaechang
Copy link
Contributor

seems fine to me, but @mavasani is more expert on language than me so, you probably want him to take a look.

@jinujoseph
Copy link
Contributor Author

@AlekseyTs tagging you to relook this.

IExpressionStatement (OperationKind.ExpressionStatement)
IInvocationExpression (static void System.Console.WriteLine(System.String value)) (OperationKind.InvocationExpression, Type: System.Void)
IArgument (Matching Parameter: value) (OperationKind.Argument)
IOperation: (OperationKind.None)
Copy link
Contributor

@AlekseyTs AlekseyTs Mar 29, 2017

Choose a reason for hiding this comment

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

IOperation: (OperationKind.None) [](start = 8, length = 33)

It looks like string interpolations are not supported, please create an issue to track that, unless we already have one. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

filed issue #18300

IArgument (Matching Parameter: s) (OperationKind.Argument)
ILocalReferenceExpression: s (OperationKind.LocalReferenceExpression, Type: System.String)
IArgument (Matching Parameter: result) (OperationKind.Argument)
ILocalReferenceExpression: i (OperationKind.LocalReferenceExpression, Type: System.Int32)
Copy link
Contributor

@AlekseyTs AlekseyTs Mar 29, 2017

Choose a reason for hiding this comment

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

ILocalReferenceExpression: i (OperationKind.LocalReferenceExpression, Type: System.Int32) [](start = 8, length = 89)

Design issue - should we have a special node for this declaration? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

filed issue #18303

private void M()
{
/*<bind>*/if (true)
A();
Copy link
Contributor

@AlekseyTs AlekseyTs Mar 29, 2017

Choose a reason for hiding this comment

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

A(); [](start = 12, length = 4)

Please add a test where embedded statements declare out or pattern variables. #Closed

returnValue = count
End If"
returnValue = count
End If
Copy link
Contributor

@AlekseyTs AlekseyTs Mar 29, 2017

Choose a reason for hiding this comment

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

Is this code intentional? #Closed

Dim n As Integer = 7
If (m > 20) Then'BIND:"If (m > 20) Then"
Console.WriteLine("Result1")
ElseIf (n > 10) Then
Copy link
Contributor

@AlekseyTs AlekseyTs Mar 29, 2017

Choose a reason for hiding this comment

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

ElseIf (n > 10) Then [](start = 8, length = 20)

Consider testing similar scenario for line if. #Closed

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Mar 29, 2017

Done with review pass. #Closed

@jinujoseph
Copy link
Contributor Author

Thanks @AlekseyTs , have addressed the feedback


VerifyOperationTreeForTest(Of SingleLineIfStatementSyntax)(source, expectedOperationTree)
End Sub
<Fact(), WorkItem(17601, "https://github.com/dotnet/roslyn/issues/17601")>
Copy link
Contributor

@AlekseyTs AlekseyTs Mar 29, 2017

Choose a reason for hiding this comment

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

<Fact(), WorkItem(17601, "https://github.com/dotnet/roslyn/issues/17601")> [](start = 8, length = 74)

Please add an empty line between the methods. #Closed

@jinujoseph
Copy link
Contributor Author

retest windows_eta_open_prtest please

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM

@jinujoseph
Copy link
Contributor Author

eta failure due to #18250
retest windows_eta_open_prtest please

@jinujoseph jinujoseph merged commit fa37d1b into dotnet:master Mar 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants