Skip to content

Conversation

@KevinMarquette
Copy link
Contributor

@KevinMarquette KevinMarquette commented Mar 11, 2018

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:

PR Checklist

@KevinMarquette KevinMarquette changed the title WIP: Use new Pester syntax: -Parameter for Pester tests in Utility Use new Pester syntax: -Parameter for Pester tests in Utility Mar 13, 2018
else
{
,$val1 | Should BeOfType "System.Array"
,$val1 | Should -BeOfType "System.Array"
Copy link
Collaborator

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
Copy link
Collaborator

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.

Describe "Get-Random" -Tags "CI" {
It "Should return a random number greater than -1 " {
Get-Random | Should BeGreaterThan -1
Get-Random | Should -BeGreaterThan -1
Copy link
Collaborator

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.

$rs = Get-RunspaceDebug
$rs | Should -Not -BeNullOrEmpty
$rs[0] | Should BeOfType "Microsoft.PowerShell.Commands.PSRunspaceDebug"
$rs[0] | Should -BeOfType "Microsoft.PowerShell.Commands.PSRunspaceDebug"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space.

$comObject = New-Object -ComObject $name
$comObject.$Property | Should -Not -BeNullOrEmpty
$comObject.$Property | should beoftype $Type
$comObject.$Property | Should -beoftype $Type
Copy link
Collaborator

@iSazonov iSazonov Mar 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space and case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"
Copy link
Collaborator

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.

It "returns a new guid" {
$guid = New-Guid
$guid | Should BeOfType System.Guid
$guid | Should -BeOfType System.Guid
Copy link
Collaborator

@iSazonov iSazonov Mar 23, 2018

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
Copy link
Collaborator

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.

@KevinMarquette
Copy link
Contributor Author

I cleaned up the extra spaces across all files using \| Should -(\w+)\s\s+ to find them all.

catch
{
$_.FullyQualifiedErrorId | Should Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand"
$_.FullyQualifiedErrorId | Should -Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand"
Copy link
Member

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..."

&{
Set-Variable foo baz
$foo | should be baz
$foo | Should -Be baz
Copy link
Member

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


{ [Test.AddType.BasicTest1]::Add1(1, 2) } | Should Throw
{ [Test.AddType.BasicTest2]::Add2(3, 4) } | Should Throw
{ [Test.AddType.BasicTest1]::Add1(1, 2) } | Should -Throw
Copy link
Member

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).

@SteveL-MSFT
Copy link
Member

I think @kalgiz already took care of these tests with her PR #6366

@KevinMarquette
Copy link
Contributor Author

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.

@iSazonov
Copy link
Collaborator

@KevinMarquette Thanks for your contribution!
Sorry, we must explicitly write in the original Issue who grab the job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants