Merge pull request #807 from PowerShell/GetVariablePesterUnitTest
Add Get-Variable Pester Unit Test
This commit is contained in:
commit
f38a11fc02
|
@ -1,3 +1,57 @@
|
||||||
|
|
||||||
|
Describe "Get-Variable DRT Unit Tests" -Tags DRT{
|
||||||
|
It "Get-Variable of not existing variable Name should throw ItemNotFoundException"{
|
||||||
|
try {
|
||||||
|
Get-Variable -EA Stop -Name nonexistingVariableName
|
||||||
|
Throw "Execution OK"
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
$_.FullyQualifiedErrorId | Should be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Get-Variable of existing variable Name with include and bogus exclude should work"{
|
||||||
|
Set-Variable newVar testing
|
||||||
|
$var1=get-variable -Name newVar -Include newVar -Exclude bogus
|
||||||
|
$var1.Name|Should Be "newVar"
|
||||||
|
$var1.Value|Should Be "testing"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Get-Variable of existing variable Name with Description and Option should work"{
|
||||||
|
Set-Variable newVar testing -Option ReadOnly -Description "testing description"
|
||||||
|
$var1=get-variable -Name newVar
|
||||||
|
$var1.Name|Should Be "newVar"
|
||||||
|
$var1.Value|Should Be "testing"
|
||||||
|
$var1.Options|Should Be "ReadOnly"
|
||||||
|
$var1.Description|Should Be "testing description"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Get-Variable of existing variable Globbing Name should work"{
|
||||||
|
Set-Variable abcaVar testing
|
||||||
|
Set-Variable bcdaVar "another test"
|
||||||
|
Set-Variable aVarfoo wow
|
||||||
|
$var1=get-variable -Name *aVar* -Scope local
|
||||||
|
$var1.Count | Should be 3
|
||||||
|
$var1[0].Name|Should Be "abcaVar"
|
||||||
|
$var1[0].Value|Should Be "testing"
|
||||||
|
$var1[1].Name|Should Be "aVarfoo"
|
||||||
|
$var1[1].Value|Should Be "wow"
|
||||||
|
$var1[2].Name|Should Be "bcdaVar"
|
||||||
|
$var1[2].Value|Should Be "another test"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Get-Variable of existing private variable Name should throw ItemNotFoundException skip now as bug#818" -Skip:$true{
|
||||||
|
try {
|
||||||
|
Set-Variable newVar testing -Option Private
|
||||||
|
&{Get-Variable -Name newVar}
|
||||||
|
Throw "Execution OK"
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
$_.FullyQualifiedErrorId | Should be "VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Describe "Get-Variable" {
|
Describe "Get-Variable" {
|
||||||
It "Should be able to call with no parameters without error" {
|
It "Should be able to call with no parameters without error" {
|
||||||
{ Get-Variable } | Should Not Throw
|
{ Get-Variable } | Should Not Throw
|
||||||
|
@ -18,7 +72,7 @@ Describe "Get-Variable" {
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should be able to call using the gv alias" {
|
It "Should be able to call using the gv alias" {
|
||||||
{ gv } | Should Not Throw
|
(get-alias gv).Definition | Should be "Get-Variable"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should be able to call using the Name switch" {
|
It "Should be able to call using the Name switch" {
|
||||||
|
@ -81,7 +135,7 @@ Describe "Get-Variable" {
|
||||||
|
|
||||||
$actual = Get-Variable -Exclude var1, var2
|
$actual = Get-Variable -Exclude var1, var2
|
||||||
|
|
||||||
$actual | Where-Object { $_.Name -eq "var3" } | Should Not BeNullOrEmpty
|
$actual.Name -contains "var3" | Should Be $true
|
||||||
}
|
}
|
||||||
|
|
||||||
Context "Scope Tests" {
|
Context "Scope Tests" {
|
||||||
|
@ -89,7 +143,7 @@ Describe "Get-Variable" {
|
||||||
It "Should be able to get a global scope variable using the global switch" {
|
It "Should be able to get a global scope variable using the global switch" {
|
||||||
New-Variable globalVar -Value 1 -Scope global -Force
|
New-Variable globalVar -Value 1 -Scope global -Force
|
||||||
|
|
||||||
(Get-Variable -Name globalVar -Scope global)[0].Value | Should Be 1
|
(Get-Variable -Name globalVar -Scope global).Value | Should Be 1
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should not be able to clear a global scope variable using the local switch" {
|
It "Should not be able to clear a global scope variable using the local switch" {
|
||||||
|
@ -100,9 +154,9 @@ Describe "Get-Variable" {
|
||||||
|
|
||||||
It "Should be able to get a global variable when there's one in the script scope" {
|
It "Should be able to get a global variable when there's one in the script scope" {
|
||||||
New-Variable globalVar -Value 1 -Scope global -Force
|
New-Variable globalVar -Value 1 -Scope global -Force
|
||||||
{ New-Variable globalVar -Value 2 -Scope script -Force }
|
{ New-Variable globalVar -Value 2 -Scope script -Force}
|
||||||
|
|
||||||
$(Get-Variable -Name globalVar).Value | Should Be 1
|
(Get-Variable -Name globalVar).Value | Should Be 1
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should be able to get an item locally using the local switch" {
|
It "Should be able to get an item locally using the local switch" {
|
||||||
|
@ -118,7 +172,7 @@ Describe "Get-Variable" {
|
||||||
|
|
||||||
New-Variable localVar -Value 2 -Scope global -Force
|
New-Variable localVar -Value 2 -Scope global -Force
|
||||||
|
|
||||||
$(Get-Variable -Name localVar -Scope global).Value | Should Be 2
|
(Get-Variable -Name localVar -Scope global).Value | Should Be 2
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should be able to get a script variable created using the script switch" {
|
It "Should be able to get a script variable created using the script switch" {
|
||||||
|
|
Loading…
Reference in a new issue