| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| manifestInfo.AddDetectedCmdletExport(detectedCmdlet); | ||
| } | ||
| bool found = false; | ||
| PSModuleInfo module = LoadModule(scriptFile, |
There was a problem hiding this comment.
Can you use named parameters. Example: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/named-and-optional-arguments
Sorry, something went wrong.
There was a problem hiding this comment.
That is actually existing code; I didn't change it; looks like Github's diff'er has room for improvement :) - see picture below.
Anyway, there are multiple LoadModule calls like this one throughout the file, so if refactoring is to be done - it has to be done to all of them - and that is out of scope of this bugfix.
Sorry, something went wrong.
| } | ||
| foreach (string detectedCmdlet in module.ExportedCmdlets.Keys) | ||
| { | ||
| manifestInfo.AddDetectedCmdletExport(detectedCmdlet); |
There was a problem hiding this comment.
AddDetected* methods from PSModuleInfo in most cases seem to be called multiple times using a for loop. Will it make sense to add an overload which accepts IEnumerable?
Sorry, something went wrong.
There was a problem hiding this comment.
Maybe. But as previous comment - this would be refactoring of unrelated code - out of scope of this bug fix.
Sorry, something went wrong.
| Import-Module .\module2.psd1 -Version 1.0 | ||
| Get-Content out.txt | Should Be '21' | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
Add new line at the end.
Sorry, something went wrong.
There was a problem hiding this comment.
Fixed.
Sorry, something went wrong.
|
|
||
| AfterAll { | ||
| Pop-Location | ||
| #Remove-Item $moduleRootPath -Recurse -Force -ErrorAction SilentlyContinue |
There was a problem hiding this comment.
Remove commented line.
Sorry, something went wrong.
There was a problem hiding this comment.
Fixed.
Sorry, something went wrong.
| Remove-Item out.txt -Force -ErrorAction SilentlyContinue | ||
| } | ||
|
|
||
| It "Verify ScriptsToProcess are executed for top-level module" { |
There was a problem hiding this comment.
You may want to take a look at TestCases parameter of Pester It.
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks for suggestion; I did give it a try. I believe that semantic difference between these tests is larger than what TestCases parameter is aimed for; plus I don't like that TestCases parameter has worse logging (same test name repeated several times vs individual, descriptive test names in case of individual 'It's).
Sorry, something went wrong.
There was a problem hiding this comment.
You can have custom test case names for individual test cases. Have look at: https://github.com/PowerShell/PowerShell/blob/02b5f357a20e6dee9f8e60e3adb9025be3c94490/test/powershell/engine/ParameterBinding/NullableBooleanDCR.Tests.ps1
Here the parameters will be parameter splat for Import-Module, and expected result, test name.
Sorry, something went wrong.
There was a problem hiding this comment.
That is actually cool; thank you!
I've updated tests.
Sorry, something went wrong.
There was a problem hiding this comment.
Good idea; I've updated tests.
Sorry, something went wrong.
| BeforeAll { | ||
| $moduleRootPath = Join-Path $TestDrive 'TestModules' | ||
| New-Item $moduleRootPath -ItemType Directory -Force | Out-Null | ||
| Push-Location $moduleRootPath |
There was a problem hiding this comment.
Why do you need to push location? Can you use full paths for all cmdlets like New-Item, New-ModuleManifest etc?
Sorry, something went wrong.
There was a problem hiding this comment.
I chose push location specifically because I didn't want to deal with full paths. :)
Sorry, something went wrong.
| Remove-Item out.txt -Force -ErrorAction SilentlyContinue | ||
| } | ||
|
|
||
| It "Verify ScriptsToProcess are executed for top-level module" { |
There was a problem hiding this comment.
You can have custom test case names for individual test cases. Have look at: https://github.com/PowerShell/PowerShell/blob/02b5f357a20e6dee9f8e60e3adb9025be3c94490/test/powershell/engine/ParameterBinding/NullableBooleanDCR.Tests.ps1
Here the parameters will be parameter splat for Import-Module, and expected result, test name.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This is fix for #3738 "ScriptsToProcess not honored when Import-Module is passed -Version param".
The bug was cased by existing check in LoadModule functions:
When loading usual module files, this check is valid;
However, same LoadModule function is used to load ScriptsToProcess - and this when this check was
triggered and ScriptsToProcess were not executed.
The fix is to work around that condition for ScriptsToProcess in the same way it is currently done for NestedModules - temporary reset the version info for the duration of processing ScriptsToProcess / NestedModules.
Test results before the fix:

Test results after the fix:
