Skip to content

Commit

Permalink
Add a skipped unit tests for dotnet#7446
Browse files Browse the repository at this point in the history
  • Loading branch information
mavasani committed Dec 14, 2015
1 parent 7e0c315 commit a5bcd22
Showing 1 changed file with 139 additions and 1 deletion.
140 changes: 139 additions & 1 deletion src/Compilers/CSharp/Test/Semantic/Diagnostics/GetDiagnosticsTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// 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 System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Test.Utilities;
using Xunit;
using Roslyn.Test.Utilities;
using Xunit;

namespace Microsoft.CodeAnalysis.CSharp.UnitTests
{
Expand Down Expand Up @@ -124,5 +126,141 @@ public void Foo()
Assert.Equal(DiagnosticSeverity.Warning, info.DefaultSeverity);
Assert.Equal(4, info.WarningLevel);
}

[Fact(Skip ="7446"), WorkItem(7446, "https://github.com/dotnet/roslyn/issues/7446")]
public void TestCompilationEventQueueWithSemanticModelGetDiagnostics()
{
var source1 = @"
namespace N1
{
partial class Class
{
private void NonPartialMethod1() { }
}
}
";
var source2 = @"
namespace N1
{
partial class Class
{
private void NonPartialMethod2() { }
}
}
";

var tree1 = CSharpSyntaxTree.ParseText(source1, path: "file1");
var tree2 = CSharpSyntaxTree.ParseText(source2, path: "file2");
var eventQueue = new AsyncQueue<CompilationEvent>();
var compilation = CreateCompilationWithMscorlib45(new[] { tree1, tree2 }).WithEventQueue(eventQueue);

// Invoke SemanticModel.GetDiagnostics to force populate the event queue for symbols in the first source file.
var tree = compilation.SyntaxTrees.Single(t => t == tree1);
var root = tree.GetRoot();
var model = compilation.GetSemanticModel(tree);
model.GetDiagnostics(root.FullSpan);

Assert.True(eventQueue.Count > 0);
bool compilationStartedFired;
HashSet<string> declaredSymbolNames, completedCompilationUnits;
Assert.True(DequeueCompilationEvents(eventQueue, out compilationStartedFired, out declaredSymbolNames, out completedCompilationUnits));

// Verify symbol declared events fired for all symbols declared in the first source file.
Assert.True(compilationStartedFired);
Assert.True(declaredSymbolNames.Contains(compilation.GlobalNamespace.Name));
Assert.True(declaredSymbolNames.Contains("N1"));
Assert.True(declaredSymbolNames.Contains("Class"));
Assert.True(declaredSymbolNames.Contains("NonPartialMethod1"));
Assert.True(completedCompilationUnits.Contains(tree.FilePath));
}

[Fact(Skip = "7446"), WorkItem(7446, "https://github.com/dotnet/roslyn/issues/7446")]
public void TestCompilationEventsForPartialMethod()
{
var source1 = @"
namespace N1
{
partial class Class
{
private void NonPartialMethod1() { }
partial void PartialMethod();
}
}
";
var source2 = @"
namespace N1
{
partial class Class
{
private void NonPartialMethod2() { }
partial void PartialMethod() { }
}
}
";

var tree1 = CSharpSyntaxTree.ParseText(source1, path: "file1");
var tree2 = CSharpSyntaxTree.ParseText(source2, path: "file2");
var eventQueue = new AsyncQueue<CompilationEvent>();
var compilation = CreateCompilationWithMscorlib45(new[] { tree1, tree2 }).WithEventQueue(eventQueue);

// Invoke SemanticModel.GetDiagnostics to force populate the event queue for symbols in the first source file.
var tree = compilation.SyntaxTrees.Single(t => t == tree1);
var root = tree.GetRoot();
var model = compilation.GetSemanticModel(tree);
model.GetDiagnostics(root.FullSpan);

Assert.True(eventQueue.Count > 0);
bool compilationStartedFired;
HashSet<string> declaredSymbolNames, completedCompilationUnits;
Assert.True(DequeueCompilationEvents(eventQueue, out compilationStartedFired, out declaredSymbolNames, out completedCompilationUnits));

// Verify symbol declared events fired for all symbols declared in the first source file.
Assert.True(compilationStartedFired);
Assert.True(declaredSymbolNames.Contains(compilation.GlobalNamespace.Name));
Assert.True(declaredSymbolNames.Contains("N1"));
Assert.True(declaredSymbolNames.Contains("Class"));
Assert.True(declaredSymbolNames.Contains("NonPartialMethod1"));
Assert.True(declaredSymbolNames.Contains("PartialMethod"));
Assert.True(completedCompilationUnits.Contains(tree.FilePath));
}

private static bool DequeueCompilationEvents(AsyncQueue<CompilationEvent> eventQueue, out bool compilationStartedFired, out HashSet<string> declaredSymbolNames, out HashSet<string> completedCompilationUnits)
{
compilationStartedFired = false;
declaredSymbolNames = new HashSet<string>();
completedCompilationUnits = new HashSet<string>();
if (eventQueue.Count == 0)
{
return false;
}

CompilationEvent compEvent;
while (eventQueue.TryDequeue(out compEvent))
{
if (compEvent is CompilationStartedEvent)
{
Assert.False(compilationStartedFired, "Unexpected multiple compilation stated events");
compilationStartedFired = true;
}
else
{
var symbolDeclaredEvent = compEvent as SymbolDeclaredCompilationEvent;
if (symbolDeclaredEvent != null)
{
Assert.True(declaredSymbolNames.Add(symbolDeclaredEvent.Symbol.Name), "Unexpected multiple symbol declared events for same symbol");
}
else
{
var compilationCompeletedEvent = compEvent as CompilationUnitCompletedEvent;
if (compilationCompeletedEvent != null)
{
Assert.True(completedCompilationUnits.Add(compilationCompeletedEvent.CompilationUnit.FilePath));
}
}
}
}

return true;
}
}
}

0 comments on commit a5bcd22

Please sign in to comment.