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
Make InModuleScope-parameters available as variables in scriptblock #1957
Conversation
@nohwnd Am I on the right track? I've yet to understand when to set sessionstate vs scriptblock hints, so I know they're wrong. Haven't used the debug-messages before, so not sure what I'd expect or what would be useful in this scenario. |
LGTM, merge if you are done, or re-request review later :) |
Added another test and updated help with example. Good to go. I don't have permissions to merge with protected branch, so your turn 👍 |
I've just tested this functionality on a test suite and am not getting the expected result. I am not sure though if I'm getting this right so it may be something I'm doing wrong. Should I raise a new issue? I've have a sample module that you can test this with. Effectively, the old test code defines the InModuleScope statement as: ) {
InModuleScope ims -Parameters @{ Scenario = $Scenario; Result = $Result; ExpectedSuccess = $ExpectedSuccess; } {
param(
[string]$Scenario,
[object]$Result,
[boolean]$ExpectedSuccess
) Where the template parameters are Scenario, Result and ExpectedSuccess. I've changed this to become: ) {
InModuleScope ims {
Please note that the binding error I'm currently seeing is with $Result:
... and $Result can be a string or a PSCustomObject. The whole module and test suite are available at ims If you really need to raise a new issue, then let me know. I suspect that I'm not doing this the way as intended, so I'd like this to be checked first before I raise an issue. Cheers, |
For future readers; as mentioned in the discussion, this PR removes the requirement for the param-block only. You still need to specify |
InModuleScope
currently requires param-block to make parameters available by name (if not, only available as arguments). This PR add parameters as dynamic variables inside the scriptblock similar to how it works with mocks.Fix #1603
PR Checklist
Create Pull Request
to mark it as a draft. PR can be markedReady for review
when it's ready.