{"action":"created","issue":{"url":"https://api.github.com/repos/pester/Pester/issues/1172","repository_url":"https://api.github.com/repos/pester/Pester","labels_url":"https://api.github.com/repos/pester/Pester/issues/1172/labels{/name}","comments_url":"https://api.github.com/repos/pester/Pester/issues/1172/comments","events_url":"https://api.github.com/repos/pester/Pester/issues/1172/events","html_url":"https://github.com/pester/Pester/pull/1172","id":391826554,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM5MjM0MDE5","number":1172,"title":"General code cleanup","user":{"login":"fourpastmidnight","id":6895593,"node_id":"MDQ6VXNlcjY4OTU1OTM=","avatar_url":"https://avatars0.githubusercontent.com/u/6895593?v=4","gravatar_id":"","url":"https://api.github.com/users/fourpastmidnight","html_url":"https://github.com/fourpastmidnight","followers_url":"https://api.github.com/users/fourpastmidnight/followers","following_url":"https://api.github.com/users/fourpastmidnight/following{/other_user}","gists_url":"https://api.github.com/users/fourpastmidnight/gists{/gist_id}","starred_url":"https://api.github.com/users/fourpastmidnight/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fourpastmidnight/subscriptions","organizations_url":"https://api.github.com/users/fourpastmidnight/orgs","repos_url":"https://api.github.com/users/fourpastmidnight/repos","events_url":"https://api.github.com/users/fourpastmidnight/events{/privacy}","received_events_url":"https://api.github.com/users/fourpastmidnight/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-12-17T17:59:05Z","updated_at":"2019-01-03T18:11:10Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/pester/Pester/pulls/1172","html_url":"https://github.com/pester/Pester/pull/1172","diff_url":"https://github.com/pester/Pester/pull/1172.diff","patch_url":"https://github.com/pester/Pester/pull/1172.patch"},"body":"This PR just contains some general code cleanups:\r\n\r\n1. Ensuring that the `$SafeCommand` version of `Where-Object` is used in files where in other instances, the `$SafeCommands` instance was being used\r\n2. Ensuring that when checking for null, that `$null` is on the LHS of the equality check\r\n3. Ensuring that aliases are not used (e.g. `ForEach-Object` instead of `foreach` when on the RHS of a pipe)\r\n\r\nI'm sure there are more things that could be cleaned up, but these were pointed out by PSScriptAnalyzer in a project I'm working on where I've taken a private dependency on a customized version of Pester.\r\n\r\n**NOTE:** I ran the tests locally, and I'm getting a lot of failures related to not being able to convert a breakpoint to a boolean. Not sure if my changes are causing this (I can't see how) or whether these are the result of recent changes due to the Assert-MockCalled issue work that's been done over the past few days. I'll update this PR description when I get more information, but posting this PR for now."},"comment":{"url":"https://api.github.com/repos/pester/Pester/issues/comments/451228583","html_url":"https://github.com/pester/Pester/pull/1172#issuecomment-451228583","issue_url":"https://api.github.com/repos/pester/Pester/issues/1172","id":451228583,"node_id":"MDEyOklzc3VlQ29tbWVudDQ1MTIyODU4Mw==","user":{"login":"fourpastmidnight","id":6895593,"node_id":"MDQ6VXNlcjY4OTU1OTM=","avatar_url":"https://avatars0.githubusercontent.com/u/6895593?v=4","gravatar_id":"","url":"https://api.github.com/users/fourpastmidnight","html_url":"https://github.com/fourpastmidnight","followers_url":"https://api.github.com/users/fourpastmidnight/followers","following_url":"https://api.github.com/users/fourpastmidnight/following{/other_user}","gists_url":"https://api.github.com/users/fourpastmidnight/gists{/gist_id}","starred_url":"https://api.github.com/users/fourpastmidnight/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fourpastmidnight/subscriptions","organizations_url":"https://api.github.com/users/fourpastmidnight/orgs","repos_url":"https://api.github.com/users/fourpastmidnight/repos","events_url":"https://api.github.com/users/fourpastmidnight/events{/privacy}","received_events_url":"https://api.github.com/users/fourpastmidnight/received_events","type":"User","site_admin":false},"created_at":"2019-01-03T18:11:10Z","updated_at":"2019-01-03T18:11:10Z","author_association":"CONTRIBUTOR","body":"Spoke too soon. I found the offending change--but it doesn't change the fact that the tests are not failing locally. So the question is, what's different about the CI environments which cause the tests to fail?\r\n\r\nThe change is in `Coverage.ps1` in `Exit-CoverageAnalysis`. While cleaning up some issues spotted by PSScriptAnalyzer, specifically, comparison with `$null` where `$null` was no the RHS of the `-ne` operator. Null comparisons should be performed with `$null` on the LHS. Is there something special about the following line?\r\n\r\n```diff\r\n- $breakpoints = @($PesterState.CommandCoverage.Breakpoint) -ne $null\r\n+ $breakpoints = $null -ne @($PesterState.CommandCoverage.Breakpoint)\r\n  if ($breakpoints.Count -gt 0)\r\n  {\r\n      & $SafeCommands['Remove-PSBreakpoint'] -Breakpoint $breakpoints\r\n  }\r\n```\r\n\r\nLooking at both lines of the diff, it would appear the order of operations should be:\r\n\r\n1. Compare the array `@($PesterState.CommandCoverage.Breakpoint)` to `$null`\r\n2. Store the result in `$breakpoints`. This implies that `$breakpoints` is a Boolean.\r\n3. When executing the `if` condition, since `$breakpoints` is a Boolean, it doesn't have a `Count` property, so that should be, at worst, an InvalidOperationException or NullReferenceException, and at best, False, which is 0, and the `if` block would never execute.\r\n\r\nBut when I executed the original line in Powershell where `$null` is on the RHS of the `-ne` operator, $breakpoints is, in fact, a `System.Object[]`! Looks like I need to review Powershell's operator precedence rules?? Wow, that's really unexpected."}}
{"actor":{"display_login":"fourpastmidnight"}}