From 6aac4976fbb54a86ea31ce44ef4aef77e93c0287 Mon Sep 17 00:00:00 2001 From: James Truher Date: Wed, 24 Aug 2016 16:58:21 -0700 Subject: [PATCH] Add simple runspace debugging tests --- .../Scripting/Debugging/Debugging.Tests.ps1 | 2 +- .../Debug-Runspace.Tests.ps1 | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 test/powershell/Modules/Microsoft.PowerShell.Utility/Debug-Runspace.Tests.ps1 diff --git a/test/powershell/Language/Scripting/Debugging/Debugging.Tests.ps1 b/test/powershell/Language/Scripting/Debugging/Debugging.Tests.ps1 index 402d43b57..88c55cee3 100644 --- a/test/powershell/Language/Scripting/Debugging/Debugging.Tests.ps1 +++ b/test/powershell/Language/Scripting/Debugging/Debugging.Tests.ps1 @@ -33,7 +33,7 @@ Describe "Breakpoints when set should be hit" -tag "CI" { } } -Describe "It should be possible to reset runspace debugging" { +Describe "It should be possible to reset runspace debugging" -tag "Feature" { BeforeAll { import-module $helperModule -force $path = setup -pass -f TestScript_2.ps1 -content $script2 diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Debug-Runspace.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Debug-Runspace.Tests.ps1 new file mode 100644 index 000000000..8b41fe1aa --- /dev/null +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Debug-Runspace.Tests.ps1 @@ -0,0 +1,59 @@ +Describe "Debug-Runspace" -tag "CI" { + BeforeAll { + $rs1 = [runspacefactory]::CreateRunspace() + $rs1.Open() + $rs1.Name = "MyRunspace1" + $rs2 = [runspacefactory]::CreateRunspace() + $rs2.Open() + $rs2.Name = "MyRunspace2" + } + AfterAll { + if ( $rs1 ) { $rs1.Dispose() } + if ( $rs2 ) { $rs1.Dispose() } + } + + It "Debugging a runspace should fail is the name is ambiguous" { + try { + Debug-Runspace -Name "My*" -ea stop + throw "Execution OK" + } + catch { + $_.FullyQualifiedErrorId | should be "DebugRunspaceTooManyRunspaceFound,Microsoft.PowerShell.Commands.DebugRunspaceCommand" + } + } + + It "Debugging a runspace should fail is the name is not found" { + try { + Debug-Runspace -Name "dflkjsdkfjldkjssldfj" -ea stop + throw "Execution OK" + } + catch { + $_.FullyQualifiedErrorId | should be "DebugRunspaceNoRunspaceFound,Microsoft.PowerShell.Commands.DebugRunspaceCommand" + } + } + + It "Debugging a runspace should fail is the runspace is not open" { + try { + $rs2.Close() + Debug-Runspace -runspace $rs2 -ea stop + throw "Execution OK" + } + catch { + $_.FullyQualifiedErrorId | should be "InvalidOperation,Microsoft.PowerShell.Commands.DebugRunspaceCommand" + } + } + + It "Debugging a runspace should fail is the runspace has no debugger" { + try { + $rs1.Debugger.SetDebugMode("None") + Debug-Runspace -runspace $rs1 -ea stop + throw "Execution OK" + } + catch { + $_.FullyQualifiedErrorId | should be "InvalidOperation,Microsoft.PowerShell.Commands.DebugRunspaceCommand" + } + } + +} + +