提交 e86980ee 编写于 作者: G Gen Lu

Increase coverage to operators, constructors and destructors

上级 52c53962
......@@ -516,7 +516,7 @@ public static SyntaxTree ParseWithRoundTripCheck(string text, CSharpParseOptions
options = options.WithConcurrentBuild(false);
}
#if TEST_OPERATION
#if Test_IOperation_Interface
// Create a compilation for the purpose of verifying operation tree only,
// so this won't interfere with test.
var compilationForOperationWalking = CSharpCompilation.Create(
......@@ -541,26 +541,27 @@ public static SyntaxTree ParseWithRoundTripCheck(string text, CSharpParseOptions
CSharpParseOptions parseOptions = null)
{
var trees = (sources == null) ? null : sources.Select(s => Parse(s, options: parseOptions)).ToArray();
var compilationOptions = options ?? TestOptions.ReleaseDll;
#if TEST_OPERATION
#if Test_IOperation_Interface
// Create a compilation for the purpose of verifying operation tree only,
// so this won't interfere with test.
var compilationForOperationWalking = CSharpCompilation.Create(
identity.Name,
options: options ?? TestOptions.ReleaseDll,
options: compilationOptions,
references: references,
syntaxTrees: trees);
WalkOperationTree(compilationForOperationWalking);
#endif
var c = CSharpCompilation.Create(identity.Name, options: options ?? TestOptions.ReleaseDll, references: references, syntaxTrees: trees);
var c = CSharpCompilation.Create(identity.Name, options: compilationOptions, references: references, syntaxTrees: trees);
Assert.NotNull(c.Assembly); // force creation of SourceAssemblySymbol
((SourceAssemblySymbol)c.Assembly).lazyAssemblyIdentity = identity;
return c;
}
#if TEST_OPERATION
#if Test_IOperation_Interface
private static void WalkOperationTree(CSharpCompilation compilation)
{
var operationWalker = TestOperationWalker.GetInstance();
......@@ -571,7 +572,7 @@ private static void WalkOperationTree(CSharpCompilation compilation)
var root = tree.GetRoot();
// TODO: check other operation root as well (property, etc.)
foreach (MethodDeclarationSyntax methodNode in root.DescendantNodesAndSelf().Where(n => n.Kind() == SyntaxKind.MethodDeclaration))
foreach (BaseMethodDeclarationSyntax methodNode in root.DescendantNodesAndSelf().OfType<BaseMethodDeclarationSyntax>())
{
var bodyNode = methodNode.Body;
if (bodyNode != null)
......
......@@ -20,17 +20,30 @@ Friend Module CompilationUtils
Optional options As VisualBasicCompilationOptions = Nothing,
Optional assemblyName As String = Nothing,
Optional parseOptions As VisualBasicParseOptions = Nothing) As VisualBasicCompilation
#If TEST_OPERATION Then
Dim compilationForOperationWalking = VisualBasicCompilation.Create(If(assemblyName, "TestOperation"), sourceTrees.Select(Function(s) VisualBasicSyntaxTree.ParseText(s, parseOptions)), If(references Is Nothing, {MscorlibRef}, {MscorlibRef}.Concat(references)), options)
Dim syntaxTrees = sourceTrees.Select(Function(s) VisualBasicSyntaxTree.ParseText(s, parseOptions))
Dim metadataReferences = If(references Is Nothing, {MscorlibRef}, {MscorlibRef}.Concat(references))
#If Test_IOperation_Interface Then
Dim compilationForOperationWalking = VisualBasicCompilation.Create(If(assemblyName, "TestOperation"), syntaxTrees, metadataReferences, options)
WalkOperationTrees(compilationForOperationWalking)
#End If
Return VisualBasicCompilation.Create(If(assemblyName, "Test"), sourceTrees.Select(Function(s) VisualBasicSyntaxTree.ParseText(s, parseOptions)), If(references Is Nothing, {MscorlibRef}, {MscorlibRef}.Concat(references)), options)
Return VisualBasicCompilation.Create(If(assemblyName, "Test"), syntaxTrees, metadataReferences, options)
End Function
Public Function CreateCompilationWithMscorlib(sourceTrees As IEnumerable(Of SyntaxTree),
Optional references As IEnumerable(Of MetadataReference) = Nothing,
Optional options As VisualBasicCompilationOptions = Nothing) As VisualBasicCompilation
Return VisualBasicCompilation.Create(GetUniqueName(), sourceTrees, If(references Is Nothing, {MscorlibRef}, {MscorlibRef}.Concat(references)), options)
Dim metadataReferences = If(references Is Nothing, {MscorlibRef}, {MscorlibRef}.Concat(references))
#If Test_IOperation_Interface Then
Dim compilationForOperationWalking = VisualBasicCompilation.Create(GetUniqueName(), sourceTrees, metadataReferences, options)
WalkOperationTrees(compilationForOperationWalking)
#End If
Return VisualBasicCompilation.Create(GetUniqueName(), sourceTrees, metadataReferences, options)
End Function
Public Function CreateCompilationWithMscorlib45(sourceTrees As IEnumerable(Of SyntaxTree),
......@@ -227,7 +240,7 @@ Friend Module CompilationUtils
End If
End If
#If TEST_OPERATION Then
#If Test_IOperation_Interface Then
Dim compilationForOperationWalking = VisualBasicCompilation.Create(If(assemblyName, GetUniqueName()), sourceTrees, references, options)
WalkOperationTrees(compilationForOperationWalking)
#End If
......@@ -263,7 +276,7 @@ Friend Module CompilationUtils
Return c
End Function
#If TEST_OPERATION Then
#If Test_IOperation_Interface Then
Private Sub WalkOperationTrees(compilation As VisualBasicCompilation)
Dim operationWalker = TestOperationWalker.GetInstance()
......@@ -272,10 +285,9 @@ Friend Module CompilationUtils
Dim root = tree.GetRoot()
' need to check other operation root as well (property, etc)
For Each methodNode As MethodBlockSyntax In root.DescendantNodesAndSelf().Where(Function(n)
Dim kind = n.Kind()
Return kind = SyntaxKind.FunctionBlock OrElse kind = SyntaxKind.SubBlock
End Function)
For Each methodNode As MethodBlockBaseSyntax In root.DescendantNodesAndSelf().OfType(Of MethodBlockBaseSyntax)
' Have to iterate through statements because a bug:
' https://github.com/dotnet/roslyn/issues/8919
For Each statement In methodNode.Statements
Dim operation = semanticModel.GetOperation(statement)
operationWalker.Visit(operation)
......
......@@ -22,7 +22,7 @@ public static TestOperationWalker GetInstance()
return s_instance;
}
#if TEST_NONE_OPERATION
#if Test_IOperation_None_Kind
internal override void VisitNoneOperation(IOperation operation)
{
Assert.True(false, "Encountered an IOperation with `Kind == OperationKind.None` while walking the operation tree.");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册