logic: update Visual Studio plugin to support Visual Studio 2017
* changed description text of Visual Studio plugin * changed plugin install targets to include VS 2017 * add license file with MIT license * updated vsix for deployment * implement wrapper for all used classes of VCProjectEngine.dll since you cannot just use the oldest version of this assembly (see https://stackoverflow.com/questions/44288050/typecast-fails-when-visual-studio-extension-uses-reference-to-older-assembly). * improved serialization and deserialization of compile commands and compilation databases. * updated used JSON package * rename CommandObject to CompileCommand * changed implementation to keep non-existent file paths in cdb * made methods of SolutionParser non-static * replace spaces with tabs * added IntegrationTests project * configured tests to simulate a new instance of VisualStudio * added cinder as test project for integration tests * remove all absolute paths from expected output of integration tests fortune cookie message = A stranger will bring great meaning to your life.
This commit is contained in:
+130
@@ -0,0 +1,130 @@
|
||||
using System;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Microsoft.VSSDK.Tools.VsIdeTesting;
|
||||
using Microsoft.VisualStudio.Shell.Interop;
|
||||
using EnvDTE;
|
||||
using CoatiSoftware.SourcetrailPlugin.SolutionParser;
|
||||
using System.IO;
|
||||
using CoatiSoftware.SourcetrailPlugin.IntegrationTests.Helpers;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace CoatiSoftware.SourcetrailPlugin.IntegrationTests
|
||||
{
|
||||
[TestClass]
|
||||
public class CreateCdbTests
|
||||
{
|
||||
private bool _updateExpectedOutput = false;
|
||||
|
||||
[TestMethod]
|
||||
[HostType("VS IDE")]
|
||||
public void TestSourcetrailPluginPackageGetsLoaded()
|
||||
{
|
||||
UIThreadInvoker.Invoke(new Action(() =>
|
||||
{
|
||||
// Load the package into the shell.
|
||||
Assert.IsNotNull(VsIdeTestHostContext.ServiceProvider);
|
||||
IVsShell shellService = (IVsShell)VsIdeTestHostContext.ServiceProvider.GetService(typeof(SVsShell));
|
||||
Guid packageGuid = new Guid(GuidList.guidSourcetrailPluginPkgString);
|
||||
|
||||
IVsPackage package;
|
||||
shellService.IsPackageLoaded(ref packageGuid, out package);
|
||||
if (package == null)
|
||||
{
|
||||
shellService.LoadPackage(ref packageGuid, out package);
|
||||
}
|
||||
|
||||
Assert.IsTrue(package is SourcetrailPluginPackage);
|
||||
}));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[HostType("VS IDE")]
|
||||
public void TestCompilationDatabaseCreationForCinderSolution()
|
||||
{
|
||||
UIThreadInvoker.Initialize();
|
||||
UIThreadInvoker.Invoke(new Action(() =>
|
||||
{
|
||||
TestCompilationDatabaseForSolution("../../../SourcetrailPlugin.IntegrationTests/bin/data/cinder/cinder.sln");
|
||||
}));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[HostType("VS IDE")]
|
||||
public void TestCompilationDatabaseCreationForAllFilesInSameFolder()
|
||||
{
|
||||
UIThreadInvoker.Initialize();
|
||||
UIThreadInvoker.Invoke(new Action(() =>
|
||||
{
|
||||
TestCompilationDatabaseForSolution("../../../SourcetrailPlugin.IntegrationTests/bin/data/all_in_same_folder/test.sln");
|
||||
}));
|
||||
}
|
||||
|
||||
private void TestCompilationDatabaseForSolution(string solutionPath)
|
||||
{
|
||||
Console.WriteLine("opening solution: " + solutionPath);
|
||||
Helpers.TestUtility.OpenSolution(solutionPath);
|
||||
|
||||
Console.WriteLine("creating compilation database");
|
||||
|
||||
CompilationDatabase output = null;
|
||||
try
|
||||
{
|
||||
output = CreateCompilationDatabaseForCurrentSolution();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Exception: " + e.Message);
|
||||
Console.WriteLine("Stack Trace: " + e.StackTrace);
|
||||
Assert.Fail("Caught and exception while creating compilation database.");
|
||||
}
|
||||
|
||||
Assert.IsNotNull(output);
|
||||
|
||||
string cdbPath = Path.ChangeExtension(solutionPath, "json");
|
||||
if (_updateExpectedOutput)
|
||||
{
|
||||
Console.WriteLine("writing compilation database to file: " + cdbPath);
|
||||
File.WriteAllText(cdbPath, output.SerializeToJson());
|
||||
Assert.IsTrue(File.Exists(cdbPath));
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("reading compilation database from file: " + cdbPath);
|
||||
CompilationDatabase expectedOutput = CompilationDatabase.LoadFromFile(cdbPath);
|
||||
Assert.IsNotNull(expectedOutput);
|
||||
|
||||
Console.WriteLine("comparing generated compilation database to expected output");
|
||||
Assert.IsTrue(output == expectedOutput, "The created compilation database differs from the expected output");
|
||||
}
|
||||
|
||||
Console.WriteLine("closing solution");
|
||||
Helpers.TestUtility.CloseCurrentSolution();
|
||||
}
|
||||
|
||||
private static CompilationDatabase CreateCompilationDatabaseForCurrentSolution()
|
||||
{
|
||||
DTE dte = (DTE)VsIdeTestHostContext.ServiceProvider.GetService(typeof(DTE));
|
||||
Assert.IsNotNull(dte);
|
||||
|
||||
CompilationDatabase cdb = new CompilationDatabase();
|
||||
foreach (Project project in dte.Solution.Projects)
|
||||
{
|
||||
List<string> configurationNames = Utility.SolutionUtility.GetConfigurationNames(dte);
|
||||
Assert.IsTrue(configurationNames.Count > 0, "No target configurations found in loaded solution.");
|
||||
|
||||
List<string> platformNames = Utility.SolutionUtility.GetPlatformNames(dte);
|
||||
Assert.IsTrue(platformNames.Count > 0, "No target platforms found in loaded solution.");
|
||||
|
||||
SolutionParser.SolutionParser solutionParser = new SolutionParser.SolutionParser(new TestPathResolver());
|
||||
foreach (SolutionParser.CompileCommand command in solutionParser.CreateCompileCommands(
|
||||
project, configurationNames[0], platformNames[0], "c11"
|
||||
))
|
||||
{
|
||||
cdb.AddCommandObject(command);
|
||||
}
|
||||
}
|
||||
|
||||
return cdb;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user