-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Use new Pester syntax: -Parameter for Pester tests in Utility #6359
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
Use new Pester syntax: -Parameter for Pester tests in Utility #6359
Conversation
} | ||
else | ||
{ | ||
,$val1 | Should BeOfType "System.Array" | ||
,$val1 | Should -BeOfType "System.Array" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra space in three lines.
@@ -93,23 +93,23 @@ Describe "Get-Random DRT Unit Tests" -Tags "CI" { | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra space. Below in the file too.
@@ -7,7 +7,7 @@ Describe "Get-RunspaceDebug" -Tags "CI" { | |||
It "Should return Microsoft.Powershell.Commands.PSRunspaceDebug as the return type" { | |||
$rs = Get-RunspaceDebug | |||
$rs | Should -Not -BeNullOrEmpty | |||
$rs[0] | Should BeOfType "Microsoft.PowerShell.Commands.PSRunspaceDebug" | |||
$rs[0] | Should -BeOfType "Microsoft.PowerShell.Commands.PSRunspaceDebug" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra space.
@@ -200,7 +200,7 @@ try | |||
param($Name, $Property, $Type) | |||
$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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra space and case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
case is corrected
@@ -4,7 +4,7 @@ Describe "New-TimeSpan DRT Unit Tests" -Tags "CI" { | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra space. Below in the file too.
@@ -4,7 +4,7 @@ Describe "New-Guid" -Tags "CI" { | |||
|
|||
It "returns a new guid" { | |||
$guid = New-Guid | |||
$guid | Should BeOfType System.Guid | |||
$guid | Should -BeOfType System.Guid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra spaces.
$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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra spaces in two lines.
I cleaned up the extra spaces across all files using |
@@ -11,7 +11,7 @@ Describe "Add-Member DRT Unit Tests" -Tags "CI" { | |||
} | |||
catch | |||
{ | |||
$_.FullyQualifiedErrorId | Should Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand" | |||
$_.FullyQualifiedErrorId | Should -Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should update these tests to use:
{ ...scriptblock... } | Should -Throw -ErrorId "...fully qualified error id..."
@@ -35,7 +35,7 @@ Describe "Clear-Variable DRT Unit Tests" -Tags "CI" { | |||
Set-Variable foo bar | |||
&{ | |||
Set-Variable foo baz | |||
$foo | should be baz | |||
$foo | Should -Be baz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For strings, unless we explicitly want case insensitive matching, we should use -BeExactly
} | ||
|
||
It "Can compile C# files" { | ||
|
||
{ [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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 @secondRandomNumber
should beShould -Be @secondRandomNumber
and testedShould -Be #nothing. it should be Nothing at all.
should beShould -BeNullOrEmpty
Should -Not -Be NullOrEmpty
should beShould -Not -BeNullOrEmpty
and tested because of functional changePR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files 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