Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upVersion checking tests for Import-Module #7499
Conversation
rjmholt
added some commits
Aug 10, 2018
rjmholt
changed the title
Version checking tests for Import-Module
WIP: Version checking tests for Import-Module
Aug 11, 2018
This comment has been minimized.
This comment has been minimized.
|
Have marked as WIP while I add GUID tests |
rjmholt
changed the title
WIP: Version checking tests for Import-Module
Version checking tests for Import-Module
Aug 13, 2018
rjmholt
changed the title
Version checking tests for Import-Module
WIP: Version checking tests for Import-Module
Aug 13, 2018
rjmholt
changed the title
WIP: Version checking tests for Import-Module
Version checking tests for Import-Module
Aug 14, 2018
This comment has been minimized.
This comment has been minimized.
|
Tests marked |
rjmholt
requested review from
daxian-dbw,
BrucePay,
SteveL-MSFT and
anmenaga
Aug 14, 2018
SteveL-MSFT
requested changes
Aug 16, 2018
|
I'll wait for some refactoring before reviewing in detail |
| } | ||
| if ($Guid) | ||
| { | ||
| $mod.Guid | Should -Be $actualGuid |
This comment has been minimized.
This comment has been minimized.
SteveL-MSFT
Aug 16, 2018
Member
This assert is already handled by line 189 so this doesn't need to be here
| } | ||
| if ($Guid) | ||
| { | ||
| $mod.Guid | Should -Be $actualGuid |
This comment has been minimized.
This comment has been minimized.
| } | ||
| if ($Guid) | ||
| { | ||
| $mod.Guid | Should -Be $actualGuid |
This comment has been minimized.
This comment has been minimized.
| } | ||
| if ($Guid) | ||
| { | ||
| $mod.Guid | Should -Be $actualGuid |
This comment has been minimized.
This comment has been minimized.
| } | ||
| if ($Guid) | ||
| { | ||
| $mod.Guid | Should -Be $actualGuid |
This comment has been minimized.
This comment has been minimized.
| } | ||
| if ($Guid) | ||
| { | ||
| $mod.Guid | Should -Be $actualGuid |
This comment has been minimized.
This comment has been minimized.
| } | ||
| if ($Guid) | ||
| { | ||
| $mod.Guid | Should -Be $actualGuid |
This comment has been minimized.
This comment has been minimized.
| } | ||
| if ($Guid) | ||
| { | ||
| $mod.Guid | Should -Be $actualGuid |
This comment has been minimized.
This comment has been minimized.
|
|
||
| $mod = Import-Module -FullyQualifiedName $modSpec -PassThru | ||
|
|
||
| $mod.Name | Should -Be $moduleName |
This comment has been minimized.
This comment has been minimized.
SteveL-MSFT
Aug 16, 2018
Member
This validation code is very similar throughout this script. It seems you should have a Validate type function instead of the same code repeated
| if ($ModuleVersion -and $MaximumVersion -and ($ModuleVersion -ge $MaximumVersion)) | ||
| { | ||
| $sb | Should -Throw -ErrorId 'ArgumentOutOfRange,Microsoft.PowerShell.Commands.ImportModuleCommand' | ||
| return |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
rjmholt
Aug 16, 2018
•
Author
Member
Given the choice I prefer if-return, because:
- The reader knows that they can stop reading when they see
return - Less indentation and less horizontal programming
- Closer to pattern match/guard style, which I find helps the "exhaust all possibilities" mentality
- The
returnworks as a forcing function to not juggle state
I see many instances in the code base that I imagine initially started as innocent if-elses that could have been if-returns, but whose complexity has since increased due to that choice:
PowerShell/src/System.Management.Automation/engine/Modules/ImportModuleCommand.cs
Lines 1698 to 1783 in 01634e4
PowerShell/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs
Lines 6351 to 6506 in 01634e4
PowerShell/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs
Lines 3646 to 3715 in 01634e4
To my mind, using else just before the end of a function is a useless use of else.
rjmholt
added some commits
Aug 16, 2018
SteveL-MSFT
requested changes
Aug 16, 2018
| { | ||
| param( | ||
| $Module, | ||
| [string]$Name, |
This comment has been minimized.
This comment has been minimized.
SteveL-MSFT
Aug 16, 2018
Member
Does it make sense to default this to $moduleName, $guid to $actualGuid, and $version to $actualVersion since that is used by most (all?) of the tests?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
rjmholt
Aug 17, 2018
Author
Member
Worth noting that the $moduleName one relies on dynamic scope. I kept the other parameters, since I think it's less confusing. But it's not quite consistent with $moduleName.
|
|
||
| if ($ModuleVersion -and $MaximumVersion -and ($ModuleVersion -ge $MaximumVersion)) | ||
| { | ||
| $sb | Should -Throw -ErrorId 'ArgumentOutOfRange,Microsoft.PowerShell.Commands.ImportModuleCommand' |
This comment has been minimized.
This comment has been minimized.
SteveL-MSFT
Aug 16, 2018
Member
If all the negative test cases result in a terminating error, it may be simpler to have the FQErrorId as part of the testcase variation so this would simply be
$sb | Should -Throw -ErrorId $ErrodId
This comment has been minimized.
This comment has been minimized.
rjmholt
Aug 17, 2018
Author
Member
Just realised this second suggestion doesn't work just yet; Import-Module -MaximumVersion -MinimumVersion throws a different error to Import-Module @{ ModuleVersion = ; MaximumVersion = }.
That's what #7347 changes.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@SteveL-MSFT was the feedback addressed? |
SteveL-MSFT
approved these changes
Sep 18, 2018
daxian-dbw
self-assigned this
Sep 20, 2018
daxian-dbw
closed this
Sep 20, 2018
daxian-dbw
reopened this
Sep 20, 2018
This comment has been minimized.
This comment has been minimized.
|
Reopen the PR to restart stuck CIs |
This comment has been minimized.
This comment has been minimized.
|
@daxian-dbw this can be merged now. |
rjmholt commentedAug 11, 2018
PR Summary
Adds a number of tests to check the version of the module to import against constraints given to the cmdlet.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.[feature]if the change is significant or affects feature testsThis adds testing for #7125