Skip to content

Commit

Permalink
Add integration test to flag MEF composition breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmalinowski committed Mar 31, 2022
1 parent 91bd6e5 commit 8faf468
Showing 1 changed file with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 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.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 (int 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);
}
}

Assert.Empty(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");
}
}
}

0 comments on commit 8faf468

Please sign in to comment.