{"action":"created","issue":{"url":"https://api.github.com/repos/pester/Pester/issues/426","labels_url":"https://api.github.com/repos/pester/Pester/issues/426/labels{/name}","comments_url":"https://api.github.com/repos/pester/Pester/issues/426/comments","events_url":"https://api.github.com/repos/pester/Pester/issues/426/events","html_url":"https://github.com/pester/Pester/pull/426","id":117281679,"number":426,"title":"Improve stack trace and exception console output","user":{"login":"alx9r","id":11237922,"avatar_url":"https://avatars.githubusercontent.com/u/11237922?v=3","gravatar_id":"","url":"https://api.github.com/users/alx9r","html_url":"https://github.com/alx9r","followers_url":"https://api.github.com/users/alx9r/followers","following_url":"https://api.github.com/users/alx9r/following{/other_user}","gists_url":"https://api.github.com/users/alx9r/gists{/gist_id}","starred_url":"https://api.github.com/users/alx9r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alx9r/subscriptions","organizations_url":"https://api.github.com/users/alx9r/orgs","repos_url":"https://api.github.com/users/alx9r/repos","events_url":"https://api.github.com/users/alx9r/events{/privacy}","received_events_url":"https://api.github.com/users/alx9r/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-11-17T04:48:57Z","updated_at":"2015-11-26T19:11:00Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/pester/Pester/pulls/426","html_url":"https://github.com/pester/Pester/pull/426","diff_url":"https://github.com/pester/Pester/pull/426.diff","patch_url":"https://github.com/pester/Pester/pull/426.patch"},"body":"*Note: This is my first PR.  While I'm fairly confident about PowerShell and Pester, I'm a git/github novice.*\r\n\r\n------\r\n\r\nThis pull request improves the stack traces and exceptions that Pester outputs to the console.  This is similar to PR #228 except that it (hopefully) addresses the concerns with that PR.\r\n\r\nStack trace outputs are complicated by the fact that `ErrorRecord.ScriptStackTrace` is not available in PowerShell 2.  I did not find a good substitute for `.ScriptStackTrace` under PowerShell 2.  Rather, I opted to use `ErrorRecord.InvocationInfo` to produce a single-line \"stack trace\" for PowerShell 2.  This is the same technique as is already used in `Get-PesterResult` to produce `TestResult.stackTrace`.\r\n\r\nThe improvements of this PR over master and #228 are as follows:\r\n * Console Output:\r\n     * When `ErrorRecord` is a result of `PesterAssertionFailed`:\r\n        * If `.ScriptStackTrace` is **not** available: No changes. The \"Expected...But was\" messages stay the same and there are no changes to the stack trace because `.ScriptStackTrace` is unavailable.\r\n        * If `.ScriptScriptTrace` is available: The typical single line stack trace changes from eg. `at line: 36 in C:\\temp\\scriptpath.ps1` to `at <ScriptBlock>, C:\\temp\\scriptpath.ps1: line 36`.  The rest of the output is \"Expected...But was\", etc and remains unchanged.\r\n     * When an exception other than `PesterAssertionFailed` produces the `ErrorRecord`:\r\n        * Messages from exceptions are prefixed with their type name.\r\n        * The full chain of nested exceptions are output instead of just the outer exception.\r\n        * When `.ScriptStackTrace` is available the full unit-under-test stack trace is output.  The lines of the stack trace that reference Pester internals are omitted.\r\n * Implementation:\r\n    * Adds plumbing to get `.ErrorRecord` into `TestResult` for later use.  This aspect is similar to #228 which didn't seem to be a concern at that time.\r\n    * Implements `ConvertTo-FailureLines` - This does the heavy-lifting of extracting, re-ordering, and formatting just the right script trace and exception details from `ErrorRecord`.\r\n    * Adds call to `ConvertTo-FailureLines` to Write-PesterResult.\r\n\r\n### Console Output Comparison\r\n\r\nThese comparisons are using PowerShell 4.\r\n\r\n![image](https://cloud.githubusercontent.com/assets/11237922/11202422/ec2c022a-8c9c-11e5-8766-7882ba320ef7.png)\r\n\r\nOn the left is prior to this PR.  On the right is with this PR.  Note the following:\r\n * The first `throws` shows the full three lines of stack trace from the unit under test.\r\n * The second `throws` shows the nested exceptions and name prefixes `ArgumentException` and `FormatException`.\r\n * The `should` shows the slight difference in the way failed assertions are formatted.\r\n\r\nHere is another output comparison from an integration test of a deeply nest project I'm working on.  First the original output from Pester:\r\n\r\n![image](https://cloud.githubusercontent.com/assets/11237922/11202576/58ad6654-8c9e-11e5-88af-5db08578abc5.png)\r\n\r\nThat is rather short and unhelpful during integration.  The following is the exact same output except with this PR applied:\r\n\r\n![image](https://cloud.githubusercontent.com/assets/11237922/11202614/c2c58d8c-8c9e-11e5-8954-3142d1431fd0.png)\r\n\r\nNote the completeness of the exceptions and stack trace.  This is my motivation for this PR.  It speeds iteration during integration because you get this information up-front without having to spend time setting breakpoints and stepping through code to get the same information.\r\n\r\n\r\n### Next Steps\r\n\r\nPlease tell me whether you think this PR could become a candidate for merging into master.  I'm happy to put more work into improving/polishing/overhauling this PR.  But I'd like to get some feedback to make sure I'm on the right track before spending more time on this."},"comment":{"url":"https://api.github.com/repos/pester/Pester/issues/comments/159978461","html_url":"https://github.com/pester/Pester/pull/426#issuecomment-159978461","issue_url":"https://api.github.com/repos/pester/Pester/issues/426","id":159978461,"user":{"login":"alx9r","id":11237922,"avatar_url":"https://avatars.githubusercontent.com/u/11237922?v=3","gravatar_id":"","url":"https://api.github.com/users/alx9r","html_url":"https://github.com/alx9r","followers_url":"https://api.github.com/users/alx9r/followers","following_url":"https://api.github.com/users/alx9r/following{/other_user}","gists_url":"https://api.github.com/users/alx9r/gists{/gist_id}","starred_url":"https://api.github.com/users/alx9r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alx9r/subscriptions","organizations_url":"https://api.github.com/users/alx9r/orgs","repos_url":"https://api.github.com/users/alx9r/repos","events_url":"https://api.github.com/users/alx9r/events{/privacy}","received_events_url":"https://api.github.com/users/alx9r/received_events","type":"User","site_admin":false},"created_at":"2015-11-26T19:11:00Z","updated_at":"2015-11-26T19:11:00Z","body":"@nohwnd Thanks for the update and taking the time to help me with this.  I've got some homework to do to understand how to squash these commits without [causing problems](https://stackoverflow.com/questions/14534397/squash-all-my-commits-into-one-for-github-pull-request#comment41454149_14535190).  If it's OK with you I'll try get that done in the next week (assuming it's still possible to squash them)."}}