-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration test to flag MEF composition breaks
- Loading branch information
1 parent
7cb07dd
commit 0dbf59c
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
src/VisualStudio/IntegrationTest/New.IntegrationTests/MefCompositionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// 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; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Castle.Core.Internal; | ||
using Microsoft.VisualStudio.Shell.Interop; | ||
using Roslyn.Test.Utilities; | ||
using Roslyn.VisualStudio.IntegrationTests; | ||
using Xunit; | ||
|
||
namespace Roslyn.VisualStudio.NewIntegrationTests | ||
{ | ||
public class MefCompositionTests : AbstractIntegrationTest | ||
{ | ||
[IdeFact] | ||
public async Task AssertNoCompositionFailures() | ||
{ | ||
// Read the .err file that contains errors; this isn't a great way to do it but we have no | ||
// better option at this point. | ||
var shell = await TestServices.Shell.GetRequiredGlobalServiceAsync<SVsSettingsManager, IVsSettingsManager>(HangMitigatingCancellationToken); | ||
Marshal.ThrowExceptionForHR(shell.GetApplicationDataFolder((uint)__VsApplicationDataFolder.ApplicationDataFolder_LocalSettings, out var applicationDataFolder)); | ||
|
||
var compositionErrorFileLines = File.ReadAllLines(Path.Combine(applicationDataFolder, @"ComponentModelCache\Microsoft.VisualStudio.Default.err")); | ||
var compositionErrors = new List<string>(); | ||
|
||
for (var i = 0; i < compositionErrorFileLines.Length; i++) | ||
{ | ||
var line = compositionErrorFileLines[i]; | ||
|
||
if (line.EndsWith("expected exactly 1 export matching constraints:") && | ||
StartsWithApplicableSymbol(line)) | ||
{ | ||
var entireError = string.Join(Environment.NewLine, compositionErrorFileLines.Skip(i).TakeWhile(s => !string.IsNullOrWhiteSpace(s))); | ||
compositionErrors.Add(entireError); | ||
} | ||
} | ||
|
||
// Ideally I'd write Assert.Empty(compositionErrors), but since the string gets truncated we'll do this instead | ||
AssertEx.Equal("", string.Join(Environment.NewLine, compositionErrors)); | ||
} | ||
|
||
private static bool StartsWithApplicableSymbol(string s) | ||
{ | ||
// ExternalAccess missing exports may mean the langauge isn't installed, or you aren't running | ||
// on fully matched bits; rather than flag them let's keep the noise down. | ||
if (s.StartsWith("Microsoft.CodeAnalysis.ExternalAccess")) | ||
return false; | ||
|
||
// Not actually our code | ||
if (s.StartsWith("Microsoft.CodeAnalysis.Editor.TypeScript")) | ||
return false; | ||
|
||
return s.StartsWith("Microsoft.CodeAnalysis") || | ||
s.StartsWith("Microsoft.VisualStudio.LanguageServices") || | ||
s.StartsWith("Roslyn"); | ||
} | ||
} | ||
} |