Skip to content
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ Describe "Remove-Variable" -Tags "CI" {

Remove-Variable var1

$var1 | Should -Be #nothing. it should be Nothing at all.
$var1 | Should -BeNullOrEmpty
{ Get-Variable var1 -ErrorAction stop } |
Should -Throw -ErrorId 'VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand'
}

It "Should not throw error when used with the Name field, and named variable is specified and exists" {
New-Variable -Name var1 -Value 2

Remove-Variable -Name var1

$var1 | Should -Be #nothing. it should be Nothing at all.
$var1 | Should -BeNullOrEmpty
{ Get-Variable var1 -ErrorAction stop } |
Should -Throw -ErrorId 'VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand'
}

It "Should throw error when used with Name field, and named variable does not exist" {
Expand All @@ -42,9 +46,16 @@ Describe "Remove-Variable" -Tags "CI" {

Remove-Variable -Name tmp*

$tmpvar1 | Should -Be #nothing. it should be Nothing at all.
$tmpvar2 | Should -Be #nothing. it should be Nothing at all.
$tmpmyvar1 | Should -Be #nothing. it should be Nothing at all.
$tmpvar1 | Should -BeNullOrEmpty
$tmpvar2 | Should -BeNullOrEmpty
$tmpmyvar1 | Should -BeNullOrEmpty

{ Get-Variable tmpvar1 -ErrorAction stop } |
Should -Throw -ErrorId 'VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand'
{ Get-Variable tmpvar2 -ErrorAction stop } |
Should -Throw -ErrorId 'VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand'
{ Get-Variable tmpmyvar1 -ErrorAction stop } |
Should -Throw -ErrorId 'VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand'
}

It "Should be able to exclude a set of variables to remove using the Exclude switch" {
Expand All @@ -58,9 +69,14 @@ Describe "Remove-Variable" -Tags "CI" {

Remove-Variable -Name tmp* -Exclude *my*

$tmpvar1 | Should -Be #nothing. it should be Nothing at all.
$tmpvar2 | Should -Be #nothing. it should be Nothing at all.
$tmpvar1 | Should -BeNullOrEmpty
$tmpvar2 | Should -BeNullOrEmpty
$tmpmyvar1 | Should -Be 234

{ Get-Variable tmpvar1 -ErrorAction stop } |
Should -Throw -ErrorId 'VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand'
{ Get-Variable tmpvar2 -ErrorAction stop } |
Should -Throw -ErrorId 'VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand'
}

It "Should be able to include a set of variables to remove using the Include switch" {
Expand All @@ -78,9 +94,12 @@ Describe "Remove-Variable" -Tags "CI" {

$tmpvar1 | Should -BeExactly "tempvalue"
$tmpvar2 | Should -Be 2
$tmpmyvar1 | Should -Be #nothing. it should be Nothing at all.
$tmpmyvar1 | Should -BeNullOrEmpty
$thevar | Should -Be 1

{ Get-Variable tmpmyvar1 -ErrorAction stop } |
Should -Throw -ErrorId 'VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand'

Remove-Variable tmpvar1
Remove-Variable tmpvar2
Remove-Variable thevar
Expand Down