Skip to content
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 in SDK and Provider tests #6490

Merged
merged 3 commits into from
Mar 29, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions test/powershell/Provider/Pester.AutomountedDrives.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@ Describe "Test suite for validating automounted PowerShell drives" -Tags @('Feat
Context "Validating automounting FileSystem drives" {

It "Test automounting using subst.exe" -Skip:$SubstNotFound {
& $powershell -noprofile -command "& '$AutomountSubstDriveScriptPath' -FullPath '$substDir'" | Should Be "Drive found"
& $powershell -noprofile -command "& '$AutomountSubstDriveScriptPath' -FullPath '$substDir'" | Should -BeExactly "Drive found"
}

It "Test automounting using New-VHD/Mount-VHD" -Skip:$VHDToolsNotFound {
& $powershell -noprofile -command "& '$AutomountVHDDriveScriptPath' -VHDPath '$vhdPath'" | Should Be "Drive found"
& $powershell -noprofile -command "& '$AutomountVHDDriveScriptPath' -VHDPath '$vhdPath'" | Should -BeExactly "Drive found"
}
}

Context "Validating automounting FileSystem drives from modules" {

It "Test automounting using subst.exe" -Skip:$SubstNotFound {
& $powershell -noprofile -command "& '$AutomountSubstDriveScriptPath' -useModule -FullPath '$substDir'" | Should Be "Drive found"
& $powershell -noprofile -command "& '$AutomountSubstDriveScriptPath' -useModule -FullPath '$substDir'" | Should -BeExactly "Drive found"
}

It "Test automounting using New-VHD/Mount-VHD" -Skip:$VHDToolsNotFound {
$vhdPath = Join-Path $TestDrive 'TestAutomountVHD.vhd'
& $powershell -noprofile -command "& '$AutomountVHDDriveScriptPath' -useModule -VHDPath '$vhdPath'" | Should Be "Drive found"
& $powershell -noprofile -command "& '$AutomountVHDDriveScriptPath' -useModule -VHDPath '$vhdPath'" | Should -BeExactly "Drive found"
}
}
}
13 changes: 4 additions & 9 deletions test/powershell/Provider/ProviderIntrinsics.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@ Describe "ProviderIntrinsics Tests" -tags "CI" {
setup -d TestDir
}
It 'If a childitem exists, HasChild method returns $true' {
$ExecutionContext.InvokeProvider.ChildItem.HasChild("$TESTDRIVE") | Should be $true
$ExecutionContext.InvokeProvider.ChildItem.HasChild("$TESTDRIVE") | Should -BeTrue
}
It 'If a childitem does not exist, HasChild method returns $false' {
$ExecutionContext.InvokeProvider.ChildItem.HasChild("$TESTDRIVE/TestDir") | Should be $false
$ExecutionContext.InvokeProvider.ChildItem.HasChild("$TESTDRIVE/TestDir") | Should -BeFalse
}
It 'If the path does not exist, HasChild throws an exception' {
try {
$ExecutionContext.InvokeProvider.ChildItem.HasChild("TESTDRIVE/ThisDirectoryDoesNotExist")
throw "Execution OK"
}
catch {
$_.fullyqualifiederrorid | should be "ItemNotFoundException"
}
{$ExecutionContext.InvokeProvider.ChildItem.HasChild("TESTDRIVE/ThisDirectoryDoesNotExist")} |
Copy link
Member

Choose a reason for hiding this comment

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

nit: please add whitespace after open brace and before closing brace. same for other ones below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made this correction to this file and 1 other that had the same issue.

Should -Throw -ErrorId 'ItemNotFoundException'
}
}

12 changes: 6 additions & 6 deletions test/powershell/SDK/Json.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ Describe "Json.NET LINQ Parsing" -tags "CI" {
}

It "Should return data via Item()" {
[string]$json.Item("Name") | Should Be "Zaphod Beeblebrox"
[string]$json.Item("Name") | Should -BeExactly "Zaphod Beeblebrox"
}

It "Should return data via []" {
[string]$json["Planet"] | Should Be "Betelgeuse"
[string]$json["Planet"] | Should -BeExactly "Betelgeuse"
}

It "Should return nested data via Item().Item()" {
[int]$json.Item("Appendages").Item("Heads") | Should Be 2
[int]$json.Item("Appendages").Item("Heads") | Should -Be 2
}

It "Should return nested data via [][]" {
[int]$json["Appendages"]["Arms"] | Should Be 3
[int]$json["Appendages"]["Arms"] | Should -Be 3
}

It "Should return correct array count" {
$json["Achievements"].Count | Should Be 4
$json["Achievements"].Count | Should -Be 4
}

It "Should return array data via [n]" {
[string]$json["Achievements"][3] | Should Be "One hoopy frood"
[string]$json["Achievements"][3] | Should -BeExactly "One hoopy frood"
}
}
77 changes: 26 additions & 51 deletions test/powershell/SDK/PSDebugging.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Describe "PowerShell Command Debugging" -tags "CI" {

if (!$process.HasExited)
{
$process.HasExited | Should Be $true
$process.HasExited | Should -BeTrue
$process.Kill()
}
}
Expand All @@ -54,7 +54,7 @@ Describe "PowerShell Command Debugging" -tags "CI" {
$process.StandardInput.Close()

EnsureChildHasExited $process
$process.ExitCode | Should Be 0
$process.ExitCode | Should -Be 0
}

It "Should be able to continue into debugging" {
Expand All @@ -71,7 +71,7 @@ Describe "PowerShell Command Debugging" -tags "CI" {
$process.StandardInput.Close()

EnsureChildHasExited $process
$process.ExitCode | Should Be 0
$process.ExitCode | Should -Be 0
}

It -Pending "Should be able to list help for debugging" {
Expand All @@ -93,7 +93,7 @@ Describe "PowerShell Command Debugging" -tags "CI" {
$process.StandardInput.Close()

EnsureChildHasExited $process
$line | Should Be "For instructions about how to customize your debugger prompt, type `"help about_prompt`"."
$line | Should -BeExactly "For instructions about how to customize your debugger prompt, type `"help about_prompt`"."
}

It "Should be able to step over debugging" {
Expand All @@ -109,7 +109,7 @@ Describe "PowerShell Command Debugging" -tags "CI" {
$process.StandardInput.Close()

EnsureChildHasExited $process
$process.ExitCode | Should Be 0
$process.ExitCode | Should -Be 0
}

It "Should be able to step out of debugging" {
Expand All @@ -123,7 +123,7 @@ Describe "PowerShell Command Debugging" -tags "CI" {
$process.StandardInput.Close()

EnsureChildHasExited $process
$process.ExitCode | Should Be 0
$process.ExitCode | Should -Be 0
}

It "Should be able to quit debugging" {
Expand All @@ -137,7 +137,7 @@ Describe "PowerShell Command Debugging" -tags "CI" {
$process.StandardInput.Close()

EnsureChildHasExited $process
$process.ExitCode | Should Be 0
$process.ExitCode | Should -Be 0
}

It -Pending "Should be able to list source code in debugging" {
Expand All @@ -156,7 +156,7 @@ Describe "PowerShell Command Debugging" -tags "CI" {
$process.StandardInput.Write("`n")
$process.StandardInput.Write("`n")

$line | Should Be " 1:* `$function:foo = { 'bar' }"
$line | Should -BeExactly " 1:* `$function:foo = { 'bar' }"
$process.StandardInput.Close()
EnsureChildHasExited $process

Expand All @@ -174,7 +174,7 @@ Describe "PowerShell Command Debugging" -tags "CI" {
$line = $process.StandardOutput.ReadLine()
}

$line | Should Be "foo {} <No file>"
$line | Should -BeExactly "foo {} <No file>"
$process.StandardInput.Close()
EnsureChildHasExited $process

Expand All @@ -200,26 +200,21 @@ Describe "Runspace Debugging API tests" -tag CI {
}

It "PSStandaloneMonitorRunspaceInfo should throw when called with a null argument to the constructor" {
try {
[PSStandaloneMonitorRunspaceInfo]::new($null)
throw "Execution should have thrown"
}
Catch {
$_.FullyQualifiedErrorId | should be PSArgumentNullException
}
{[PSStandaloneMonitorRunspaceInfo]::new($null)} |
Should -Throw -ErrorId 'PSArgumentNullException'
}

it "PSStandaloneMonitorRunspaceInfo properties should have proper values" {
$monitorInfo.Runspace.InstanceId | Should be $InstanceId
$monitorInfo.RunspaceType | Should be "StandAlone"
$monitorInfo.NestedDebugger | Should BeNullOrEmpty
$monitorInfo.Runspace.InstanceId | Should -Be $InstanceId
$monitorInfo.RunspaceType | Should -BeExactly "Standalone"
$monitorInfo.NestedDebugger | Should -BeNullOrEmpty
}

It "Embedded runspace properties should have proper values" {
$embeddedRunspaceInfo.Runspace.InstanceId | should be $InstanceId
$embeddedRunspaceInfo.ParentDebuggerId | should be $parentDebuggerId
$embeddedRunspaceInfo.Command.InstanceId | should be $ps.InstanceId
$embeddedRunspaceInfo.NestedDebugger | Should BeNullOrEmpty
$embeddedRunspaceInfo.Runspace.InstanceId | Should -Be $InstanceId
$embeddedRunspaceInfo.ParentDebuggerId | Should -Be $parentDebuggerId
$embeddedRunspaceInfo.Command.InstanceId | Should -Be $ps.InstanceId
$embeddedRunspaceInfo.NestedDebugger | Should -BeNullOrEmpty
}
}
Context "Test Monitor RunspaceInfo API tests" {
Expand All @@ -234,41 +229,21 @@ Describe "Runspace Debugging API tests" -tag CI {
}

It "DebuggerUtils StartMonitoringRunspace requires non-null debugger" {
try {
[DebuggerUtils]::StartMonitoringRunspace($null,$runspaceInfo)
throw "Execution should have thrown"
}
catch {
$_.fullyqualifiederrorid | should be PSArgumentNullException
}
{[DebuggerUtils]::StartMonitoringRunspace($null,$runspaceInfo)} |
Should -Throw -ErrorId 'PSArgumentNullException'
}
It "DebuggerUtils StartMonitoringRunspace requires non-null runspaceInfo" {
try {
[DebuggerUtils]::StartMonitoringRunspace($runspace.Debugger,$null)
throw "Execution should have thrown"
}
catch {
$_.fullyqualifiederrorid | should be PSArgumentNullException
}
{[DebuggerUtils]::StartMonitoringRunspace($runspace.Debugger,$null)} |
Should -Throw -ErrorId 'PSArgumentNullException'
}

It "DebuggerUtils EndMonitoringRunspace requires non-null debugger" {
try {
[DebuggerUtils]::EndMonitoringRunspace($null,$runspaceInfo)
throw "Execution should have thrown"
}
catch {
$_.fullyqualifiederrorid | should be PSArgumentNullException
}
{[DebuggerUtils]::EndMonitoringRunspace($null,$runspaceInfo)} |
Should -Throw -ErrorId 'PSArgumentNullException'
}
It "DebuggerUtils EndMonitoringRunspace requires non-null runspaceInfo" {
try {
[DebuggerUtils]::EndMonitoringRunspace($runspace.Debugger,$null)
throw "Execution should have thrown"
}
catch {
$_.fullyqualifiederrorid | should be PSArgumentNullException
}
{[DebuggerUtils]::EndMonitoringRunspace($runspace.Debugger,$null)} |
Should -Throw -ErrorId 'PSArgumentNullException'
}

}
Expand Down