public void CustomCommandsErrorList() { using (var app = new PythonVisualStudioApp()) { PythonProjectNode node; EnvDTE.Project proj; OpenProject(app, "ErrorCommand.sln", out node, out proj); var expectedItems = new[] { new { Document = "Program.py", Line = 0, Column = 1, Category = __VSERRORCATEGORY.EC_ERROR, Message = "This is an error with a relative path." }, new { Document = Path.Combine(node.ProjectHome, "Program.py"), Line = 2, Column = 3, Category = __VSERRORCATEGORY.EC_WARNING, Message = "This is a warning with an absolute path." }, new { Document = ">>>", Line = 4, Column = -1, Category = __VSERRORCATEGORY.EC_ERROR, Message = "This is an error with an invalid path." }, }; Execute(node, "Produce Errors"); var items = app.WaitForErrorListItems(3); Console.WriteLine("Got errors:"); foreach (var item in items) { string document, text; Assert.AreEqual(0, item.Document(out document), "HRESULT getting document"); Assert.AreEqual(0, item.get_Text(out text), "HRESULT getting message"); Console.WriteLine(" {0}: {1}", document ?? "(null)", text ?? "(null)"); } Assert.AreEqual(expectedItems.Length, items.Count); // Second invoke should replace the error items in the list, not add new ones to those already existing. Execute(node, "Produce Errors"); items = app.WaitForErrorListItems(3); Assert.AreEqual(expectedItems.Length, items.Count); items.Sort(Comparer<IVsTaskItem>.Create((x, y) => { int lx, ly; x.Line(out lx); y.Line(out ly); return lx.CompareTo(ly); })); for (int i = 0; i < expectedItems.Length; ++i) { var item = items[i]; var expectedItem = expectedItems[i]; string document, message; item.get_Text(out message); item.Document(out document); int line, column; item.Line(out line); item.Column(out column); uint category; ((IVsErrorItem)item).GetCategory(out category); Assert.AreEqual(expectedItem.Document, document); Assert.AreEqual(expectedItem.Line, line); Assert.AreEqual(expectedItem.Column, column); Assert.AreEqual(expectedItem.Message, message); Assert.AreEqual(expectedItem.Category, (__VSERRORCATEGORY)category); } app.ServiceProvider.GetUIThread().Invoke((Action)delegate { items[0].NavigateTo(); }); var doc = app.Dte.ActiveDocument; Assert.IsNotNull(doc); Assert.AreEqual("Program.py", doc.Name); var textDoc = (EnvDTE.TextDocument)doc.Object("TextDocument"); Assert.AreEqual(1, textDoc.Selection.ActivePoint.Line); Assert.AreEqual(2, textDoc.Selection.ActivePoint.DisplayColumn); } }
public void IndentationInconsistencyIgnore() { using (var app = new PythonVisualStudioApp()) { var options = app.Options; var severity = options.IndentationInconsistencySeverity; options.IndentationInconsistencySeverity = Severity.Ignore; app.OnDispose(() => options.IndentationInconsistencySeverity = severity); var project = app.OpenProject(@"TestData\InconsistentIndentation.sln"); List<IVsTaskItem> items = app.WaitForErrorListItems(0); Assert.AreEqual(0, items.Count); } }
public void ImportPresentThenAddThenRemoveReference() { var python = PythonPaths.Versions.LastOrDefault(p => p.Version.Is3x() && !p.Isx64); python.AssertInstalled(); var vcproj = TestData.GetPath(@"TestData\ProjectReference\NativeModule\NativeModule.vcxproj"); File.WriteAllText(vcproj, File.ReadAllText(vcproj) .Replace("$(PYTHON_INCLUDE)", Path.Combine(python.PrefixPath, "include")) .Replace("$(PYTHON_LIB)", Path.Combine(python.PrefixPath, "libs")) ); using (var app = new PythonVisualStudioApp()) using (app.SelectDefaultInterpreter(python)) { var project = app.OpenProject(@"TestData\ProjectReference\CProjectReference.sln", projectName: "PythonApplication2", expectedProjects: 2); var wnd = project.ProjectItems.Item("Program.py").Open(); wnd.Activate(); try { app.Dte.Solution.SolutionBuild.Clean(true); string text; var items = app.WaitForErrorListItems(1); Assert.AreEqual(1, items.Count); Assert.AreEqual(0, items[0].get_Text(out text)); Assert.IsTrue(text.Contains("native_module"), text); app.Dte.Solution.SolutionBuild.Build(true); items = app.WaitForErrorListItems(0); Assert.AreEqual(0, items.Count); } finally { wnd.Close(); } } }
public void IndentationInconsistencyError() { using (var app = new PythonVisualStudioApp()) { var options = app.Options; var severity = options.IndentationInconsistencySeverity; options.IndentationInconsistencySeverity = Severity.Error; app.OnDispose(() => options.IndentationInconsistencySeverity = severity); var project = app.OpenProject(@"TestData\InconsistentIndentation.sln"); var items = app.WaitForErrorListItems(1); Assert.AreEqual(1, items.Count); VSTASKPRIORITY[] pri = new VSTASKPRIORITY[1]; ErrorHandler.ThrowOnFailure(items[0].get_Priority(pri)); Assert.AreEqual(VSTASKPRIORITY.TP_HIGH, pri[0]); } }