Use new Pester syntax: -Parameter for Pester tests in Utility#6359
Use new Pester syntax: -Parameter for Pester tests in Utility#6359KevinMarquette wants to merge 24 commits intoPowerShell:masterfrom
Conversation
| else | ||
| { | ||
| ,$val1 | Should BeOfType "System.Array" | ||
| ,$val1 | Should -BeOfType "System.Array" |
There was a problem hiding this comment.
Extra spaces. Below in the file too.
| $result | Should BeOfType $type | ||
| $result | Should -BeGreaterThan $greaterThan | ||
| $result | Should -BeLessThan $lessThan | ||
| $result | Should -BeOfType $type |
There was a problem hiding this comment.
Extra space in three lines.
| Describe "Get-Random" -Tags "CI" { | ||
| It "Should return a random number greater than -1 " { | ||
| Get-Random | Should BeGreaterThan -1 | ||
| Get-Random | Should -BeGreaterThan -1 |
There was a problem hiding this comment.
Extra space. Below in the file too.
| $rs = Get-RunspaceDebug | ||
| $rs | Should -Not -BeNullOrEmpty | ||
| $rs[0] | Should BeOfType "Microsoft.PowerShell.Commands.PSRunspaceDebug" | ||
| $rs[0] | Should -BeOfType "Microsoft.PowerShell.Commands.PSRunspaceDebug" |
| $comObject = New-Object -ComObject $name | ||
| $comObject.$Property | Should -Not -BeNullOrEmpty | ||
| $comObject.$Property | should beoftype $Type | ||
| $comObject.$Property | Should -beoftype $Type |
There was a problem hiding this comment.
case is corrected
| It "Should works proper with new-timespan"{ | ||
| $results = New-TimeSpan -Days 10 -Hours 10 -Minutes 10 -Seconds 10 | ||
| $results | Should BeOfType "System.Timespan" | ||
| $results | Should -BeOfType "System.Timespan" |
There was a problem hiding this comment.
Extra space. Below in the file too.
| It "returns a new guid" { | ||
| $guid = New-Guid | ||
| $guid | Should BeOfType System.Guid | ||
| $guid | Should -BeOfType System.Guid |
| $stopwatch.ElapsedMilliseconds | Should BeGreaterThan 500 | ||
| $stopwatch.ElapsedMilliseconds | Should BeLessThan 1500 | ||
| $stopwatch.ElapsedMilliseconds | Should -BeGreaterThan 500 | ||
| $stopwatch.ElapsedMilliseconds | Should -BeLessThan 1500 |
There was a problem hiding this comment.
Extra spaces in two lines.
|
I cleaned up the extra spaces across all files using |
| catch | ||
| { | ||
| $_.FullyQualifiedErrorId | Should Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand" | ||
| $_.FullyQualifiedErrorId | Should -Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand" |
There was a problem hiding this comment.
We should update these tests to use:
{ ...scriptblock... } | Should -Throw -ErrorId "...fully qualified error id..."| &{ | ||
| Set-Variable foo baz | ||
| $foo | should be baz | ||
| $foo | Should -Be baz |
There was a problem hiding this comment.
For strings, unless we explicitly want case insensitive matching, we should use -BeExactly
|
|
||
| { [Test.AddType.BasicTest1]::Add1(1, 2) } | Should Throw | ||
| { [Test.AddType.BasicTest2]::Add2(3, 4) } | Should Throw | ||
| { [Test.AddType.BasicTest1]::Add1(1, 2) } | Should -Throw |
There was a problem hiding this comment.
We should never have just Should -Throw, please get the error being thrown and add -ErrorId. We want to prevent the test from passing if it throws for a different reason than what is being tested (like out of memory, for example).
|
Sorry about that. I didn't see that other pull request then I did the work and submitted this PR. I reviewed the merge conflicts that now exist and this PR has nothing new to add any more. |
|
@KevinMarquette Thanks for your contribution! |
PR Summary
Use new Pester syntax: -Parameter for Pester tests in Utility. #6245
Because of the number of tests in Utility, this PR only contains the updated Pester syntax. Issues, functional, or test style changes will be handled in separate PRs.
Items identified so far that need issues created:
Should -Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)needs to be refactoredShould -Be @secondRandomNumbershould beShould -Be @secondRandomNumberand testedShould -Be #nothing. it should be Nothing at all.should beShould -BeNullOrEmptyShould -Not -Be NullOrEmptyshould beShould -Not -BeNullOrEmptyand tested because of functional changePR 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 tests