8000 Use new Pester syntax: -Parameter for Pester tests in Utility by KevinMarquette · Pull Request #6359 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

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

Closed

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.

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

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

@@ -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
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

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

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

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

@@ -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
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

}

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
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
0