Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow paths to be pipelined to Invoke-ScriptAnalyzer #1040

Merged
merged 7 commits into from
Jul 19, 2018

Conversation

edyoung
Copy link
Contributor

@edyoung edyoung commented Jul 17, 2018

PR Summary

Resolves issue #1039

Allow Get-ChildItem *.psm1 -Recurse -Exclude *.test.ps1 | Invoke-ScriptAnalyzer

Also fix some errors I was getting from test scripts. Unclear why others weren't seeing that.

PR Checklist

Note: Tick the boxes below that apply to this pull request by putting an x between the square brackets. Please mark anything not applicable to this PR NA.

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • User facing documentation needed
  • Change is not breaking
  • Make sure you've added a new test if existing tests do not effectively test the code changed
  • This PR is ready to merge and is not work in progress
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready

@edyoung edyoung changed the title Add exclude switch Allow paths to be pipelined to Invoke-ScriptAnalyzer Jul 17, 2018
@edyoung
Copy link
Contributor Author

edyoung commented Jul 17, 2018

AppVeyor failure appears unrelated.

It "Can be piped from Get-ChildItem" {
$piped = ( Get-ChildItem -Path $directory -Filter TestTestPath*.ps1 | Invoke-ScriptAnalyzer)
$explicit = Invoke-ScriptAnalyzer -Path $directory\TestTestPath*.ps1
$piped.Count -eq $explicit.Count | Should -BeTrue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would result in a much better error message if the test fails:

$piped.Count  | Should -Be $explicit.Count

@@ -9,7 +9,7 @@ if (-not (Test-PSEditionCoreCLR))
$null,"Wow6432Node" | ForEach-Object {
try
{
Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force
Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force -ErrorAction SilentlyContinue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please elaborate on the error that you were getting that led you to apply this change? On which environment (platform and ps version) did you see it?

Copy link
Contributor Author

@edyoung edyoung Jul 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

running tests in non-elevated windows powershell on Windows 10. Despite the try/catch errors are shown when this fails to update HKLM key.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks for the info. This does not happen on my machine, I am wondering if this could be caused by some group policy in your environment. Although it seems that this test code should reviewed again and possibly refactored, I think we can still accept your changes to it.

Copy link
Collaborator

@bergmeister bergmeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, the fix looks OK to me, thanks for improving PSSA. I pushed an empty commit to restart CI but you are right that this was probably a sporadic failure, the error message indicated though that the test failure was caused by a PSSA bug (I suspect it was one of the known multi-threading issues).
I left one minor comment for an improved test assertion and a question regarding the unrelated test improvement.
But the next time, please follow the GitHub flow model and create the branch in your fork.

@@ -66,7 +66,7 @@ Describe "Test importing correct customized rules" {
$null,"Wow6432Node" | ForEach-Object {
try
{
Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force
Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force -EA SilentlyContinue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: Use -ErrorAction SilentlyContinue for consistency, readability and to not rely on parameter aliases

Copy link
Collaborator

@bergmeister bergmeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok, overall, only a minor nit. The first CI run that I re-triggered had a problem with Push-AppVeyorArtifact, I raised this issue with AppVeyor as it seems to be a (repeated) regression from their side: appveyor/ci#2183
The 2nd build hung and timed out after 3h, I therefore started it again. We have not seen such behaviour before, therefore it is probably due to environmental changes in AppVeyor....

@bergmeister bergmeister added this to the 1.18 milestone Jul 18, 2018
@bergmeister
Copy link
Collaborator

Appveyor responded and said they fixed the issue mentioned above. Will close and re-open to trigger CI again

@bergmeister bergmeister reopened this Jul 19, 2018
@JamesWTruher JamesWTruher merged commit b79e2f5 into development Jul 19, 2018
@bergmeister bergmeister deleted the add_exclude_switch branch July 24, 2018 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants