From 9bc5c1e70f0ba4977a79addf18297c168bab1e30 Mon Sep 17 00:00:00 2001 From: KevinMarquette Date: Sat, 24 Mar 2018 13:09:53 -0700 Subject: [PATCH 1/3] #6245 refactor SDK and Provider Pester tests to use v4 Should syntax --- .../Pester.AutomountedDrives.Tests.ps1 | 8 +- .../Provider/ProviderIntrinsics.Tests.ps1 | 13 +--- test/powershell/SDK/Json.Tests.ps1 | 12 +-- test/powershell/SDK/PSDebugging.Tests.ps1 | 77 +++++++------------ 4 files changed, 40 insertions(+), 70 deletions(-) diff --git a/test/powershell/Provider/Pester.AutomountedDrives.Tests.ps1 b/test/powershell/Provider/Pester.AutomountedDrives.Tests.ps1 index b6f1abad79c..4884f3abb92 100644 --- a/test/powershell/Provider/Pester.AutomountedDrives.Tests.ps1 +++ b/test/powershell/Provider/Pester.AutomountedDrives.Tests.ps1 @@ -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" } } } diff --git a/test/powershell/Provider/ProviderIntrinsics.Tests.ps1 b/test/powershell/Provider/ProviderIntrinsics.Tests.ps1 index a39cba58d34..3b6f76add74 100644 --- a/test/powershell/Provider/ProviderIntrinsics.Tests.ps1 +++ b/test/powershell/Provider/ProviderIntrinsics.Tests.ps1 @@ -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")} | + Should -Throw -ErrorId 'ItemNotFoundException' } } diff --git a/test/powershell/SDK/Json.Tests.ps1 b/test/powershell/SDK/Json.Tests.ps1 index 300ebdec92e..bdc2c8f616f 100644 --- a/test/powershell/SDK/Json.Tests.ps1 +++ b/test/powershell/SDK/Json.Tests.ps1 @@ -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" } } diff --git a/test/powershell/SDK/PSDebugging.Tests.ps1 b/test/powershell/SDK/PSDebugging.Tests.ps1 index 9555e99ff07..ae87abcfff2 100644 --- a/test/powershell/SDK/PSDebugging.Tests.ps1 +++ b/test/powershell/SDK/PSDebugging.Tests.ps1 @@ -33,7 +33,7 @@ Describe "PowerShell Command Debugging" -tags "CI" { if (!$process.HasExited) { - $process.HasExited | Should Be $true + $process.HasExited | Should -BeTrue $process.Kill() } } @@ -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" { @@ -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" { @@ -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" { @@ -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" { @@ -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" { @@ -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" { @@ -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 @@ -174,7 +174,7 @@ Describe "PowerShell Command Debugging" -tags "CI" { $line = $process.StandardOutput.ReadLine() } - $line | Should Be "foo {} " + $line | Should -BeExactly "foo {} " $process.StandardInput.Close() EnsureChildHasExited $process @@ -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" { @@ -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' } } From 85b3808a179833cb2200c0afb6b192b041a637a5 Mon Sep 17 00:00:00 2001 From: KevinMarquette Date: Sat, 24 Mar 2018 14:01:59 -0700 Subject: [PATCH 2/3] Correct case of test to match actual return value --- test/powershell/SDK/PSDebugging.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/SDK/PSDebugging.Tests.ps1 b/test/powershell/SDK/PSDebugging.Tests.ps1 index ae87abcfff2..ce6552ed672 100644 --- a/test/powershell/SDK/PSDebugging.Tests.ps1 +++ b/test/powershell/SDK/PSDebugging.Tests.ps1 @@ -206,7 +206,7 @@ Describe "Runspace Debugging API tests" -tag CI { it "PSStandaloneMonitorRunspaceInfo properties should have proper values" { $monitorInfo.Runspace.InstanceId | Should -Be $InstanceId - $monitorInfo.RunspaceType | Should -BeExactly "StandAlone" + $monitorInfo.RunspaceType | Should -BeExactly "Standalone" $monitorInfo.NestedDebugger | Should -BeNullOrEmpty } From 494ee9cf6a80d8219255fa4b36c9d10b66448132 Mon Sep 17 00:00:00 2001 From: KevinMarquette Date: Tue, 27 Mar 2018 20:29:56 -0700 Subject: [PATCH 3/3] [Feature] add proper whitespace near braces --- test/powershell/Provider/ProviderIntrinsics.Tests.ps1 | 2 +- test/powershell/SDK/PSDebugging.Tests.ps1 | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/powershell/Provider/ProviderIntrinsics.Tests.ps1 b/test/powershell/Provider/ProviderIntrinsics.Tests.ps1 index 3b6f76add74..0880b1b6f7d 100644 --- a/test/powershell/Provider/ProviderIntrinsics.Tests.ps1 +++ b/test/powershell/Provider/ProviderIntrinsics.Tests.ps1 @@ -11,7 +11,7 @@ Describe "ProviderIntrinsics Tests" -tags "CI" { $ExecutionContext.InvokeProvider.ChildItem.HasChild("$TESTDRIVE/TestDir") | Should -BeFalse } It 'If the path does not exist, HasChild throws an exception' { - {$ExecutionContext.InvokeProvider.ChildItem.HasChild("TESTDRIVE/ThisDirectoryDoesNotExist")} | + { $ExecutionContext.InvokeProvider.ChildItem.HasChild("TESTDRIVE/ThisDirectoryDoesNotExist") } | Should -Throw -ErrorId 'ItemNotFoundException' } } diff --git a/test/powershell/SDK/PSDebugging.Tests.ps1 b/test/powershell/SDK/PSDebugging.Tests.ps1 index ce6552ed672..f1d486a258b 100644 --- a/test/powershell/SDK/PSDebugging.Tests.ps1 +++ b/test/powershell/SDK/PSDebugging.Tests.ps1 @@ -200,7 +200,7 @@ Describe "Runspace Debugging API tests" -tag CI { } It "PSStandaloneMonitorRunspaceInfo should throw when called with a null argument to the constructor" { - {[PSStandaloneMonitorRunspaceInfo]::new($null)} | + { [PSStandaloneMonitorRunspaceInfo]::new($null) } | Should -Throw -ErrorId 'PSArgumentNullException' } @@ -229,20 +229,20 @@ Describe "Runspace Debugging API tests" -tag CI { } It "DebuggerUtils StartMonitoringRunspace requires non-null debugger" { - {[DebuggerUtils]::StartMonitoringRunspace($null,$runspaceInfo)} | + { [DebuggerUtils]::StartMonitoringRunspace($null,$runspaceInfo) } | Should -Throw -ErrorId 'PSArgumentNullException' } It "DebuggerUtils StartMonitoringRunspace requires non-null runspaceInfo" { - {[DebuggerUtils]::StartMonitoringRunspace($runspace.Debugger,$null)} | + { [DebuggerUtils]::StartMonitoringRunspace($runspace.Debugger,$null) } | Should -Throw -ErrorId 'PSArgumentNullException' } It "DebuggerUtils EndMonitoringRunspace requires non-null debugger" { - {[DebuggerUtils]::EndMonitoringRunspace($null,$runspaceInfo)} | + { [DebuggerUtils]::EndMonitoringRunspace($null,$runspaceInfo) } | Should -Throw -ErrorId 'PSArgumentNullException' } It "DebuggerUtils EndMonitoringRunspace requires non-null runspaceInfo" { - {[DebuggerUtils]::EndMonitoringRunspace($runspace.Debugger,$null)} | + { [DebuggerUtils]::EndMonitoringRunspace($runspace.Debugger,$null) } | Should -Throw -ErrorId 'PSArgumentNullException' }