public void DebugTest(CacheTestMessage message) { var debugger = new DebugHandler(_application); debugger.Debug(message); LastDebugSession = message; }
private static string ConvertFromRunner(CacheTestMessage s) { var x = s.Test.Name; var lastdot = x.LastIndexOf('.'); if (lastdot == -1) { return(""); } string ret; if (s.Test.Runner == TestRunner.MSpec) { ret = "mspecMachine.Specifications.It " + x.Substring(0, lastdot) + "." + x.Substring(lastdot + 1, x.Length - lastdot - 1); } else if (s.Test.Runner == TestRunner.SimpleTesting) { ret = "Simple.Testing.ClientFramework.Specification " + x.Substring(0, lastdot) + "::" + x.Substring(lastdot + 1, x.Length - lastdot - 1) + "()"; } else if (x.Contains("(")) { ret = "System.Void " + x.Substring(0, lastdot) + "::" + RemoveParens(x.Substring(lastdot + 1, x.Length - lastdot - 1)) + "()"; } else { ret = "System.Void " + x.Substring(0, lastdot) + "::" + x.Substring(lastdot + 1, x.Length - lastdot - 1) + "()"; } return(ret.Replace("+", "/")); }
public void Exec(vsCommandExecOption ExecuteOption, ref object VariantIn, ref object VariantOut, ref bool Handled) { var pos = new OnDemandRunFromCursorPosition(_applicationObject); Core.DebugLog.Debug.WriteDebug("Looking for test at current position"); var types = pos.FromCurrentPosition(); if (types.Tests.Count() == 1 || types.Members.Count() == 1) { Core.DebugLog.Debug.WriteDebug("Found 1 test"); Core.DebugLog.Debug.WriteDebug("Getting assembly for " + _applicationObject.ActiveDocument.ProjectItem.ContainingProject.FullName); var assembly = _getAssemblyFromProject(_applicationObject.ActiveDocument.ProjectItem.ContainingProject.FullName); if (assembly == null) { return; } var test = types.Tests.Count() > 0 ? types.Tests.ElementAt(0) : types.Members.ElementAt(0); var testMessage = new CacheTestMessage(assembly, new Messages.TestResult(Messages.TestRunner.Any, Messages.TestRunStatus.Passed, test)); Core.DebugLog.Debug.WriteDebug("Peeking at test message"); _peek(testMessage); if (!_manualBuild() || _buildRunner.Build()) { Core.DebugLog.Debug.WriteDebug("Starting debug"); _debug(testMessage); } } }
private bool setBreakpointFromStacktrace(CacheTestMessage test, ref string targetFramework) { // pull test name from full name var vsTestName = test.Test.Name.Replace("+", "."); var testName = vsTestName.Substring(vsTestName.LastIndexOf('.') + 1, vsTestName.Length - (vsTestName.LastIndexOf('.') + 1)); AutoTest.Core.DebugLog.Debug.WriteDebug("Attempting to set breakpoint through call stack for " + testName); foreach (var line in test.Test.StackTrace) { if (!File.Exists(line.File)) { continue; } AutoTest.Core.DebugLog.Debug.WriteDebug(string.Format("Locating file {0}", line.File)); var window = _application.OpenFile(EnvDTE.Constants.vsViewKindCode, line.File); if (breakOnFunctionElement(line.File, window.ProjectItem.FileCodeModel.CodeElements, testName)) { AutoTest.Core.DebugLog.Debug.WriteDebug("Found code file containing test and set breakpoint"); targetFramework = window.Project.Properties.Item("TargetFrameworkMoniker").Value.ToString(); AutoTest.Core.DebugLog.Debug.WriteDebug(string.Format("Target framework is {0}", targetFramework)); return(true); } } return(false); }
public bool isTheSameTestAs(CacheTestMessage original, CacheTestMessage item) { return (original.Assembly.Equals(item.Assembly) && original.Test.Runner.Equals(item.Test.Runner) && original.Test.Name.Equals(item.Test.Name) && original.Test.DisplayName.Equals(item.Test.DisplayName)); }
private bool existsIn(CacheTestMessage[] cacheTestMessages, CacheTestMessage item) { var query = from i in cacheTestMessages where i.Assembly.Equals(item.Assembly) && i.Test.Runner.Equals(item.Test.Runner) && i.Test.Name.Equals(item.Test.Name) select i; return(query.Count() > 0); }
private bool existsIn(IEnumerable <CacheTestMessage> cacheTestMessages, CacheTestMessage item) { var query = from i in cacheTestMessages where i.Assembly.Equals(item.Assembly) && i.Test.Runner.Equals(item.Test.Runner) && i.Test.Name.Equals(item.Test.Name) select i; return(query.Any()); }
private void onTestMessage(CacheTestMessage cacheTestMessage) { var controls = new List <string>(); controls.Add(_control.linkLabelTestDetails.Name); controls.Add(_control.linkLabelDebugTest.Name); //controls.Add(_control.linkLabelSystemMessages.Name); displayAndOrder(controls.ToArray()); }
public static void Debug(DTE2 app, CacheTestMessage test) { if (Connect.CannotDebug(app, test)) { return; } new DebugHandler(app).Debug(test); Connect.LastDebugRun = test; }
private IStackLine getMatchingStackLine(CacheTestMessage testItem) { foreach (var line in testItem.Test.StackTrace) { if (line.Method.Equals(testItem.Test.Name)) { return(line); } } return(null); }
private bool setBreakpointFromMethod(CacheTestMessage test, ref string targetFramework) { AutoTest.Core.DebugLog.Debug.WriteDebug("Attempting to set breakpoint through test method for " + test.Test.Name); var breakpoint = _application.Debugger.Breakpoints.Add(test.Test.Name.Replace("+", ".")); if (breakpoint != null) { return(true); } return(false); }
private void onTestMessage(CacheTestMessage cacheTestMessage, bool isRunning) { var controls = new List <string>(); controls.Add(_testDetails.Name); controls.Add(_debugTest.Name); if (isRunning) { controls.Add(_cancelRun.Name); } displayAndOrder(controls.ToArray()); }
private string getFixture(CacheTestMessage x) { if (x.Test.Runner == TestRunner.MSpec) { return(x.Test.Name); } var end = x.Test.Name.LastIndexOf('.'); if (end == -1) { return(x.Test.Name); } return(x.Test.Name.Substring(0, end)); }
private void goToTestItemReference(CacheTestMessage testItem) { if (testItem.Test.StackTrace.Length > 0) { // TODO: Add this again when type cache is faster if (CanGoToTypes) { goToType(testItem.Assembly, testItem.Test.Name); } else { goToReference(testItem.Test.StackTrace[0].File, testItem.Test.StackTrace[0].LineNumber, 0); } } }
public static bool CannotDebug(EnvDTE80.DTE2 app, CacheTestMessage test) { lock (_dirtyRealtimeDocuments) { clearOutdatedRealtimeChanges(""); var inRealtime = _dirtyRealtimeDocuments.Count != 0; if (inRealtime) { _client.PauseEngine(); System.Threading.Thread.Sleep(1000); app.ExecuteCommand("File.SaveAll"); _client.ResumeEngine(); } } return(false); }
public void Should_serialize_chache_test_message() { var ignored = new TestResult(TestRunner.Any, TestRunStatus.Ignored, "test name ignored"); ignored.Message = "message ignored"; ignored.StackTrace = new StackLineMessage[] { new StackLineMessage("stackmethod ignored", "stack file ignored", 6) }; var message = new CacheTestMessage("assembly", ignored); var output = serializeDeserialize(message); Assert.AreEqual("assembly", output.Assembly); Assert.AreEqual(TestRunStatus.Ignored, output.Test.Status); Assert.AreEqual("test name ignored", output.Test.Name); Assert.AreEqual("message ignored", output.Test.Message); Assert.AreEqual("stackmethod ignored", output.Test.StackTrace[0].Method); Assert.AreEqual("stack file ignored", output.Test.StackTrace[0].File); Assert.AreEqual(6, output.Test.StackTrace[0].LineNumber); }
private IStackLine getMatchingStackLine(CacheTestMessage testItem) { foreach (var line in testItem.Test.StackTrace) { if (line.Method.Equals(testItem.Test.Name)) { return(line); } } var lastWithLine = testItem.Test.StackTrace.LastOrDefault(x => x.LineNumber > 0); if (lastWithLine != null) { return(lastWithLine); } return(null); }
private string getDuration(CacheTestMessage message) { var duration = message.Test.TimeSpent; if (duration.TotalHours >= 1) { return(string.Format("{0} hours {1} minutes {2} seconds {3} milliseconds", duration.Hours, duration.Minutes, duration.Seconds, duration.Milliseconds)); } if (duration.TotalMinutes >= 1) { return(string.Format("{0} minutes {1} seconds {2} milliseconds", duration.Minutes, duration.Seconds, duration.Milliseconds)); } if (duration.TotalSeconds >= 1) { return(string.Format("{0} seconds {1} milliseconds", duration.Seconds, duration.Milliseconds)); } return(string.Format("{0} milliseconds", duration.Milliseconds)); }
private void goToTestItemReference(CacheTestMessage testItem) { if (testItem.Test.StackTrace.Length > 0) { var exactLine = getMatchingStackLine(testItem); if (exactLine != null) { goToReference(exactLine.File, exactLine.LineNumber, 0); return; } if (CanGoToTypes) { if (goToType(testItem.Assembly, testItem.Test.Name)) { return; } } } }
private string getText(CacheTestMessage message) { var stackTrace = new StringBuilder(); foreach (var line in message.Test.StackTrace) { if (File.Exists(line.File)) { stackTrace.AppendLine(string.Format("at {0} in {1}{2}:line {3}{4}", line.Method, LinkParser.TAG_START, line.File, line.LineNumber, LinkParser.TAG_END)); } else { var text = string.Format("at {0} in {1}{2}{3}", line.Method, LinkParser.TAG_START, line.File, LinkParser.TAG_END); if (text.Replace("<<Link>>", "").Replace("<</Link>>", "").Trim() != "at in") { stackTrace.AppendLine(text); } } } return(string.Format( "Assembly: {0}{4}" + "Test: {1}{4}" + "Duration: " + getDuration(message) + "{4}{4}" + "Message:{4}{2}{4}{4}" + "Stack trace{4}{3}", message.Assembly, message.Test.DisplayName, message.Test.Message, stackTrace.ToString(), Environment.NewLine)); }
public void Exec(vsCommandExecOption ExecuteOption, ref object VariantIn, ref object VariantOut, ref bool Handled) { var pos = new OnDemandRunFromCursorPosition(_applicationObject); var types = pos.FromCurrentPosition(); if (types.Tests.Count() == 1 || types.Members.Count() == 1) { var assembly = _getAssemblyFromProject(_applicationObject.ActiveDocument.ProjectItem.ContainingProject.FullName); if (assembly == null) { return; } var test = types.Tests.Count() > 0 ? types.Tests.ElementAt(0) : types.Members.ElementAt(0); var testMessage = new CacheTestMessage(assembly, new Messages.TestResult(Messages.TestRunner.Any, Messages.TestRunStatus.Passed, test)); _peek(testMessage); if (!_manualBuild() || _buildRunner.Build()) { var debugger = new DebugHandler(_applicationObject); _debug(testMessage); } } }
private new void Handle(LiveTestStatusMessage liveStatus) { if (!_isRunning) { return; } _storeSelected(); var ofCount = liveStatus.TotalNumberOfTests > 0 ? string.Format(" of {0}", liveStatus.TotalNumberOfTests) : ""; var testName = liveStatus.CurrentTest; if (testName.Trim().Length > 0) { testName += " in "; } printMessage(new RunMessages(RunMessageType.Normal, string.Format("testing {3}{0} ({1}{2} tests completed)", Path.GetFileNameWithoutExtension(liveStatus.CurrentAssembly), liveStatus.TestsCompleted, ofCount, testName))); if (_showFailing) { foreach (var test in liveStatus.FailedButNowPassingTests) { var testItem = new CacheTestMessage(test.Assembly, test.Test); _removeTest((t) => isTheSameTestAs(testItem, t)); } foreach (var test in liveStatus.FailedTests) { var testItem = new CacheTestMessage(test.Assembly, test.Test); _removeTest((t) => isTheSameTestAs(testItem, t)); addFeedbackItem("Test failed", formatTestResult(testItem), Color.Red, testItem); } } _restoreSelected(isSame); }
private new void Handle(LiveTestStatusMessage liveStatus) { if (!_isRunning) { return; } listViewFeedback.SuspendLayout(); var ofCount = liveStatus.TotalNumberOfTests > 0 ? string.Format(" of {0}", liveStatus.TotalNumberOfTests) : ""; var testName = liveStatus.CurrentTest; if (testName.Trim().Length > 0) { testName += " in "; } printMessage(new RunMessages(RunMessageType.Normal, string.Format("testing {3}{0} ({1}{2} tests completed)", Path.GetFileNameWithoutExtension(liveStatus.CurrentAssembly), liveStatus.TestsCompleted, ofCount, testName))); if (_showFailing) { foreach (var test in liveStatus.FailedButNowPassingTests) { var testItem = new CacheTestMessage(test.Assembly, test.Test); foreach (ListViewItem item in listViewFeedback.Items) { if (item.Tag.GetType() != typeof(CacheTestMessage)) { continue; } var itm = (CacheTestMessage)item.Tag; if (isTheSameTestAs(itm, testItem)) { item.Remove(); break; } } } object selected = null; if (listViewFeedback.SelectedItems.Count == 1) { selected = listViewFeedback.SelectedItems[0].Tag; } foreach (var test in liveStatus.FailedTests) { var testItem = new CacheTestMessage(test.Assembly, test.Test); ListViewItem toRemove = null; foreach (ListViewItem item in listViewFeedback.Items) { if (item.Tag.GetType() != typeof(CacheTestMessage)) { continue; } var itm = (CacheTestMessage)item.Tag; if (isTheSameTestAs(itm, testItem)) { toRemove = item; break; } } int index = toRemove == null ? 0 : toRemove.Index; if (toRemove != null) { toRemove.Remove(); } addFeedbackItem("Test failed", formatTestResult(testItem), Color.Red, testItem, selected, index); } } listViewFeedback.ResumeLayout(); }
public DetailBuilder(CacheTestMessage message) { Text = getText(message); Links = getLinks(); }
public void Debug(CacheTestMessage test) { try { AutoTest.Core.DebugLog.Debug.WriteDebug("Starting debug session"); var found = false; var targetFramework = ""; found = setBreakpointFromMethod(test, ref targetFramework); if (!found) { found = setBreakpointFromStacktrace(test, ref targetFramework); } if (!found) { return; } var process = new AutoTestRunnerDebugProcess(); var assembly = test.Assembly; AutoTest.Core.DebugLog.Debug.WriteDebug("Starting process suspended"); var command = ""; var options = new RunOptions(); var runner = new RunnerOptions(getTestRunner(TestRunnerConverter.ToString(test.Test.Runner), test.Assembly, test.Test.Name)); var asm = new AssemblyOptions(test.Assembly); asm.AddTest(test.Test.Name); runner.AddAssembly(asm); options.AddTestRun(runner); AutoTest.Core.DebugLog.Debug.WriteDebug(string.Format("Starting {0}", command)); var processID = process.StartPaused(options, test.Test.Runner); try { AutoTest.Core.DebugLog.Debug.WriteDebug("Locating debugger for Visual Studio " + _application.Version); var dbg2 = (EnvDTE80.Debugger2)_application.Debugger; var trans = (EnvDTE80.Transport)dbg2.Transports.Item("Default"); EnvDTE80.Engine[] dbgeng; if (_application.Version == "9.0") { dbgeng = new EnvDTE80.Engine[] { trans.Engines.Item("Managed") }; } else { if (process.Framework >= new Version(4, 0)) { dbgeng = new EnvDTE80.Engine[] { trans.Engines.Item(string.Format("Managed (v{0}.{1})", process.Framework.Major, process.Framework.Minor)) } } ; else { dbgeng = new EnvDTE80.Engine[] { trans.Engines.Item("Managed (v2.0, v1.1, v1.0)") } }; } EnvDTE80.Process2 proc2 = null; foreach (EnvDTE80.Process2 proc in dbg2.GetProcesses(trans, null)) { if (proc.ProcessID == processID) { proc2 = proc; break; } } if (proc2 != null) { proc2.Attach2(dbgeng); } } catch (Exception ex) { AutoTest.Core.DebugLog.Debug.WriteException(ex); throw; } finally { AutoTest.Core.DebugLog.Debug.WriteDebug("Resuming process"); process.Resume(); } } catch (Exception ex) { AutoTest.Core.DebugLog.Debug.WriteException(ex); } }
public void OnInternalMessage(object message) { if (message.Is <RunStartedMessage>()) { clearRunnerTypeAnyItems(); } if (message.Is <BuildRunMessage>()) { if (((BuildRunMessage)message).Results.Errors.Length == 0) { var project = ((BuildRunMessage)message).Results.Project; // Make sure no errors remain in log lock (_buildMessages) { var toRemove = new List <KeyValuePair <long, CacheBuildMessage> >(); foreach (var item in _buildMessages) { if (project == null || item.Value.Project.Equals(project)) { toRemove.Add(item); } } var ids = new List <long>(); foreach (var item in toRemove) { ids.Add(item.Key); _buildMessages.Remove(item); } _dispatch("remove-builditems", new { ids = ids.ToArray() }); } } } if (message.Is <CacheMessages>()) { var cache = (CacheMessages)message; removeItems(cache); foreach (var error in cache.ErrorsToAdd) { addItem("Build error", formatBuildResult(error), Color.Red, error); } foreach (var failed in cache.FailedToAdd) { addItem("Test failed", formatTestResult(failed), Color.Red, failed); } foreach (var warning in cache.WarningsToAdd) { addItem("Build warning", formatBuildResult(warning), Color.Black, warning); } foreach (var ignored in cache.IgnoredToAdd) { addItem("Test ignored", formatTestResult(ignored), Color.Black, ignored); } } if (message.Is <LiveTestStatusMessage>()) { var liveStatus = (LiveTestStatusMessage)message; foreach (var test in liveStatus.FailedButNowPassingTests) { var testItem = new CacheTestMessage(test.Assembly, test.Test); removeTestItem((t) => isTheSameTestAs(testItem, t)); } foreach (var test in liveStatus.FailedTests) { var testItem = new CacheTestMessage(test.Assembly, test.Test); removeTestItem((t) => isTheSameTestAs(testItem, t)); addItem("Test failed", formatTestResult(testItem), Color.Red, testItem); } } }
public DebugTestArgs(CacheTestMessage test) { Test = test; }
public void SetLastDebugSession(CacheTestMessage msg) { LastDebugSession = msg; }
private string formatTestResult(CacheTestMessage item) { return(string.Format("{0} -> ({1}) {2}", item.Test.Status, item.Test.Runner.ToString(), item.Test.DisplayName)); }