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

Script scope variables not defined for tests #2028

Closed
rjmholt opened this issue Jul 14, 2021 · 4 comments
Closed

Script scope variables not defined for tests #2028

rjmholt opened this issue Jul 14, 2021 · 4 comments

Comments

@rjmholt
Copy link

rjmholt commented Jul 14, 2021

General summary of the issue

PSScriptAnalyzer migrated to Pester 5 about a year ago, but recently we've seen some new test failures in CI.

I wasn't able to reproduce the issue in my local clone, and my suspicion is that my local Pester version (5.1-rc1) doesn't have the issue.

In CI we seem to be using 5.0.2.

I'm working on the fix in PowerShell/PSScriptAnalyzer#1697.

Essentially:

It looks like we're using Pester 5.0.2 in PS 4 and I'm wondering what the right solution is here and why it might be behaving differently across different platforms.

@rjmholt
Copy link
Author

rjmholt commented Jul 15, 2021

So I've fixed the original issue, but had to duplicate code because some variables were needed in both the discovery and test phases.

Now I'm hitting a strange problem where our Pester tests call a module which calls Should and we get something like this:

[-] UseConsistentIndentation.When a multi-line command is given.Should indent properly after line continuation (backtick) character 231ms (225ms|6ms)
 CommandNotFoundException: The term 'Should' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
 at Test-CorrectionExtentFromContent, C:\projects\psscriptanalyzer\Tests\PSScriptAnalyzerTestHelper.psm1:49
 at <ScriptBlock>, C:\projects\psscriptanalyzer\Tests\Rules\UseConsistentIndentation.tests.ps1:286

Link to the test code and the helper function definition.

This only happens in PowerShell 4; the tests all pass and run correctly in PS 5.1 and 7 on all platforms.

@rjmholt
Copy link
Author

rjmholt commented Jul 15, 2021

I managed to find a workaround for this: PowerShell/PSScriptAnalyzer@1f8f793.

@fflaten
Copy link
Collaborator

fflaten commented Jul 15, 2021

This only happens in PowerShell 4; the tests all pass and run correctly in PS 5.1 and 7 on all platforms.

Thanks. Probably same as #1831. Can you reproduce consistently? Possible to run this in a different CI or server with PSv4? Both issues point to Appveyor WMF4 image it seems.

@rjmholt
Copy link
Author

rjmholt commented Jul 15, 2021

Sounds like this is indeed #1831. I don't have easy access to another instance unfortunately.

@rjmholt rjmholt closed this as completed Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants