protected void OnUpdateCopy(CommandInfo info) { UnitTest test = GetSelectedTest (); if (test != null) { var last = test.GetLastResult (); Gtk.TreeModel foo; Gtk.TreeIter iter; if (!failuresTreeView.Selection.GetSelected (out foo, out iter)) { info.Enabled = false; return; } int type = (int)failuresStore.GetValue (iter, 5); switch (type) { case ErrorMessage: info.Enabled = !string.IsNullOrEmpty (last.Message); return; case StackTrace: default: info.Enabled = !string.IsNullOrEmpty (last.StackTrace); return; } } info.Enabled = error != null; }
bool IsGoToFailureEnabled(UnitTest test) { if (test.SourceCodeLocation == null || test is UnitTestGroup) { return(false); } UnitTestResult res = test.GetLastResult(); return(res != null && res.IsFailure); }
protected void OnShowTest() { UnitTest test = CurrentNode.DataItem as UnitTest; SourceCodeLocation loc = null; UnitTestResult res = test.GetLastResult(); loc = test.SourceCodeLocation; if (loc != null) { IdeApp.Workbench.OpenDocument(loc.FileName, loc.Line, loc.Column, true); } }
protected void OnCopy() { UnitTest test = GetSelectedTest (); if (test != null) { var last = test.GetLastResult (); if (last == null) return; Gtk.TreeModel foo; Gtk.TreeIter iter; if (!failuresTreeView.Selection.GetSelected (out foo, out iter)) return; int type = (int)failuresStore.GetValue (iter, 5); var clipboard = Clipboard.Get (Gdk.Atom.Intern ("CLIPBOARD", false)); switch (type) { case ErrorMessage: clipboard.Text = last.Message; break; case StackTrace: clipboard.Text = last.StackTrace; break; default: clipboard.Text = last.Message + Environment.NewLine + "Stack trace:" + Environment.NewLine + last.StackTrace; break; } } else { if (error == null) return; var clipboard = Clipboard.Get (Gdk.Atom.Intern ("CLIPBOARD", false)); Gtk.TreeModel foo; Gtk.TreeIter iter; if (!failuresTreeView.Selection.GetSelected (out foo, out iter)) return; int type = (int)failuresStore.GetValue (iter, 5); switch (type) { case ErrorMessage: clipboard.Text = error.Message; break; case StackTrace: clipboard.Text = error.StackTrace; break; default: clipboard.Text = error.Message + Environment.NewLine + "Stack trace:" + Environment.NewLine + error.StackTrace; break; } } }
protected void OnShowTest() { UnitTest test = GetSelectedTest (); if (test == null) return; SourceCodeLocation loc = null; UnitTestResult res = test.GetLastResult (); if (res != null && res.IsFailure) loc = res.GetFailureLocation (); if (loc == null) loc = test.SourceCodeLocation; if (loc != null) IdeApp.Workbench.OpenDocument (loc.FileName, loc.Line, loc.Column); }
protected void OnUpdateCopy(CommandInfo info) { UnitTest test = GetSelectedTest(); if (test != null) { var result = test.GetLastResult(); if (result != null) { info.Enabled = !string.IsNullOrEmpty(result.StackTrace); return; } } info.Enabled = false; }
protected void OnCopy() { UnitTest test = GetSelectedTest(); if (test != null) { var last = test.GetLastResult(); if (last == null) { return; } var clipboard = Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false)); clipboard.Text = last.StackTrace; } }
protected void OnUpdateCopy(CommandInfo info) { UnitTest test = GetSelectedTest(); Console.WriteLine("selected test :" + test); if (test != null) { var result = test.GetLastResult(); Console.WriteLine("last result:" + result); if (result != null) { Console.WriteLine(result.StackTrace); info.Enabled = !string.IsNullOrEmpty(result.StackTrace); return; } } info.Enabled = false; }
protected void OnShowFailure() { UnitTest test = CurrentNode.DataItem as UnitTest; SourceCodeLocation loc = null; UnitTestResult res = test.GetLastResult(); if (res != null && res.IsFailure) { loc = res.GetFailureLocation(); } if (loc == null) { loc = test.SourceCodeLocation; } if (loc != null) { IdeApp.Workbench.OpenDocument(loc.FileName, loc.Line, loc.Column); } }
/* public override void GetNodeAttributes (ITreeNavigator parentNode, object dataObject, ref NodeAttributes attributes) * { * attributes |= NodeAttributes.UseMarkup; * } */ public override void BuildNode(ITreeBuilder treeBuilder, object dataObject, NodeInfo nodeInfo) { UnitTest test = dataObject as UnitTest; nodeInfo.Icon = test.StatusIcon; var title = RemoveMarkup(test.Title); if (test.Status == TestStatus.Running) { nodeInfo.Label = title; return; } else if (test.Status == TestStatus.Loading) { nodeInfo.Label = title + GettextCatalog.GetString(" (Loading)"); return; } else if (test.Status == TestStatus.LoadError) { nodeInfo.Label = title + GettextCatalog.GetString(" (Load failed)"); return; } else { nodeInfo.Label = title; UnitTestResult res = test.GetLastResult(); if (res != null && treeBuilder.Options ["ShowTestCounters"] && (test is UnitTestGroup)) { nodeInfo.Label += string.Format(GettextCatalog.GetString(" ({0} passed, {1} failed, {2} not run)"), res.Passed, res.ErrorsAndFailures, res.TestsNotRun); } if (treeBuilder.Options ["ShowTestTime"]) { nodeInfo.Label += string.Format(" Time: {0}ms", res.Time.TotalMilliseconds); } } }
UnitTestResult RunWithConsoleRunner (ProcessExecutionCommand cmd, UnitTest test, string suiteName, string pathName, string testName, TestContext testContext) { var outFile = Path.GetTempFileName (); LocalConsole cons = new LocalConsole (); try { MonoDevelop.NUnit.External.TcpTestListener tcpListener = null; LocalTestMonitor localMonitor = new LocalTestMonitor (testContext, test, suiteName, testName != null); if (!string.IsNullOrEmpty (cmd.Arguments)) cmd.Arguments += " "; cmd.Arguments += "\"-xml=" + outFile + "\" " + AssemblyPath; bool automaticUpdates = cmd.Command != null && (cmd.Command.Contains ("GuiUnit") || (cmd.Command.Contains ("mdtool.exe") && cmd.Arguments.Contains ("run-md-tests"))); if (!string.IsNullOrEmpty(pathName)) cmd.Arguments += " -run=" + test.TestId; if (automaticUpdates) { tcpListener = new MonoDevelop.NUnit.External.TcpTestListener (localMonitor, suiteName); cmd.Arguments += " -port=" + tcpListener.Port; } // Note that we always dispose the tcp listener as we don't want it listening // forever if the test runner does not try to connect to it using (tcpListener) { using (var p = testContext.ExecutionContext.Execute (cmd, cons)) { testContext.Monitor.CancelRequested += p.Cancel; if (testContext.Monitor.IsCancelRequested) p.Cancel (); p.WaitForCompleted (); testContext.Monitor.CancelRequested -= p.Cancel; } if (new FileInfo (outFile).Length == 0) throw new Exception ("Command failed"); } // mdtool.exe does not necessarily guarantee we get automatic updates. It just guarantees // that if guiunit is being used then it will give us updates. If you have a regular test // assembly compiled against nunit.framework.dll if (automaticUpdates && tcpListener.HasReceivedConnection) { if (testName != null) return localMonitor.SingleTestResult; return test.GetLastResult (); } XDocument doc = XDocument.Load (outFile); if (doc.Root != null) { var root = doc.Root.Elements ("test-suite").FirstOrDefault (); if (root != null) { cons.SetDone (); var ot = cons.Out.ReadToEnd (); var et = cons.Error.ReadToEnd (); testContext.Monitor.WriteGlobalLog (ot); if (!string.IsNullOrEmpty (et)) { testContext.Monitor.WriteGlobalLog ("ERROR:\n"); testContext.Monitor.WriteGlobalLog (et); } bool macunitStyle = doc.Root.Element ("environment") != null && doc.Root.Element ("environment").Attribute ("macunit-version") != null; var result = ReportXmlResult (localMonitor, root, "", macunitStyle); if (testName != null) result = localMonitor.SingleTestResult; return result; } } throw new Exception ("Test results could not be parsed."); } catch (Exception ex) { cons.SetDone (); var ot = cons.Out.ReadToEnd (); var et = cons.Error.ReadToEnd (); testContext.Monitor.WriteGlobalLog (ot); if (!string.IsNullOrEmpty (et)) { testContext.Monitor.WriteGlobalLog ("ERROR:\n"); testContext.Monitor.WriteGlobalLog (et); } testContext.Monitor.ReportRuntimeError ("Test execution failed.\n" + ot + "\n" + et, ex); return UnitTestResult.CreateIgnored ("Test execution failed"); } finally { File.Delete (outFile); cons.Dispose (); } }
/* public override void GetNodeAttributes (ITreeNavigator parentNode, object dataObject, ref NodeAttributes attributes) * { * attributes |= NodeAttributes.UseMarkup; * } */ public override void BuildNode(ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon) { UnitTest test = dataObject as UnitTest; if (test.Status == TestStatus.Running) { icon = CircleImage.Running; label = test.Title; return; } else if (test.Status == TestStatus.Loading) { icon = CircleImage.Loading; label = test.Title + GettextCatalog.GetString(" (Loading)"); return; } else if (test.Status == TestStatus.LoadError) { icon = CircleImage.Failure; label = test.Title + GettextCatalog.GetString(" (Load failed)"); return; } else { label = test.Title; UnitTestResult res = test.GetLastResult(); if (res == null) { icon = CircleImage.None; } else if (res.Inconclusive > 0) { icon = CircleImage.Inconclusive; } else if (res.ErrorsAndFailures > 0 && res.Passed > 0) { icon = CircleImage.SuccessAndFailure; } else if (res.IsFailure) { icon = CircleImage.Failure; } else if (res.IsSuccess) { icon = CircleImage.Success; } else if (res.IsNotRun) { icon = CircleImage.NotRun; } else { icon = CircleImage.None; } if (res != null && treeBuilder.Options ["ShowTestCounters"] && (test is UnitTestGroup)) { label += string.Format(GettextCatalog.GetString(" ({0} passed, {1} failed, {2} not run)"), res.Passed, res.ErrorsAndFailures, res.TestsNotRun); } if (treeBuilder.Options ["ShowTestTime"]) { label += " Time: {0}ms" + (res.Time.TotalMilliseconds); } } }
UnitTestResult RunWithConsoleRunner(ProcessExecutionCommand cmd, UnitTest test, string suiteName, string pathName, string testName, TestContext testContext) { var outFile = Path.GetTempFileName(); LocalConsole cons = new LocalConsole(); try { MonoDevelop.NUnit.External.TcpTestListener tcpListener = null; LocalTestMonitor localMonitor = new LocalTestMonitor(testContext, test, suiteName, testName != null); if (!string.IsNullOrEmpty(cmd.Arguments)) { cmd.Arguments += " "; } cmd.Arguments += "\"-xml=" + outFile + "\" " + AssemblyPath; bool automaticUpdates = cmd.Command.Contains("GuiUnit") || (cmd.Command.Contains("mdtool.exe") && cmd.Arguments.Contains("run-md-tests")); if (!string.IsNullOrEmpty(pathName)) { cmd.Arguments += " -run=" + pathName; } if (automaticUpdates) { tcpListener = new MonoDevelop.NUnit.External.TcpTestListener(localMonitor, suiteName); cmd.Arguments += " -port=" + tcpListener.Port; } // Note that we always dispose the tcp listener as we don't want it listening // forever if the test runner does not try to connect to it using (tcpListener) { var p = testContext.ExecutionContext.Execute(cmd, cons); testContext.Monitor.CancelRequested += p.Cancel; if (testContext.Monitor.IsCancelRequested) { p.Cancel(); } p.WaitForCompleted(); if (new FileInfo(outFile).Length == 0) { throw new Exception("Command failed"); } } // mdtool.exe does not necessarily guarantee we get automatic updates. It just guarantees // that if guiunit is being used then it will give us updates. If you have a regular test // assembly compiled against nunit.framework.dll if (automaticUpdates && tcpListener.HasReceivedConnection) { if (testName != null) { return(localMonitor.SingleTestResult); } return(test.GetLastResult()); } XDocument doc = XDocument.Load(outFile); if (doc.Root != null) { var root = doc.Root.Elements("test-suite").FirstOrDefault(); if (root != null) { cons.SetDone(); var ot = cons.Out.ReadToEnd(); var et = cons.Error.ReadToEnd(); testContext.Monitor.WriteGlobalLog(ot); if (!string.IsNullOrEmpty(et)) { testContext.Monitor.WriteGlobalLog("ERROR:\n"); testContext.Monitor.WriteGlobalLog(et); } bool macunitStyle = doc.Root.Element("environment") != null && doc.Root.Element("environment").Attribute("macunit-version") != null; var result = ReportXmlResult(localMonitor, root, "", macunitStyle); if (testName != null) { result = localMonitor.SingleTestResult; } return(result); } } throw new Exception("Test results could not be parsed."); } catch (Exception ex) { cons.SetDone(); var ot = cons.Out.ReadToEnd(); var et = cons.Error.ReadToEnd(); testContext.Monitor.WriteGlobalLog(ot); if (!string.IsNullOrEmpty(et)) { testContext.Monitor.WriteGlobalLog("ERROR:\n"); testContext.Monitor.WriteGlobalLog(et); } testContext.Monitor.ReportRuntimeError("Test execution failed.\n" + ot + "\n" + et, ex); return(UnitTestResult.CreateIgnored("Test execution failed")); } finally { File.Delete(outFile); } }
bool IsGoToFailureEnabled (UnitTest test) { if (test.SourceCodeLocation == null || test is UnitTestGroup) return false; UnitTestResult res = test.GetLastResult (); return res != null && res.IsFailure; }
UnitTestResult RunWithConsoleRunner(ProcessExecutionCommand cmd, UnitTest test, string suiteName, string pathName, string testName, TestContext testContext) { var outFile = Path.GetTempFileName(); LocalConsole cons = new LocalConsole(); try { LocalTestMonitor localMonitor = new LocalTestMonitor(testContext, test, suiteName, testName != null); if (!string.IsNullOrEmpty(cmd.Arguments)) { cmd.Arguments += " "; } cmd.Arguments += "\"-xml=" + outFile + "\" " + AssemblyPath; bool automaticUpdates = cmd.Command.Contains("GuiUnit") || (cmd.Command.Contains("mdtool.exe") && cmd.Arguments.Contains("run-md-tests")); if (!string.IsNullOrEmpty(testName)) { cmd.Arguments += " -run=" + suiteName + "." + testName; } else if (!string.IsNullOrEmpty(suiteName)) { cmd.Arguments += " -run=" + suiteName; } if (automaticUpdates) { var tcpListener = new MonoDevelop.NUnit.External.TcpTestListener(localMonitor, suiteName); cmd.Arguments += " -port=" + tcpListener.Port; } var p = testContext.ExecutionContext.Execute(cmd, cons); testContext.Monitor.CancelRequested += p.Cancel; if (testContext.Monitor.IsCancelRequested) { p.Cancel(); } p.WaitForCompleted(); if (new FileInfo(outFile).Length == 0) { throw new Exception("Command failed"); } if (automaticUpdates) { if (testName != null) { return(localMonitor.SingleTestResult); } return(test.GetLastResult()); } XDocument doc = XDocument.Load(outFile); if (doc.Root != null) { var root = doc.Root.Elements("test-suite").FirstOrDefault(); if (root != null) { cons.SetDone(); var ot = cons.Out.ReadToEnd(); var et = cons.Error.ReadToEnd(); testContext.Monitor.WriteGlobalLog(ot); if (!string.IsNullOrEmpty(et)) { testContext.Monitor.WriteGlobalLog("ERROR:\n"); testContext.Monitor.WriteGlobalLog(et); } bool macunitStyle = doc.Root.Element("environment") != null && doc.Root.Element("environment").Attribute("macunit-version") != null; var result = ReportXmlResult(localMonitor, root, "", macunitStyle); if (testName != null) { result = localMonitor.SingleTestResult; } return(result); } } throw new Exception("Test results could not be parsed."); } catch (Exception ex) { cons.SetDone(); var ot = cons.Out.ReadToEnd(); var et = cons.Error.ReadToEnd(); testContext.Monitor.WriteGlobalLog(ot); if (!string.IsNullOrEmpty(et)) { testContext.Monitor.WriteGlobalLog("ERROR:\n"); testContext.Monitor.WriteGlobalLog(et); } testContext.Monitor.ReportRuntimeError("Test execution failed.\n" + ot + "\n" + et, ex); return(UnitTestResult.CreateIgnored("Test execution failed")); } finally { File.Delete(outFile); } }
UnitTestResult RunWithConsoleRunner (ProcessExecutionCommand cmd, UnitTest test, string suiteName, string pathName, string testName, TestContext testContext) { var outFile = Path.GetTempFileName (); LocalConsole cons = new LocalConsole (); try { LocalTestMonitor localMonitor = new LocalTestMonitor (testContext, test, suiteName, testName != null); if (!string.IsNullOrEmpty (cmd.Arguments)) cmd.Arguments += " "; cmd.Arguments += "\"-xml=" + outFile + "\" " + AssemblyPath; bool automaticUpdates = cmd.Command.Contains ("GuiUnit") || (cmd.Command.Contains ("mdtool.exe") && cmd.Arguments.Contains ("run-md-tests")); if (!string.IsNullOrEmpty (testName)) cmd.Arguments += " -run=" + suiteName + "." + testName; else if (!string.IsNullOrEmpty (suiteName)) cmd.Arguments += " -run=" + suiteName; if (automaticUpdates) { var tcpListener = new MonoDevelop.NUnit.External.TcpTestListener (localMonitor, suiteName); cmd.Arguments += " -port=" + tcpListener.Port; } var p = testContext.ExecutionContext.Execute (cmd, cons); testContext.Monitor.CancelRequested += p.Cancel; if (testContext.Monitor.IsCancelRequested) p.Cancel (); p.WaitForCompleted (); if (new FileInfo (outFile).Length == 0) throw new Exception ("Command failed"); if (automaticUpdates) { if (testName != null) return localMonitor.SingleTestResult; return test.GetLastResult (); } XDocument doc = XDocument.Load (outFile); if (doc.Root != null) { var root = doc.Root.Elements ("test-suite").FirstOrDefault (); if (root != null) { cons.SetDone (); var ot = cons.Out.ReadToEnd (); var et = cons.Error.ReadToEnd (); testContext.Monitor.WriteGlobalLog (ot); if (!string.IsNullOrEmpty (et)) { testContext.Monitor.WriteGlobalLog ("ERROR:\n"); testContext.Monitor.WriteGlobalLog (et); } bool macunitStyle = doc.Root.Element ("environment") != null && doc.Root.Element ("environment").Attribute ("macunit-version") != null; var result = ReportXmlResult (localMonitor, root, "", macunitStyle); if (testName != null) result = localMonitor.SingleTestResult; return result; } } throw new Exception ("Test results could not be parsed."); } catch (Exception ex) { cons.SetDone (); var ot = cons.Out.ReadToEnd (); var et = cons.Error.ReadToEnd (); testContext.Monitor.WriteGlobalLog (ot); if (!string.IsNullOrEmpty (et)) { testContext.Monitor.WriteGlobalLog ("ERROR:\n"); testContext.Monitor.WriteGlobalLog (et); } testContext.Monitor.ReportRuntimeError ("Test execution failed.\n" + ot + "\n" + et, ex); return UnitTestResult.CreateIgnored ("Test execution failed"); } finally { File.Delete (outFile); } }