Programmatic indentation and whitespace-cleanup of tests

This commit is contained in:
Andrew Schwartzmeyer committed 2016-03-04 14:52:27 -08:00
1 parent 0aaf74bdcc
commit 0c6b14adab
83 files changed
+2191 -2193

No files matched your search

+9 -9
View File
@@ -1,19 +1,19 @@
Describe "Add-Member" {
It "should be able to see a newly added member of an object" {
$o = New-Object psobject
Add-Member -InputObject $o -MemberType NoteProperty -Name proppy -Value "superVal"
$o = New-Object psobject
Add-Member -InputObject $o -MemberType NoteProperty -Name proppy -Value "superVal"
$o.proppy | Should Not BeNullOrEmpty
$o.proppy | Should Be "superVal"
$o.proppy | Should Not BeNullOrEmpty
$o.proppy | Should Be "superVal"
}
It "Should be able to add a member to an object that already has a member in it" {
$o = New-Object psobject
Add-Member -InputObject $o -MemberType NoteProperty -Name proppy -Value "superVal"
Add-Member -InputObject $o -MemberType NoteProperty -Name AnotherMember -Value "AnotherValue"
$o = New-Object psobject
Add-Member -InputObject $o -MemberType NoteProperty -Name proppy -Value "superVal"
Add-Member -InputObject $o -MemberType NoteProperty -Name AnotherMember -Value "AnotherValue"
$o.AnotherMember | Should Not BeNullOrEmpty
$o.AnotherMember | Should Be "AnotherValue"
$o.AnotherMember | Should Not BeNullOrEmpty
$o.AnotherMember | Should Be "AnotherValue"
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
Describe "Add-Type" {
It "Should not throw given a simple class definition" -Skip:$IsWindows {
{ Add-Type -TypeDefinition "public static class foo { }" } | Should Not Throw
{ Add-Type -TypeDefinition "public static class foo { }" } | Should Not Throw
}
}
+93 -93
View File
@@ -1,163 +1,163 @@
Describe "Clear-Variable" {
BeforeEach {
$var1 = 3
$var1 = 3
}
It "Should be able to clear a variable using the Name switch" {
Clear-Variable -Name var1
$var1 | Should BeNullOrEmpty
{ Get-Variable var1 } | Should Not Throw
Clear-Variable -Name var1
$var1 | Should BeNullOrEmpty
{ Get-Variable var1 } | Should Not Throw
}
It "Should be able to clear a variable without using the Name switch" {
Clear-Variable var1
$var1 | Should BeNullOrEmpty
{ Get-Variable var1 } | Should Not Throw
Clear-Variable var1
$var1 | Should BeNullOrEmpty
{ Get-Variable var1 } | Should Not Throw
}
It "Should have a null value after clearing the variable" {
Clear-Variable var1
$var1 | Should BeNullOrEmpty
Clear-Variable var1
$var1 | Should BeNullOrEmpty
}
It "Should call without error using the clv alias" {
{ clv -Name var1 } | Should Not Throw
{ clv -Name var1 } | Should Not Throw
}
It "Should be able to include a set of variables to clear" {
$var1 = 2
$var2 = 3
$var3 = 4
$variable1 = 23
$variable2 = 4
$variable3 = 2
$w = 3
$var1 = 2
$var2 = 3
$var3 = 4
$variable1 = 23
$variable2 = 4
$variable3 = 2
$w = 3
Clear-Variable -Name w, vari* -Include w, vari*
Clear-Variable -Name w, vari* -Include w, vari*
$variable1 | Should BeNullOrEmpty
$variable2 | Should BeNullOrEmpty
$variable3 | Should BeNullOrEmpty
$w | Should BeNullOrEmpty
$variable1 | Should BeNullOrEmpty
$variable2 | Should BeNullOrEmpty
$variable3 | Should BeNullOrEmpty
$w | Should BeNullOrEmpty
$var1 | Should Not BeNullOrEmpty
$var2 | Should Not BeNullOrEmpty
$var3 | Should Not BeNullOrEmpty
$var1 | Should Not BeNullOrEmpty
$var2 | Should Not BeNullOrEmpty
$var3 | Should Not BeNullOrEmpty
}
It "Should be able to exclude a set of variables to clear" {
$var1 = 2
$var2 = 3
$var3 = 4
$variable1 = 23
$variable2 = 4
$variable3 = 2
$w = 3
$var1 = 2
$var2 = 3
$var3 = 4
$variable1 = 23
$variable2 = 4
$variable3 = 2
$w = 3
Clear-Variable -Name w, vari* -Exclude var*
Clear-Variable -Name w, vari* -Exclude var*
$variable1 | Should Not BeNullOrEmpty
$variable2 | Should Not BeNullOrEmpty
$variable3 | Should Not BeNullOrEmpty
$var1 | Should Not BeNullOrEmpty
$var2 | Should Not BeNullOrEmpty
$var3 | Should Not BeNullOrEmpty
$variable1 | Should Not BeNullOrEmpty
$variable2 | Should Not BeNullOrEmpty
$variable3 | Should Not BeNullOrEmpty
$var1 | Should Not BeNullOrEmpty
$var2 | Should Not BeNullOrEmpty
$var3 | Should Not BeNullOrEmpty
$w | Should BeNullOrEmpty
$w | Should BeNullOrEmpty
}
It "Should be able to pass the cleared object through the pipeline using the passthru switch" {
{ Clear-Variable -Name var1 -PassThru | Format-Wide -Property Value } | Should Not Throw
{ Clear-Variable -Name var1 -PassThru | Format-Wide -Property Value } | Should Not Throw
}
It "Should not clear environment variables" {
$env:TEMPVARIABLE = "test data"
$env:TEMPVARIABLE = "test data"
Clear-Variable -Name env:TEMPVARIABLE -ErrorAction SilentlyContinue | Should Throw
Clear-Variable -Name env:TEMPVARIABLE -ErrorAction SilentlyContinue | Should Throw
}
It "Should clear variable even if it is read-only using the Force parameter" {
New-Variable -Name var2 -Option ReadOnly -Value 100
New-Variable -Name var2 -Option ReadOnly -Value 100
Clear-Variable -Name var1
Clear-Variable -Name var2 -Force
Clear-Variable -Name var1
Clear-Variable -Name var2 -Force
$var1 | Should BeNullOrEmpty
$var2 | Should BeNullOrEmpty
$var1 | Should BeNullOrEmpty
$var2 | Should BeNullOrEmpty
Remove-Variable -Name var2 -Force
Remove-Variable -Name var2 -Force
}
It "Should throw error when trying to clear variable that is read-only without using the Force parameter" {
New-Variable -Name var2 -Option ReadOnly -Value 100
New-Variable -Name var2 -Option ReadOnly -Value 100
Clear-Variable -Name var2 -ErrorAction SilentlyContinue | Should Throw
Clear-Variable -Name var2 -ErrorAction SilentlyContinue | Should Throw
$var2 | Should Not BeNullOrEmpty
$var2 | Should Not BeNullOrEmpty
Remove-Variable -Name var2 -Force
Remove-Variable -Name var2 -Force
}
Context "Scope Tests" {
# This will violate the DRY principle. Tread softly.
# This will violate the DRY principle. Tread softly.
It "Should be able to clear a global scope variable using the global switch" {
New-Variable globalVar -Value 1 -Scope global -Force
It "Should be able to clear a global scope variable using the global switch" {
New-Variable globalVar -Value 1 -Scope global -Force
Clear-Variable -Name globalVar -Scope global
Clear-Variable -Name globalVar -Scope global
$globalVar | Should BeNullOrEmpty
}
$globalVar | Should BeNullOrEmpty
}
It "Should not be able to clear a global scope variable using the local switch" {
New-Variable globalVar -Value 1 -Scope global -Force
It "Should not be able to clear a global scope variable using the local switch" {
New-Variable globalVar -Value 1 -Scope global -Force
Clear-Variable -Name globalVar -Scope local -ErrorAction SilentlyContinue | Should Throw
}
Clear-Variable -Name globalVar -Scope local -ErrorAction SilentlyContinue | Should Throw
}
It "Should not be able to clear a global variable using the script scope switch" {
New-Variable globalVar -Value 1 -Scope global -Force
It "Should not be able to clear a global variable using the script scope switch" {
New-Variable globalVar -Value 1 -Scope global -Force
Clear-Variable -Name localVar -Scope script -ErrorAction SilentlyContinue | Should Throw
}
Clear-Variable -Name localVar -Scope script -ErrorAction SilentlyContinue | Should Throw
}
It "Should be able to clear an item locally using the local switch" {
New-Variable localVar -Value 2 -Scope local -Force
It "Should be able to clear an item locally using the local switch" {
New-Variable localVar -Value 2 -Scope local -Force
Clear-Variable -Name localVar -Scope local
Clear-Variable -Name localVar -Scope local
$localVar | Should BeNullOrEmpty
$localVar | Should BeNullOrEmpty
Clear-Variable -Name localVar -Scope script -ErrorAction SilentlyContinue | Should Throw
}
Clear-Variable -Name localVar -Scope script -ErrorAction SilentlyContinue | Should Throw
}
It "Should not be able to clear an item locally using the global switch" {
New-Variable localVar -Value 2 -Scope local -Force
It "Should not be able to clear an item locally using the global switch" {
New-Variable localVar -Value 2 -Scope local -Force
Clear-Variable -Name localVar -Scope global -ErrorAction SilentlyContinue | Should Throw
}
Clear-Variable -Name localVar -Scope global -ErrorAction SilentlyContinue | Should Throw
}
It "Should not be able to clear a local variable using the script scope switch" {
New-Variable localVar -Value 2 -Scope local -Force
It "Should not be able to clear a local variable using the script scope switch" {
New-Variable localVar -Value 2 -Scope local -Force
Clear-Variable -Name localVar -Scope script -ErrorAction SilentlyContinue | Should Throw
}
Clear-Variable -Name localVar -Scope script -ErrorAction SilentlyContinue | Should Throw
}
It "Should be able to clear a script variable created using the script switch" {
{
New-Variable -Name derp2 -Value 3 -Scope script -Force
It "Should be able to clear a script variable created using the script switch" {
{
New-Variable -Name derp2 -Value 3 -Scope script -Force
Clear-Variable -Name derp2 -Scope script
}| Should Not Throw
}
Clear-Variable -Name derp2 -Scope script
}| Should Not Throw
}
It "Should be able to clear a global script variable that was created using the script scope switch" {
{
New-Variable -Name derpx -Value 4 -Scope script -Force
It "Should be able to clear a global script variable that was created using the script scope switch" {
{
New-Variable -Name derpx -Value 4 -Scope script -Force
Clear-Variable -Name derpx -Scope script
} | Should Not Throw
}
Clear-Variable -Name derpx -Scope script
} | Should Not Throw
}
}
}
+58 -58
View File
@@ -24,137 +24,137 @@ Describe "Compare-Object" {
Test-Path $testDirectory | Should Be $true
It "Should be able to compare the same object using the referenceObject and differenceObject switches" {
{ Compare-Object -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2) } | Should Not Throw
{ Compare-Object -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2) } | Should Not Throw
}
It "Should not throw when referenceobject switch is not used" {
{ Compare-Object $(Get-Content $file1) -DifferenceObject $(Get-Content $file2) } | Should Not Throw
{ Compare-Object $(Get-Content $file1) -DifferenceObject $(Get-Content $file2) } | Should Not Throw
}
It "Should not throw when differenceobject switch is not used" {
{ Compare-Object -ReferenceObject $(Get-Content $file1) $(Get-Content $file2) } | Should Not Throw
{ Compare-Object -ReferenceObject $(Get-Content $file1) $(Get-Content $file2) } | Should Not Throw
}
It "Should be able to execute compare object using the compare alias" {
{ compare -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2) } | Should Not Throw
{ compare -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2) } | Should Not Throw
}
It "Should produce the same output when the compare alias is used" {
$alias = compare -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2)
$fullname = Compare-Object -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2)
$alias = compare -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2)
$fullname = Compare-Object -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2)
$alias[0].InputObject | Should Be $fullname[0].InputObject
$alias[0].SideIndicator | Should Be $fullname[0].SideIndicator
$alias[1].InputObject | Should Be $fullname[1].InputObject
$alias[1].SideIndicator | Should Be $fullname[1].SideIndicator
$alias[0].InputObject | Should Be $fullname[0].InputObject
$alias[0].SideIndicator | Should Be $fullname[0].SideIndicator
$alias[1].InputObject | Should Be $fullname[1].InputObject
$alias[1].SideIndicator | Should Be $fullname[1].SideIndicator
$alias.Length | Should Be 2 # There should be no other elements to test
$alias.Length | Should Be 2 # There should be no other elements to test
}
It "Should be able to execute compare object using the diff alias" {
$alias = diff -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2)
$fullname = Compare-Object -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2)
$alias = diff -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2)
$fullname = Compare-Object -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2)
$alias[0].InputObject | Should Be $fullname[0].InputObject
$alias[0].SideIndicator | Should Be $fullname[0].SideIndicator
$alias[1].InputObject | Should Be $fullname[1].InputObject
$alias[1].SideIndicator | Should Be $fullname[1].SideIndicator
$alias[0].InputObject | Should Be $fullname[0].InputObject
$alias[0].SideIndicator | Should Be $fullname[0].SideIndicator
$alias[1].InputObject | Should Be $fullname[1].InputObject
$alias[1].SideIndicator | Should Be $fullname[1].SideIndicator
$alias.Length | Should Be 2 # There should be no other elements to test
$alias.Length | Should Be 2 # There should be no other elements to test
}
It "Should indicate data that exists only in the reference dataset" {
$actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4)
$actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4)
$actualOutput[1].SideIndicator | Should Be "<="
$actualOutput[1].SideIndicator | Should Be "<="
}
It "Should indicate data that exists only in the difference dataset" {
$actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4)
$actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4)
$actualOutput[1].SideIndicator | Should Be "<="
$actualOutput[1].SideIndicator | Should Be "<="
}
It "Should indicate data that exists in both datasets when the includeEqual switch is used" {
$actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -IncludeEqual
$actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -IncludeEqual
$actualOutput.Length | Should Be 4
$actualOutput[0].SideIndicator | Should Be "=="
$actualOutput[1].SideIndicator | Should Be "=="
$actualOutput.Length | Should Be 4
$actualOutput[0].SideIndicator | Should Be "=="
$actualOutput[1].SideIndicator | Should Be "=="
}
It "Should be able to use the casesensitive switch" {
{ Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -CaseSensitive } | Should Not Throw
{ Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -CaseSensitive } | Should Not Throw
}
It "Should correctly indicate that different cases are different when the casesensitive switch is used" {
$caOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -CaseSensitive
$ncaOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4)
$caOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -CaseSensitive
$ncaOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4)
$caOutput.Length | Should Be 4
$caOutput.Length | Should Be 4
$ncaOutput[1].SideIndicator | Should Not Be $caOutput[1].SideIndicator
$ncaOutput[2].SideIndicator | Should Not Be $caOutput[2].SideIndicator
$ncaOutput[3].SideIndicator | Should Not Be $caOutput[3].SideIndicator
$ncaOutput[1].SideIndicator | Should Not Be $caOutput[1].SideIndicator
$ncaOutput[2].SideIndicator | Should Not Be $caOutput[2].SideIndicator
$ncaOutput[3].SideIndicator | Should Not Be $caOutput[3].SideIndicator
}
It "Should throw when reference set is null" {
{ Compare-Object -ReferenceObject $anonexistentvariable -DifferenceObject $(Get-Content $file4) } | Should Throw
{ Compare-Object -ReferenceObject $anonexistentvariable -DifferenceObject $(Get-Content $file4) } | Should Throw
}
It "Should throw when difference set is null" {
{ Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $anonexistentvariable } | Should Throw
{ Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $anonexistentvariable } | Should Throw
}
It "Should give a 0 array when using excludedifferent switch without also using the includeequal switch" {
$actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -ExcludeDifferent
$actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -ExcludeDifferent
$actualOutput.Length | Should Be 0
$actualOutput.Length | Should Be 0
}
It "Should only display equal lines when excludeDifferent switch is used alongside the includeequal switch" {
$actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -IncludeEqual -ExcludeDifferent
$actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -IncludeEqual -ExcludeDifferent
$actualOutput.Length | Should Be 2
$actualOutput.Length | Should Be 2
}
It "Should be able to pass objects to pipeline using the passthru switch" {
{ Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -Passthru | Format-Wide } | Should Not Throw
{ Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -Passthru | Format-Wide } | Should Not Throw
}
It "Should be able to specify the property of two objects to compare" {
$actualOutput = Compare-Object -ReferenceObject $file3 -DifferenceObject $testDirectory -Property Length
$actualOutput = Compare-Object -ReferenceObject $file3 -DifferenceObject $testDirectory -Property Length
$actualOutput[0].Length | Should BeGreaterThan 0
$actualOutput[1].Length | Should BeGreaterThan 0
$actualOutput[0].Length | Should Not Be $actualOutput[1].Length
$actualOutput[0].Length | Should BeGreaterThan 0
$actualOutput[1].Length | Should BeGreaterThan 0
$actualOutput[0].Length | Should Not Be $actualOutput[1].Length
}
It "Should be able to specify the syncwindow without error" {
{ Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -syncWindow 5 } | Should Not Throw
{ Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -syncWindow 8 } | Should Not Throw
{ Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -syncWindow 5 } | Should Not Throw
{ Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -syncWindow 8 } | Should Not Throw
}
It "Should have the expected output when changing the syncwindow" {
$var1 = 1..15
$var2 = 15..1
$var1 = 1..15
$var2 = 15..1
$actualOutput = Compare-Object -ReferenceObject $var1 -DifferenceObject $var2 -syncWindow 6
$actualOutput = Compare-Object -ReferenceObject $var1 -DifferenceObject $var2 -syncWindow 6
$actualOutput[0].InputObject | Should Be 15
$actualOutput[1].InputObject | Should Be 1
$actualOutput[2].InputObject | Should Be 1
$actualOutput[3].InputObject | Should Be 15
$actualOutput[0].InputObject | Should Be 15
$actualOutput[1].InputObject | Should Be 1
$actualOutput[2].InputObject | Should Be 1
$actualOutput[3].InputObject | Should Be 15
$actualOutput[0].SideIndicator | Should be "=>"
$actualOutput[1].SideIndicator | Should be "<="
$actualOutput[2].SideIndicator | Should be "=>"
$actualOutput[3].SideIndicator | Should be "<="
$actualOutput[0].SideIndicator | Should be "=>"
$actualOutput[1].SideIndicator | Should be "<="
$actualOutput[2].SideIndicator | Should be "=>"
$actualOutput[3].SideIndicator | Should be "<="
}
# Clean up after yourself
# Clean up after yourself
Remove-Item $testDirectory -Recurse -Force
Test-Path $testDirectory | Should Be $false
}
+20 -20
View File
@@ -5,48 +5,48 @@ Describe "ConvertFrom-Csv" {
$testcsv = Join-Path -Path (Join-Path -Path $here -ChildPath assets) -ChildPath TestCsv2.csv
$testName = "Zaphod BeebleBrox"
$testColumns = @"
a,b,c
1,2,3
a,b,c
1,2,3
"@
It "Should be able to be called" {
{ ConvertFrom-Csv -InputObject $testObject } | Should Not Throw
{ ConvertFrom-Csv -InputObject $testObject } | Should Not Throw
}
It "Should be able to pipe" {
{ $testObject | ConvertFrom-Csv } | Should Not Throw
{ $testObject | ConvertFrom-Csv } | Should Not Throw
}
It "Should have expected results when using piped inputs" {
$csvContent = Get-Content $testcsv
$actualresult = $csvContent | ConvertFrom-Csv
$csvContent = Get-Content $testcsv
$actualresult = $csvContent | ConvertFrom-Csv
$actualresult.GetType().BaseType.Name | Should Be "Array"
$actualresult[0].GetType().Name | Should Be "PSCustomObject"
$actualresult.GetType().BaseType.Name | Should Be "Array"
$actualresult[0].GetType().Name | Should Be "PSCustomObject"
#Should have a name property in the result
$actualresult[0].Name | Should Be $testName
#Should have a name property in the result
$actualresult[0].Name | Should Be $testName
}
It "Should be able to set a delimiter" {
{ $testcsv | ConvertFrom-Csv -Delimiter ";" } | Should Not Throw
{ $testcsv | ConvertFrom-Csv -Delimiter ";" } | Should Not Throw
}
It "Should actually delimit the output" {
$csvContent = Get-Content $testcsv
$actualresult = $csvContent | ConvertFrom-Csv -Delimiter ";"
$csvContent = Get-Content $testcsv
$actualresult = $csvContent | ConvertFrom-Csv -Delimiter ";"
$actualresult.GetType().BaseType.Name | Should Be "Array"
$actualresult[0].GetType().Name | Should Be "PSCustomObject"
$actualresult.GetType().BaseType.Name | Should Be "Array"
$actualresult[0].GetType().Name | Should Be "PSCustomObject"
# ConvertFrom-Csv takes the first line of the input as a header by default
$actualresult.Length | Should Be $($csvContent.Length - 1)
# ConvertFrom-Csv takes the first line of the input as a header by default
$actualresult.Length | Should Be $($csvContent.Length - 1)
}
It "Should be able to have multiple columns" {
$actualData = $testColumns | ConvertFrom-Csv
$actualData = $testColumns | ConvertFrom-Csv
$actualLength = $($( $actualData | gm) | Where-Object {$_.MemberType -eq "NoteProperty" }).Length
$actualLength = $($( $actualData | gm) | Where-Object {$_.MemberType -eq "NoteProperty" }).Length
$actualLength | Should Be 3
$actualLength | Should Be 3
}
}
@@ -1,51 +1,51 @@
Describe "ConvertFrom-StringData" {
$sampleData = @'
foo = 0
bar = 1
bazz = 2
foo = 0
bar = 1
bazz = 2
'@
It "Should not throw when called with just the stringdata switch" {
{ ConvertFrom-StringData -StringData 'a=b' } | Should Not Throw
{ ConvertFrom-StringData -StringData 'a=b' } | Should Not Throw
}
It "Should return a hashtable" {
$(ConvertFrom-StringData -StringData 'a=b').GetType().Name | Should Be "Hashtable"
$(ConvertFrom-StringData -StringData 'a=b').GetType().Name | Should Be "Hashtable"
}
It "Should throw if not in x=y format" {
{ ConvertFrom-StringData -StringData 'ab' } | Should Throw
{ ConvertFrom-StringData -StringData 'a,b' } | Should Throw
{ ConvertFrom-StringData -StringData 'a b' } | Should Throw
{ ConvertFrom-StringData -StringData 'a\tb' } | Should Throw
{ ConvertFrom-StringData -StringData 'a:b' } | Should Throw
{ ConvertFrom-StringData -StringData 'ab' } | Should Throw
{ ConvertFrom-StringData -StringData 'a,b' } | Should Throw
{ ConvertFrom-StringData -StringData 'a b' } | Should Throw
{ ConvertFrom-StringData -StringData 'a\tb' } | Should Throw
{ ConvertFrom-StringData -StringData 'a:b' } | Should Throw
}
It "Should return the data on the left side in the key" {
$actualValue = ConvertFrom-StringData -StringData 'a=b'
$actualValue = ConvertFrom-StringData -StringData 'a=b'
$actualValue.Keys | Should Be "a"
$actualValue.Keys | Should Be "a"
}
It "Should return the data on the right side in the value" {
$actualValue = ConvertFrom-StringData -StringData 'a=b'
$actualValue = ConvertFrom-StringData -StringData 'a=b'
$actualValue.Values | Should Be "b"
$actualValue.Values | Should Be "b"
}
It "Should return a keycollection for the keys" {
$(ConvertFrom-StringData -StringData 'a=b').Keys.gettype().Name | Should Be "KeyCollection"
$(ConvertFrom-StringData -StringData 'a=b').Keys.gettype().Name | Should Be "KeyCollection"
}
It "Should return a valuecollection for the values" {
$(ConvertFrom-StringData -StringData 'a=b').Values.gettype().Name | Should Be "ValueCollection"
$(ConvertFrom-StringData -StringData 'a=b').Values.gettype().Name | Should Be "ValueCollection"
}
It "Should work for multiple lines" {
{ ConvertFrom-StringData -StringData $sampleData } | Should Not Throw
{ ConvertFrom-StringData -StringData $sampleData } | Should Not Throw
$(ConvertFrom-StringData -StringData $sampleData).Keys | Should Be "foo", "bar", "bazz"
$(ConvertFrom-StringData -StringData $sampleData).Keys | Should Be "foo", "bar", "bazz"
$(ConvertFrom-StringData -StringData $sampleData).Values | Should Be "0","1","2"
$(ConvertFrom-StringData -StringData $sampleData).Values | Should Be "0","1","2"
}
}
}
+11 -11
View File
@@ -4,32 +4,32 @@ Describe "ConvertTo-Csv" {
It "Should Be able to be called without error" {
{ $testObject | ConvertTo-Csv } | Should Not Throw
{ $testObject | ConvertTo-Csv } | Should Not Throw
}
It "Should output an array of objects" {
$result = $testObject | ConvertTo-Csv
$result = $testObject | ConvertTo-Csv
$result.GetType().BaseType.Name | Should Be "Array"
$result.GetType().BaseType.Name | Should Be "Array"
}
It "Should return the type of data in the first element of the output array" {
$result = $testObject | ConvertTo-Csv
$result = $testObject | ConvertTo-Csv
$result[0] | Should Be "#TYPE System.Management.Automation.PSCustomObject"
$result[0] | Should Be "#TYPE System.Management.Automation.PSCustomObject"
}
It "Should return the column info in the second element of the output array" {
$result = $testObject | ConvertTo-Csv
$result = $testObject | ConvertTo-Csv
$result[1] | Should Match "`"FirstColumn`""
$result[1] | Should Match "`"SecondColumn`""
$result[1] | Should Match "`"FirstColumn`""
$result[1] | Should Match "`"SecondColumn`""
}
It "Should return the data as a comma-separated list in the third element of the output array" {
$result = $testObject | ConvertTo-Csv
$result[2] | Should Match "`"Hello`""
$result[2] | Should Match "`"World`""
$result = $testObject | ConvertTo-Csv
$result[2] | Should Match "`"Hello`""
$result[2] | Should Match "`"World`""
}
}
@@ -2,9 +2,9 @@ Describe "ConvertTo-SecureString" {
Context "Checking return types of ConvertTo-SecureString" {
It "Should return System.Security.SecureString after converting plaintext variable"{
$PesterTestConvert = (ConvertTo-SecureString "plaintextpester" -AsPlainText -force)
($PesterTestConvert).GetType() | Should Be securestring
It "Should return System.Security.SecureString after converting plaintext variable"{
$PesterTestConvert = (ConvertTo-SecureString "plaintextpester" -AsPlainText -force)
($PesterTestConvert).GetType() | Should Be securestring
}
}
+7 -7
View File
@@ -3,23 +3,23 @@ Describe "DotNetAPI" {
$posh_pi = 3.14159265358979
It "Should be able to use static .NET classes and get a constant" {
[System.Math]::E | Should Match $posh_E.ToString()
[System.Math]::PI | Should Match $posh_pi.ToString()
[System.Math]::E | Should Match $posh_E.ToString()
[System.Math]::PI | Should Match $posh_pi.ToString()
}
It "Should be able to invoke a method" {
[System.Environment]::GetEnvironmentVariable("PATH") | Should Be $env:PATH
[System.Environment]::GetEnvironmentVariable("PATH") | Should Be $env:PATH
}
It "Should not require 'system' in front of static classes" {
[Environment]::CommandLine | Should Be ([System.Environment]::CommandLine)
[Environment]::CommandLine | Should Be ([System.Environment]::CommandLine)
[Math]::E | Should Be ([System.Math]::E)
[Math]::E | Should Be ([System.Math]::E)
}
It "Should be able to create a new instance of a .Net object" {
[System.Guid]$guidVal = [System.Guid]::NewGuid()
[System.Guid]$guidVal = [System.Guid]::NewGuid()
$guidVal.GetType().Name | Should Be "Guid"
$guidVal.GetType().Name | Should Be "Guid"
}
}
+24 -24
View File
@@ -1,43 +1,43 @@
Describe "Environment-Variables" {
It "Should have environment variables" {
Get-Item ENV: | Should Not BeNullOrEmpty
Get-Item ENV: | Should Not BeNullOrEmpty
}
It "Should have a nonempty PATH" {
$ENV:PATH | Should Not BeNullOrEmpty
$ENV:PATH | Should Not BeNullOrEmpty
}
It "Should contain /bin in the PATH" {
if ($IsWindows)
{
$ENV:PATH | Should Match "C:"
}
else
{
$ENV:PATH | Should Match "/bin"
}
if ($IsWindows)
{
$ENV:PATH | Should Match "C:"
}
else
{
$ENV:PATH | Should Match "/bin"
}
}
It "Should have the correct HOME" {
if ($IsWindows)
{
$expected = "\Users"
Split-Path $ENV:HOMEPATH -Parent | Should Be $expected
}
else
{
$expected = /bin/bash -c "cd ~ && pwd"
$ENV:HOME | Should Be $expected
}
if ($IsWindows)
{
$expected = "\Users"
Split-Path $ENV:HOMEPATH -Parent | Should Be $expected
}
else
{
$expected = /bin/bash -c "cd ~ && pwd"
$ENV:HOME | Should Be $expected
}
}
It "Should be able to set the environment variables" {
$expected = "this is a test environment variable"
{ $ENV:TESTENVIRONMENTVARIABLE = $expected } | Should Not Throw
$expected = "this is a test environment variable"
{ $ENV:TESTENVIRONMENTVARIABLE = $expected } | Should Not Throw
$ENV:TESTENVIRONMENTVARIABLE | Should Not BeNullOrEmpty
$ENV:TESTENVIRONMENTVARIABLE | Should Be $expected
$ENV:TESTENVIRONMENTVARIABLE | Should Not BeNullOrEmpty
$ENV:TESTENVIRONMENTVARIABLE | Should Be $expected
}
}
+13 -13
View File
@@ -1,24 +1,24 @@
Describe "ExecutionPolicy" {
Context "Check Get-ExecutionPolicy behavior" {
It "Should throw PlatformNotSupported when not on Windows" -Skip:$IsWindows {
{ Get-ExecutionPolicy } | Should Throw "Operation is not supported on this platform."
}
It "Should throw PlatformNotSupported when not on Windows" -Skip:$IsWindows {
{ Get-ExecutionPolicy } | Should Throw "Operation is not supported on this platform."
}
It "Should return Microsoft.Powershell.ExecutionPolicy PSObject on Windows" -Skip:($IsLinux -Or $IsOSX) {
(Get-ExecutionPolicy).GetType() | Should Be Microsoft.Powershell.ExecutionPolicy
}
It "Should return Microsoft.Powershell.ExecutionPolicy PSObject on Windows" -Skip:($IsLinux -Or $IsOSX) {
(Get-ExecutionPolicy).GetType() | Should Be Microsoft.Powershell.ExecutionPolicy
}
}
Context "Check Set-ExecutionPolicy behavior" {
It "Should throw PlatformNotSupported when not on Windows" -Skip:$IsWindows {
{ Set-ExecutionPolicy Unrestricted } | Should Throw "Operation is not supported on this platform."
}
It "Should throw PlatformNotSupported when not on Windows" -Skip:$IsWindows {
{ Set-ExecutionPolicy Unrestricted } | Should Throw "Operation is not supported on this platform."
}
It "Should succeed on Windows" -Skip:($IsLinux -Or $IsOSX) {
# We use the Process scope to avoid affecting the system
# Unrestricted is assumed "safe", otherwise these tests would not be running
{ Set-ExecutionPolicy -Force -Scope Process -ExecutionPolicy Unrestricted } | Should Not Throw
It "Should succeed on Windows" -Skip:($IsLinux -Or $IsOSX) {
# We use the Process scope to avoid affecting the system
# Unrestricted is assumed "safe", otherwise these tests would not be running
{ Set-ExecutionPolicy -Force -Scope Process -ExecutionPolicy Unrestricted } | Should Not Throw
}
}
}
+12 -12
View File
@@ -4,28 +4,28 @@ Describe "Export-Alias" {
$fulltestpath = Join-Path -Path $($testAliasDirectory) -ChildPath $($testAliases)
BeforeEach {
New-Item -Path $testAliasDirectory -ItemType Directory -Force
New-Item -Path $testAliasDirectory -ItemType Directory -Force
}
It "Should be able to create a file in the specified location"{
Export-Alias $fulltestpath
Export-Alias $fulltestpath
Test-Path $fulltestpath | Should be $true
Test-Path $fulltestpath | Should be $true
}
It "Should create a file with the list of aliases that match the expected list" {
Export-Alias $fulltestpath
Export-Alias $fulltestpath
Test-Path $fulltestpath | Should Be $true
Test-Path $fulltestpath | Should Be $true
$actual = Get-Content $fulltestpath | Sort
$expected = $(Get-Command -CommandType Alias)
$actual = Get-Content $fulltestpath | Sort
$expected = $(Get-Command -CommandType Alias)
for ( $i=0; $i -lt $expected.Length; $i++)
{
# We loop through the expected list and not the other because the output writes some comments to the file.
$expected[$i] | Should Match $actual[$i].Name
}
for ( $i=0; $i -lt $expected.Length; $i++)
{
# We loop through the expected list and not the other because the output writes some comments to the file.
$expected[$i] | Should Match $actual[$i].Name
}
}
+28 -28
View File
@@ -3,64 +3,64 @@ Describe "Export-Csv" {
$testCsv = "output.csv"
AfterEach {
Remove-Item $testCsv -Force -ErrorAction SilentlyContinue
Remove-Item $testCsv -Force -ErrorAction SilentlyContinue
}
It "Should be able to be called without error" {
{ $testObject | Export-Csv $testCsv } | Should Not Throw
{ $testObject | Export-Csv $testCsv } | Should Not Throw
}
It "Should throw if an output file isn't specified" {
{ $testObject | Export-Csv -ErrorAction SilentlyContinue } | Should Throw
{ $testObject | Export-Csv -ErrorAction SilentlyContinue } | Should Throw
}
It "Should be a string when exporting via pipe" {
$testObject | Export-Csv $testCsv
$testObject | Export-Csv $testCsv
$piped = Get-Content $testCsv
$piped = Get-Content $testCsv
$piped[0] | Should Match ".String"
$piped[0] | Should Match ".String"
}
It "Should be an object when exporting via the inputObject switch" {
Export-Csv -InputObject $testObject -Path $testCsv
Export-Csv -InputObject $testObject -Path $testCsv
$switch = Get-Content $testCsv
$switch = Get-Content $testCsv
$switch[0] | Should Match ".Object"
$switch[0] | Should Match ".Object"
}
It "Should output a csv file containing a string of all the lengths of each element when piped input is used" {
$testObject | Export-Csv -Path $testCsv
$testObject | Export-Csv -Path $testCsv
$first = "`"" + $testObject[0].Length.ToString() + "`""
$second = "`"" + $testObject[1].Length.ToString() + "`""
$third = "`"" + $testObject[2].Length.ToString() + "`""
$expected = @("#TYPE System.String", "`"Length`"", $first , $second, $third)
$first = "`"" + $testObject[0].Length.ToString() + "`""
$second = "`"" + $testObject[1].Length.ToString() + "`""
$third = "`"" + $testObject[2].Length.ToString() + "`""
$expected = @("#TYPE System.String", "`"Length`"", $first , $second, $third)
for ( $i = 0; $i -lt $testCsv.Length; $i++)
{
$(Get-Content $testCsv)[$i] | Should Be $expected[$i]
}
for ( $i = 0; $i -lt $testCsv.Length; $i++)
{
$(Get-Content $testCsv)[$i] | Should Be $expected[$i]
}
}
It "Should be able to use the epcsv alias without error" {
{ $testObject | Export-Csv -Path $testCsv } | Should Not Throw
{ $testObject | Export-Csv -Path $testCsv } | Should Not Throw
}
It "Should have the same information when using the alias vs the cmdlet" {
$testObject | Export-Csv -Path $testCsv
$testObject | Export-Csv -Path $testCsv
$aliasObject = "alias.csv"
$aliasObject = "alias.csv"
$testObject | epcsv -Path $aliasObject
$testObject | epcsv -Path $aliasObject
for ( $i = 0; $i -lt $testCsv.Length; $i++)
{
$(Get-Content $testCsv)[$i] | Should Be $(Get-Content $aliasObject)[$i]
}
for ( $i = 0; $i -lt $testCsv.Length; $i++)
{
$(Get-Content $testCsv)[$i] | Should Be $(Get-Content $aliasObject)[$i]
}
# Clean up after yourself
Remove-Item $aliasObject -Force
# Clean up after yourself
Remove-Item $aliasObject -Force
}
}
+12 -12
View File
@@ -2,24 +2,24 @@ Describe "Export-FormatData" {
Context "Check Export-FormatData can be called validly." {
It "Should be able to be called without error" {
{ Get-FormatData | Export-FormatData -Path "outputfile" } | Should Not Throw
{ Get-FormatData | Export-FormatData -Path "outputfile" } | Should Not Throw
Remove-Item "outputfile" -Force -ErrorAction SilentlyContinue
}
}
Context "Check that the output is in the correct format" {
It "Should not return an empty xml file" {
Get-FormatData | Export-FormatData -Path "outputfile"
$piped = Get-Content "outputfile"
$piped | Should Not Be ""
Remove-Item "outputfile" -Force -ErrorAction SilentlyContinue
}
Get-FormatData | Export-FormatData -Path "outputfile"
$piped = Get-Content "outputfile"
$piped | Should Not Be ""
Remove-Item "outputfile" -Force -ErrorAction SilentlyContinue
}
It "Should have a valid xml tag at the start of the file" {
Get-FormatData | Export-FormatData -Path "outputfile"
$piped = Get-Content "outputfile"
$piped[0] | Should Be "<"
Remove-Item "outputfile" -Force -ErrorAction SilentlyContinue
}
It "Should have a valid xml tag at the start of the file" {
Get-FormatData | Export-FormatData -Path "outputfile"
$piped = Get-Content "outputfile"
$piped[0] | Should Be "<"
Remove-Item "outputfile" -Force -ErrorAction SilentlyContinue
}
}
}
+18 -18
View File
@@ -2,34 +2,34 @@ Describe "Format-Custom" {
Context "Check Format-Custom can be called validly." {
It "Should be able to be called without error" {
{ Get-FormatData | Format-Custom } | Should Not Throw
{ Get-FormatData | Format-Custom } | Should Not Throw
}
It "Should be able to call the fc alias without error" {
{ Get-FormatData | fc } | Should Not Throw
{ Get-FormatData | fc } | Should Not Throw
}
}
Context "Check Format-Custom aliases" {
It "Should have the same output between the alias and the unaliased function" {
$nonaliased = Get-FormatData | Format-Custom
$aliased = Get-FormatData | fc
$($nonaliased | Out-String).CompareTo($($aliased | Out-String)) | Should Be 0
}
It "Should have the same output between the alias and the unaliased function" {
$nonaliased = Get-FormatData | Format-Custom
$aliased = Get-FormatData | fc
$($nonaliased | Out-String).CompareTo($($aliased | Out-String)) | Should Be 0
}
}
Context "Check specific flags on Format-Custom" {
It "Should be able to specify the depth in output" {
$getprocesspester = Get-FormatData | Format-Custom -depth 1
($getprocesspester).Count | Should BeGreaterThan 0
}
It "Should be able to use the Property flag to select properties" {
$ProcessName = Get-Process | Format-Custom -Property "Name"
$ProcessName | Should Not Match "Handle"
}
It "Should be able to specify the depth in output" {
$getprocesspester = Get-FormatData | Format-Custom -depth 1
($getprocesspester).Count | Should BeGreaterThan 0
}
It "Should be able to use the Property flag to select properties" {
$ProcessName = Get-Process | Format-Custom -Property "Name"
$ProcessName | Should Not Match "Handle"
}
}
}
+35 -35
View File
@@ -1,74 +1,74 @@
Describe "Format-List" {
$nl = [Environment]::NewLine
BeforeEach {
$in = New-Object PSObject
Add-Member -InputObject $in -MemberType NoteProperty -Name testName -Value testValue
$in = New-Object PSObject
Add-Member -InputObject $in -MemberType NoteProperty -Name testName -Value testValue
}
It "Should call format list without error" {
{ $in | Format-List } | Should Not Throw
{ $in | Format-List } | Should Not BeNullOrEmpty
{ $in | Format-List } | Should Not Throw
{ $in | Format-List } | Should Not BeNullOrEmpty
}
It "Should be able to call the alias" {
{ $in | fl } | Should Not Throw
{ $in | fl } | Should Not BeNullOrEmpty
{ $in | fl } | Should Not Throw
{ $in | fl } | Should Not BeNullOrEmpty
}
It "Should have the same output whether choosing alias or not" {
$expected = $in | Format-List | Out-String
$actual = $in | fl | Out-String
$expected = $in | Format-List | Out-String
$actual = $in | fl | Out-String
$actual | Should Be $expected
$actual | Should Be $expected
}
It "Should produce the expected output" {
$expected = "${nl}${nl}testName : testValue${nl}${nl}${nl}${nl}"
$in = New-Object PSObject
Add-Member -InputObject $in -MemberType NoteProperty -Name testName -Value testValue
$expected = "${nl}${nl}testName : testValue${nl}${nl}${nl}${nl}"
$in = New-Object PSObject
Add-Member -InputObject $in -MemberType NoteProperty -Name testName -Value testValue
$in | Format-List | Should Not BeNullOrEmpty
$in | Format-List | Out-String | Should Not BeNullOrEmpty
$in | Format-List | Out-String | Should Be $expected
$in | Format-List | Should Not BeNullOrEmpty
$in | Format-List | Out-String | Should Not BeNullOrEmpty
$in | Format-List | Out-String | Should Be $expected
}
It "Should be able to call a property of the piped input" {
# Tested on two input commands to verify functionality.
{ Get-Process | Format-List -Property Name } | Should Not Throw
{ Get-Process | Format-List -Property Name } | Should Not BeNullOrEmpty
# Tested on two input commands to verify functionality.
{ Get-Process | Format-List -Property Name } | Should Not Throw
{ Get-Process | Format-List -Property Name } | Should Not BeNullOrEmpty
{ Get-Date | Format-List -Property DisplayName } | Should Not Throw
{ Get-Date | Format-List -Property DisplayName } | Should Not BeNullOrEmpty
{ Get-Date | Format-List -Property DisplayName } | Should Not Throw
{ Get-Date | Format-List -Property DisplayName } | Should Not BeNullOrEmpty
}
It "Should be able to display a list of props when separated by a comma" {
{ Get-Process | Format-List -Property Name,BasePriority } | Should Not Throw
{ Get-Process | Format-List -Property Name,BasePriority } | Should Not Throw
(Get-Process | Format-List -Property Name,BasePriority | Out-String) -Split "${nl}" |
Where-Object { $_.trim() -ne "" } |
ForEach-Object { $_ | Should Match "(Name)|(BasePriority)" }
(Get-Process | Format-List -Property Name,BasePriority | Out-String) -Split "${nl}" |
Where-Object { $_.trim() -ne "" } |
ForEach-Object { $_ | Should Match "(Name)|(BasePriority)" }
}
It "Should show the requested prop in every element" {
# Testing each element of format-list, using a for-each loop since the Format-List is so opaque
(Get-Process | Format-List -Property CPU | Out-String) -Split "${nl}" |
Where-Object { $_.trim() -ne "" } |
ForEach-Object { $_ | Should Match "CPU :" }
# Testing each element of format-list, using a for-each loop since the Format-List is so opaque
(Get-Process | Format-List -Property CPU | Out-String) -Split "${nl}" |
Where-Object { $_.trim() -ne "" } |
ForEach-Object { $_ | Should Match "CPU :" }
}
It "Should not show anything other than the requested props" {
$output = Get-Process | Format-List -Property Name | Out-String
$output = Get-Process | Format-List -Property Name | Out-String
$output | Should Not Match "CPU :"
$output | Should Not Match "Id :"
$output | Should Not Match "Handle :"
$output | Should Not Match "CPU :"
$output | Should Not Match "Id :"
$output | Should Not Match "Handle :"
}
It "Should be able to take input without piping objects to it" {
$output = { Format-List -InputObject $in }
$output = { Format-List -InputObject $in }
$output | Should Not Throw
$output | Should Not BeNullOrEmpty
$output | Should Not Throw
$output | Should Not BeNullOrEmpty
}
}
+22 -22
View File
@@ -1,39 +1,39 @@
Describe "Format-Table" {
It "Should call format table on piped input without error" {
{ Get-Process | Format-Table } | Should Not Throw
{ Get-Process | Format-Table } | Should Not Throw
{ Get-Process | ft } | Should Not Throw
{ Get-Process | ft } | Should Not Throw
}
It "Should return a format object data type" {
$val = (Get-Process | Format-Table | gm )
$val = (Get-Process | Format-Table | gm )
$val2 = (Get-Process | Format-Table | gm )
$val2 = (Get-Process | Format-Table | gm )
$val.TypeName | Should Match "Microsoft.Powershell.Commands.Internal.Format"
$val.TypeName | Should Match "Microsoft.Powershell.Commands.Internal.Format"
$val2.TypeName | Should Match "Microsoft.Powershell.Commands.Internal.Format"
$val2.TypeName | Should Match "Microsoft.Powershell.Commands.Internal.Format"
}
It "Should be able to be called with optional parameters" {
$v1 = (Get-Process | Format-Table *)
$v2 = (Get-Process | Format-Table -Property ProcessName)
$v3 = (Get-Process | Format-Table -GroupBy ProcessName)
$v4 = (Get-Process | Format-Table -View StartTime)
$v1 = (Get-Process | Format-Table *)
$v2 = (Get-Process | Format-Table -Property ProcessName)
$v3 = (Get-Process | Format-Table -GroupBy ProcessName)
$v4 = (Get-Process | Format-Table -View StartTime)
$v12 = (Get-Process | ft *)
$v22 = (Get-Process | ft -Property ProcessName)
$v32 = (Get-Process | ft -GroupBy ProcessName)
$v42 = (Get-Process | ft -View StartTime)
$v12 = (Get-Process | ft *)
$v22 = (Get-Process | ft -Property ProcessName)
$v32 = (Get-Process | ft -GroupBy ProcessName)
$v42 = (Get-Process | ft -View StartTime)
{ $v1 } | Should Not Throw
{ $v2 } | Should Not Throw
{ $v3 } | Should Not Throw
{ $v4 } | Should Not Throw
{ $v1 } | Should Not Throw
{ $v2 } | Should Not Throw
{ $v3 } | Should Not Throw
{ $v4 } | Should Not Throw
{ $v12 } | Should Not Throw
{ $v22 } | Should Not Throw
{ $v32 } | Should Not Throw
{ $v42 } | Should Not Throw
{ $v12 } | Should Not Throw
{ $v22 } | Should Not Throw
{ $v32 } | Should Not Throw
{ $v42 } | Should Not Throw
}
}
+11 -11
View File
@@ -1,40 +1,40 @@
Describe "Format-Wide" {
It "Should be able to call format wide without error" {
{ Get-Process | Format-Wide } | Should Not Throw
{ Get-Process | Format-Wide } | Should Not Throw
}
It "Should be able to use the fw alias without error" {
{ Get-Process | fw } | Should Not Throw
{ Get-Process | fw } | Should Not Throw
}
It "Should have the same output between the alias and the unaliased function" {
$nonaliased = Get-ChildItem | Format-Wide
$aliased = Get-ChildItem | fw
$nonaliased = Get-ChildItem | Format-Wide
$aliased = Get-ChildItem | fw
$($nonaliased | Out-String).CompareTo($($aliased | Out-String)) | Should Be 0
$($nonaliased | Out-String).CompareTo($($aliased | Out-String)) | Should Be 0
}
It "Should be able to specify the columns in output using the column switch" {
{ ls | Format-Wide -Column 3 } | Should Not Throw
{ ls | Format-Wide -Column 3 } | Should Not Throw
}
It "Should be able to use the autosize switch" {
{ ls | Format-Wide -Autosize } | Should Not Throw
{ ls | Format-Wide -Autosize } | Should Not Throw
}
It "Should be able to take inputobject instead of pipe" {
{ Format-Wide -InputObject $(ls) } | Should Not Throw
{ Format-Wide -InputObject $(ls) } | Should Not Throw
}
It "Should be able to use the property switch" {
{ Format-Wide -InputObject $(ls) -Property Mode } | Should Not Throw
{ Format-Wide -InputObject $(ls) -Property Mode } | Should Not Throw
}
It "Should throw an error when property switch and view switch are used together" {
{ Format-Wide -InputObject $(ls) -Property CreationTime -View aoeu } | Should Throw "Found invalid data"
{ Format-Wide -InputObject $(ls) -Property CreationTime -View aoeu } | Should Throw "Found invalid data"
}
It "Should throw and suggest proper input when view is used with invalid input without the property switch" {
{ Format-Wide -InputObject $(gps) -View aoeu } | Should Throw
{ Format-Wide -InputObject $(gps) -View aoeu } | Should Throw
}
}
+29 -29
View File
@@ -1,39 +1,39 @@
Describe "Get-Alias" {
It "Should have a return type of System.Array when gal returns more than one object" {
$val1=(Get-Alias a*)
$val2=(Get-Alias c*)
$i=0
$val1=(Get-Alias a*)
$val2=(Get-Alias c*)
$i=0
$val1 | ForEach-Object{ $i++};
if($i -lt 2) {
$val1.GetType().BaseType.FullName | Should Be "System.Management.Automation.CommandInfo"
}
else
{
$val1.GetType().BaseType.FullName | Should Be "System.Array"
}
$val1 | ForEach-Object{ $i++};
if($i -lt 2) {
$val1.GetType().BaseType.FullName | Should Be "System.Management.Automation.CommandInfo"
}
else
{
$val1.GetType().BaseType.FullName | Should Be "System.Array"
}
$val2 | ForEach-Object{ $i++};
if($i -lt 2) {
$val2.GetType().BaseType.FullName | Should Be "System.Management.Automation.CommandInfo"
}
else
{
$val2.GetType().BaseType.FullName | Should Be "System.Array"
}
$val2 | ForEach-Object{ $i++};
if($i -lt 2) {
$val2.GetType().BaseType.FullName | Should Be "System.Management.Automation.CommandInfo"
}
else
{
$val2.GetType().BaseType.FullName | Should Be "System.Array"
}
}
}
It "should return an array of 3 objects" {
$val = Get-Alias a*
$alias = gal a*
It "should return an array of 3 objects" {
$val = Get-Alias a*
$alias = gal a*
$val.CommandType | Should Not BeNullOrEmpty
$val.Name | Should Not BeNullOrEmpty
$val.ModuleName | Should BeNullOrEmpty
$val.CommandType | Should Not BeNullOrEmpty
$val.Name | Should Not BeNullOrEmpty
$val.ModuleName | Should BeNullOrEmpty
$alias.CommandType | Should Not BeNullOrEmpty
$alias.Name | Should Not BeNullOrEmpty
$alias.ModuleName | Should BeNullOrEmpty
$alias.CommandType | Should Not BeNullOrEmpty
$alias.Name | Should Not BeNullOrEmpty
$alias.ModuleName | Should BeNullOrEmpty
}
}
+22 -22
View File
@@ -1,40 +1,40 @@
Describe "Get-ChildItem" {
It "Should list the contents of the current folder" {
(Get-ChildItem .).Name.Length | Should BeGreaterThan 0
(Get-ChildItem .).Name.Length | Should BeGreaterThan 0
}
It "Should list the contents of the home directory" {
pushd $HOME
(Get-ChildItem .).Name.Length | Should BeGreaterThan 0
popd
pushd $HOME
(Get-ChildItem .).Name.Length | Should BeGreaterThan 0
popd
}
It "Should be able to use the ls alias" {
$(ls .).Name.Length | Should Be $(Get-ChildItem .).Name.Length
$(ls .).Name.Length | Should Be $(Get-ChildItem .).Name.Length
}
It "Should have a the proper fields and be populated" {
$var = Get-Childitem .
$var = Get-Childitem .
$var.Name.Length | Should BeGreaterThan 0
$var.Mode.Length | Should BeGreaterThan 0
$var.LastWriteTime | Should BeGreaterThan 0
$var.Length.Length | Should BeGreaterThan 0
$var.Name.Length | Should BeGreaterThan 0
$var.Mode.Length | Should BeGreaterThan 0
$var.LastWriteTime | Should BeGreaterThan 0
$var.Length.Length | Should BeGreaterThan 0
}
It "Should list files in sorted order" {
New-Item -Path $TestDrive -Name "a" -ItemType "File" -Force
New-Item -Path $TestDrive -Name "B" -ItemType "File" -Force
New-Item -Path $TestDrive -Name "c" -ItemType "File" -Force
New-Item -Path $TestDrive -Name "D" -ItemType "File" -Force
New-Item -Path $TestDrive -Name "E" -ItemType "Directory" -Force
$files = Get-ChildItem -Path $TestDrive
$files[0].Name | Should Be "E"
$files[1].Name | Should Be "a"
$files[2].Name | Should Be "B"
$files[3].Name | Should Be "c"
$files[4].Name | Should Be "D"
New-Item -Path $TestDrive -Name "a" -ItemType "File" -Force
New-Item -Path $TestDrive -Name "B" -ItemType "File" -Force
New-Item -Path $TestDrive -Name "c" -ItemType "File" -Force
New-Item -Path $TestDrive -Name "D" -ItemType "File" -Force
New-Item -Path $TestDrive -Name "E" -ItemType "Directory" -Force
$files = Get-ChildItem -Path $TestDrive
$files[0].Name | Should Be "E"
$files[1].Name | Should Be "a"
$files[2].Name | Should Be "B"
$files[3].Name | Should Be "c"
$files[4].Name | Should Be "D"
}
}
+36 -36
View File
@@ -14,96 +14,96 @@ Describe "Get-Content" {
$testPath2 = Join-Path -Path $TestDrive -ChildPath testfile2
BeforeEach {
New-Item -Path $testPath -ItemType file -Force -Value $testString
New-Item -Path $testPath2 -ItemType file -Force -Value $testString2
New-Item -Path $testPath -ItemType file -Force -Value $testString
New-Item -Path $testPath2 -ItemType file -Force -Value $testString2
}
AfterEach {
Remove-Item -Path $testPath -Force
Remove-Item -Path $testPath2 -Force
Remove-Item -Path $testPath -Force
Remove-Item -Path $testPath2 -Force
}
It "Should throw an error on a directory " {
# also tests that -erroraction SilentlyContinue will work.
Get-Content . -ErrorAction SilentlyContinue | Should Throw
# also tests that -erroraction SilentlyContinue will work.
Get-Content . -ErrorAction SilentlyContinue | Should Throw
}
It "Should return an Object when listing only a single line" {
(Get-Content -Path $testPath).GetType().BaseType.Name | Should Be "Object"
(Get-Content -Path $testPath).GetType().BaseType.Name | Should Be "Object"
}
It "Should deliver an array object when listing a file with multiple lines" {
(Get-Content -Path $testPath2).GetType().BaseType.Name | Should Be "Array"
(Get-Content -Path $testPath2).GetType().BaseType.Name | Should Be "Array"
}
It "Should return the correct information from a file" {
(Get-Content -Path $testPath) | Should Be $testString
(Get-Content -Path $testPath) | Should Be $testString
}
It "Should be able to call using the cat alias" {
{ cat -Path $testPath } | Should Not Throw
{ cat -Path $testPath } | Should Not Throw
}
It "Should be able to call using the gc alias" {
{ gc -Path $testPath } | Should Not Throw
{ gc -Path $testPath } | Should Not Throw
}
It "Should be able to call using the type alias" {
{ type -Path $testPath } | Should Not Throw
{ type -Path $testPath } | Should Not Throw
}
It "Should return the same values for aliases" {
$getContentAlias = Get-Content -Path $testPath
$gcAlias = gc -Path $testPath
$catAlias = cat -Path $testPath
$typeAlias = type -Path $testPath
$getContentAlias = Get-Content -Path $testPath
$gcAlias = gc -Path $testPath
$catAlias = cat -Path $testPath
$typeAlias = type -Path $testPath
$getContentAlias | Should Be $gcAlias
$getContentAlias | Should Be $catAlias
$getContentAlias | Should Be $typeAlias
$getContentAlias | Should Be $gcAlias
$getContentAlias | Should Be $catAlias
$getContentAlias | Should Be $typeAlias
}
It "Should be able to return a specific line from a file" {
(Get-Content -Path $testPath2)[1] | Should be $secondline
(Get-Content -Path $testPath2)[1] | Should be $secondline
}
It "Should be able to specify the number of lines to get the content of using the TotalCount switch" {
$returnArray = (cat -Path $testPath2 -TotalCount 2)
$returnArray = (cat -Path $testPath2 -TotalCount 2)
$returnArray[0] | Should Be $firstline
$returnArray[1] | Should Be $secondline
$returnArray[0] | Should Be $firstline
$returnArray[1] | Should Be $secondline
}
It "Should be able to specify the number of lines to get the content of using the Head switch" {
$returnArray = (cat -Path $testPath2 -Head 2)
$returnArray = (cat -Path $testPath2 -Head 2)
$returnArray[0] | Should Be $firstline
$returnArray[1] | Should Be $secondline
$returnArray[0] | Should Be $firstline
$returnArray[1] | Should Be $secondline
}
It "Should be able to specify the number of lines to get the content of using the First switch" {
$returnArray = (cat -Path $testPath2 -First 2)
$returnArray = (cat -Path $testPath2 -First 2)
$returnArray[0] | Should Be $firstline
$returnArray[1] | Should Be $secondline
$returnArray[0] | Should Be $firstline
$returnArray[1] | Should Be $secondline
}
It "Should return the last line of a file using the Tail switch" {
Get-Content -Path $testPath -Tail 1 | Should Be $testString
Get-Content -Path $testPath -Tail 1 | Should Be $testString
}
It "Should return the last lines of a file using the Last alias" {
Get-Content -Path $testPath2 -Last 1 | Should Be $fifthline
Get-Content -Path $testPath2 -Last 1 | Should Be $fifthline
}
It "Should be able to get content within a different drive" {
pushd env:
$expectedoutput = [Environment]::GetEnvironmentVariable("PATH");
pushd env:
$expectedoutput = [Environment]::GetEnvironmentVariable("PATH");
{ Get-Content PATH } | Should Not Throw
Get-Content PATH | Should Be $expectedoutput
{ Get-Content PATH } | Should Not Throw
Get-Content PATH | Should Be $expectedoutput
popd
popd
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
Describe "Get-Culture" {
It "Should return a type of CultureInfo for Get-Culture cmdlet" {
(Get-Culture).GetType() | Should Be CultureInfo
+19 -19
View File
@@ -1,36 +1,36 @@
Describe "Get-Date" {
It "Should return a DateTime object upon being called" {
(Get-Date).GetType().Name.Equals('DateTime') | Should Be $true
(Get-Date).GetType().Name.Equals('DateTime') | Should Be $true
}
It "Should have colons when ToString method is used" {
(Get-Date).ToString().Contains(":") | Should be $true
(Get-Date -DisplayHint Time).ToString().Contains(":") | Should be $true
(Get-Date -DisplayHint Date).ToString().Contains(":") | Should be $true
(Get-Date).ToString().Contains(":") | Should be $true
(Get-Date -DisplayHint Time).ToString().Contains(":") | Should be $true
(Get-Date -DisplayHint Date).ToString().Contains(":") | Should be $true
}
It "Should be able to use the format flag" {
# You would think that one could use simple loops here, but apparently powershell in Windows returns different values in loops
# You would think that one could use simple loops here, but apparently powershell in Windows returns different values in loops
(Get-Date -Format d).Contains("/") | Should be $true
(Get-Date -Format D).Contains(",") | Should be $true
(Get-Date -Format f).Contains(",") -and (Get-Date -Format f).Contains(":") | Should be $true
(Get-Date -Format F).Contains(",") -and (Get-Date -Format F).Contains(":") | Should be $true
(Get-Date -Format g).Contains("/") -and (Get-Date -Format g).Contains(":") | Should be $true
(Get-Date -Format G).Contains("/") -and (Get-Date -Format G).Contains(":") | Should be $true
(Get-Date -Format m).Contains(",") -or `
(Get-Date -Format m).Contains(":") -or `
(Get-Date -Format m).Contains("/") | Should be $false
(Get-Date -Format d).Contains("/") | Should be $true
(Get-Date -Format D).Contains(",") | Should be $true
(Get-Date -Format f).Contains(",") -and (Get-Date -Format f).Contains(":") | Should be $true
(Get-Date -Format F).Contains(",") -and (Get-Date -Format F).Contains(":") | Should be $true
(Get-Date -Format g).Contains("/") -and (Get-Date -Format g).Contains(":") | Should be $true
(Get-Date -Format G).Contains("/") -and (Get-Date -Format G).Contains(":") | Should be $true
(Get-Date -Format m).Contains(",") -or `
(Get-Date -Format m).Contains(":") -or `
(Get-Date -Format m).Contains("/") | Should be $false
}
It "Should check that Get-Date can return the correct datetime from the system time" {
$timeDifference = $(Get-Date).Subtract([System.DateTime]::Now)
$timeDifference.Days | Should Be 0
$timeDifference.Hours | Should Be 0
$timeDifference.Minutes | Should Be 0
$timeDifference.Milliseconds | Should BeLessThan 1
$timeDifference.Ticks | Should BeLessThan 10000
$timeDifference.Days | Should Be 0
$timeDifference.Hours | Should Be 0
$timeDifference.Minutes | Should Be 0
$timeDifference.Milliseconds | Should BeLessThan 1
$timeDifference.Ticks | Should BeLessThan 10000
}
}
+11 -11
View File
@@ -1,17 +1,17 @@
Describe "Get-Event" {
BeforeEach {
( New-Event -SourceIdentifier PesterTestEvent -sender Windows.timer -messagedata "PesterTestMessage" )
}
( New-Event -SourceIdentifier PesterTestEvent -sender Windows.timer -messagedata "PesterTestMessage" )
}
AfterEach {
( Remove-Event -SourceIdentifier PesterTestEvent -ErrorAction SilentlyContinue )
( Remove-Event -SourceIdentifier PesterTestEvent -ErrorAction SilentlyContinue )
}
Context "Check return type of Get-Event" {
It "Should return PSEventArgs as return type of Get-Event" {
{ ( Get-Event -SourceIdentifier PesterTestEvent ).GetType() | Should Be System.Management.Automation.PSEventArgs }
It "Should return PSEventArgs as return type of Get-Event" {
{ ( Get-Event -SourceIdentifier PesterTestEvent ).GetType() | Should Be System.Management.Automation.PSEventArgs }
}
}
@@ -20,14 +20,14 @@ Describe "Get-Event" {
It "Should return at least 1 event" {
{ (Get-Event).Count | Should BeGreaterThan 0 }
}
It "Should return PesterTestMessage as the MessageData" {
{ (Get-Event -SourceIdentifier PesterTimer).MessageData | Should Be "PesterTestMessage" }
}
It "Should return Sender as Windows.timer" {
{ (Get-Event -SourceIdentifier PesterTimer).Sender | Should be Windows.timer }
It "Should return Sender as Windows.timer" {
{ (Get-Event -SourceIdentifier PesterTimer).Sender | Should be Windows.timer }
}
}
}
@@ -1,12 +1,12 @@
Describe "Get-EventSubscriber" {
AfterEach {
Unregister-Event -SourceIdentifier PesterTestRegister -ErrorAction SilentlyContinue
Unregister-Event -SourceIdentifier PesterTestRegister -ErrorAction SilentlyContinue
}
Context "Check return type of Get-EventSubscriber" {
It "Should return System.Management.Automation.PSEventSubscriber as return type of New-Event" {
It "Should return System.Management.Automation.PSEventSubscriber as return type of New-Event" {
$pesterobject = (New-Object System.Collections.ObjectModel.ObservableCollection[object])
Register-ObjectEvent -InputObject $pesterobject -EventName CollectionChanged -SourceIdentifier PesterTestRegister
(Get-EventSubscriber).GetType() | Should Be System.Management.Automation.PSEventSubscriber
@@ -20,8 +20,8 @@ Describe "Get-EventSubscriber" {
(Get-EventSubscriber -SourceIdentifier PesterTestRegister).SourceIdentifier | Should Be "PesterTestRegister"
}
It "Should return an integer greater than 0 for the SubscriptionId" {
$pesterobject = (New-Object System.Collections.ObjectModel.ObservableCollection[object])
It "Should return an integer greater than 0 for the SubscriptionId" {
$pesterobject = (New-Object System.Collections.ObjectModel.ObservableCollection[object])
Register-ObjectEvent -InputObject $pesterobject -EventName CollectionChanged -SourceIdentifier PesterTestRegister
(Get-EventSubscriber -SourceIdentifier PesterTestRegister).SubscriptionId | Should BeGreaterThan 0
+29 -29
View File
@@ -2,48 +2,48 @@ Describe "Get-FileHash" {
New-Variable testDocument -Value (Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath testablescript.ps1) -Scope Global -Force
# The MACTripleDES and RIPEMD160 algorithms are unsupported on Linux
$algorithms = @{"SHA1" ="01B865D143E07ECC875AB0EFC0A4429387FD0CF7";
"SHA256" = "4A6DA9F1C0827143BB19FC4B0F2A8057BC1DF55F6D1F62FA3B917BA458E8F570";
"SHA384" = "656215B6A07011E625206F43E57873F49AD7B36DFCABB70F6CDCE2303D7A603E55D052774D26F339A6D80A264340CB8C";
"SHA512" = "C688C33027D89ACAC920545471C8053D8F64A54E21D0415F1E03766DDCDA215420E74FAFD1DC399864C6B6B5723A3358BD337339906797A39090B02229BF31FE";
"MD5" = "7B09811D1631C9FD46B39D1D35522F0A";
}
"SHA256" = "4A6DA9F1C0827143BB19FC4B0F2A8057BC1DF55F6D1F62FA3B917BA458E8F570";
"SHA384" = "656215B6A07011E625206F43E57873F49AD7B36DFCABB70F6CDCE2303D7A603E55D052774D26F339A6D80A264340CB8C";
"SHA512" = "C688C33027D89ACAC920545471C8053D8F64A54E21D0415F1E03766DDCDA215420E74FAFD1DC399864C6B6B5723A3358BD337339906797A39090B02229BF31FE";
"MD5" = "7B09811D1631C9FD46B39D1D35522F0A";
}
Context "Cmdlet result tests" {
It "Should default to correct hash algorithm" {
$result = Get-FileHash $testDocument
It "Should default to correct hash algorithm" {
$result = Get-FileHash $testDocument
$result.Algorithm | Should Be "SHA256"
}
$result.Algorithm | Should Be "SHA256"
}
It "Should be able to set the default hash algorithm" {
$PSDefaultParameterValues.add("Get-FileHash:Algorithm","MD5")
It "Should be able to set the default hash algorithm" {
$PSDefaultParameterValues.add("Get-FileHash:Algorithm","MD5")
$result = Get-FileHash $testDocument
$result = Get-FileHash $testDocument
$result.Algorithm | Should Be "MD5"
$result.Algorithm | Should Be "MD5"
$PSDefaultParameterValues.Remove("Get-FileHash:Algorithm")
}
$PSDefaultParameterValues.Remove("Get-FileHash:Algorithm")
}
It "Should list the path of the file under test" {
$result = Get-FileHash $testDocument
It "Should list the path of the file under test" {
$result = Get-FileHash $testDocument
$result.Path | Should Be $testDocument
}
$result.Path | Should Be $testDocument
}
}
Context "Algorithm tests" {
It "Should be able to get the correct hash from each algorithm" {
foreach ( $algorithm in $algorithms.Keys)
{
$algorithmResult = Get-FileHash $testDocument -Algorithm $algorithm
It "Should be able to get the correct hash from each algorithm" {
foreach ( $algorithm in $algorithms.Keys)
{
$algorithmResult = Get-FileHash $testDocument -Algorithm $algorithm
$algorithmResult.Hash | Should Be $algorithms[$algorithm]
}
$algorithmResult.Hash | Should Be $algorithms[$algorithm]
}
#MACTripleDES and RIPEMD160 are unsupported in the existing Pester tests from Windows team
{ Get-FileHash $testDocument -Algorithm MACTripleDES } | Should Throw "Algorithm 'MACTripleDES' is not supported in this system."
{ Get-FileHash $testDocument -Algorithm RIPEMD160 } | Should Throw "Algorithm 'RIPEMD160' is not supported in this system."
}
#MACTripleDES and RIPEMD160 are unsupported in the existing Pester tests from Windows team
{ Get-FileHash $testDocument -Algorithm MACTripleDES } | Should Throw "Algorithm 'MACTripleDES' is not supported in this system."
{ Get-FileHash $testDocument -Algorithm RIPEMD160 } | Should Throw "Algorithm 'RIPEMD160' is not supported in this system."
}
}
}
+5 -5
View File
@@ -1,13 +1,13 @@
Describe "Get-FormatData" {
Context "Check return type of Get-FormatData" {
It "Should return an object[] as the return type" {
(Get-FormatData).GetType() | Should be System.Object[]
It "Should return an object[] as the return type" {
(Get-FormatData).GetType() | Should be System.Object[]
}
It "Should return a System.Object[] with a count greater than 0" {
(Get-formatData).Count | Should BeGreaterThan 0
It "Should return a System.Object[] with a count greater than 0" {
(Get-formatData).Count | Should BeGreaterThan 0
}
}
}
+7 -7
View File
@@ -1,20 +1,20 @@
Describe "Get-Item" {
It "Should list all the items in the current working directory when asterisk is used" {
(Get-Item (Join-Path -Path $PSScriptRoot -ChildPath "*")).GetType().BaseType | Should Be 'array'
(Get-Item (Join-Path -Path $PSScriptRoot -ChildPath "*")).GetType().Name | Should Be 'Object[]'
(Get-Item (Join-Path -Path $PSScriptRoot -ChildPath "*")).GetType().BaseType | Should Be 'array'
(Get-Item (Join-Path -Path $PSScriptRoot -ChildPath "*")).GetType().Name | Should Be 'Object[]'
}
It "Should return the name of the current working directory when a dot is used" {
(Get-Item $PSScriptRoot).GetType().BaseType | Should Be 'System.IO.FileSystemInfo'
(Get-Item $PSScriptRoot).Name | Should Be (Split-Path $PSScriptRoot -Leaf)
(Get-Item $PSScriptRoot).GetType().BaseType | Should Be 'System.IO.FileSystemInfo'
(Get-Item $PSScriptRoot).Name | Should Be (Split-Path $PSScriptRoot -Leaf)
}
It "Should return the proper Name and BaseType for directory objects vs file system objects" {
(Get-Item $PSScriptRoot).GetType().Name | Should Be 'DirectoryInfo'
(Get-Item (Join-Path -Path $PSScriptRoot -ChildPath Get-Item.Tests.ps1)).GetType().Name | Should Be 'FileInfo'
(Get-Item $PSScriptRoot).GetType().Name | Should Be 'DirectoryInfo'
(Get-Item (Join-Path -Path $PSScriptRoot -ChildPath Get-Item.Tests.ps1)).GetType().Name | Should Be 'FileInfo'
}
It "Should have mode flags set" {
ls $PSScriptRoot | foreach-object { $_.Mode | Should Not BeNullOrEmpty }
ls $PSScriptRoot | foreach-object { $_.Mode | Should Not BeNullOrEmpty }
}
}
+16 -16
View File
@@ -9,44 +9,44 @@ Describe "Get-ItemProperty" {
New-Item $testfile -ItemType file -Force
It "Should be able to be called on in the current directory" {
$(Get-ItemProperty $PSScriptRoot).Name | Should Be $currentDirectory
$(Get-ItemProperty $PSScriptRoot).Name | Should Be $currentDirectory
}
It "Should be able to be called on a parent directory" {
(Get-ItemProperty $PSScriptRoot/..).Name | Should Be $parentDirectory
(Get-ItemProperty $PSScriptRoot/..).Name | Should Be $parentDirectory
}
It "Should be able to be called on a directory using the path switch" {
{ Get-ItemProperty -Path $tempDirectory } | Should Not Throw
{ Get-ItemProperty -Path $tempDirectory } | Should Not Throw
}
It "Should be able to be called on a file using the path switch" {
{ Get-ItemProperty -Path $testfile } | Should Not Throw
{ Get-ItemProperty -Path $testfile } | Should Not Throw
}
It "Should be able to access a property using the Path and name switches" {
{ Get-ItemProperty -Path $testfile -Name fullname } | Should Not Throw
{ Get-ItemProperty -Path $testfile -Name fullname } | Should Not Throw
$output = Get-ItemProperty -Path $testfile -Name fullname
$output = Get-ItemProperty -Path $testfile -Name fullname
$output.PSPath | Should Not BeNullOrEmpty
$output.PSPath | Should Not BeNullOrEmpty
$output.PSDrive | Should Be $testprovider
$output.PSDrive | Should Be $testprovider
$output.PSProvider.Name | Should Be "FileSystem"
$output.PSProvider.Name | Should Be "FileSystem"
}
It "Should be able to use the gp alias without error" {
{ gp . } | Should Not Throw
{ gp .. } | Should Not Throw
{ gp . } | Should Not Throw
{ gp .. } | Should Not Throw
}
It "Should have the same results between alias and cmdlet" {
$alias = gp -Path $testfile -Name fullname
$cmdlet = Get-ItemProperty -Path $testfile -Name fullname
$alias = gp -Path $testfile -Name fullname
$cmdlet = Get-ItemProperty -Path $testfile -Name fullname
$alias.PSPath | Should Be $cmdlet.PSPath
$alias.PSDrive | Should Be $cmdlet.PSDrive
$alias.PSProvider.Name | Should Be $cmdlet.PSProvider.Name
$alias.PSPath | Should Be $cmdlet.PSPath
$alias.PSDrive | Should Be $cmdlet.PSDrive
$alias.PSProvider.Name | Should Be $cmdlet.PSProvider.Name
}
}
+4 -4
View File
@@ -1,17 +1,17 @@
Describe "Get-Location" {
BeforeEach {
pushd $env:HOME
pushd $env:HOME
}
AfterEach {
popd
popd
}
It "Should list the output of the current working directory" {
(Get-Location).Path | Should Be $env:HOME
(Get-Location).Path | Should Be $env:HOME
}
It "Should do exactly the same thing as its alias" {
(pwd).Path | Should Be (Get-Location).Path
(pwd).Path | Should Be (Get-Location).Path
}
}
+28 -28
View File
@@ -1,41 +1,41 @@
Describe "Get-Member" {
It "Should be able to be called on string objects, ints, arrays, etc" {
$a = 1 #test numbers
$b = 1.3
$c = $false #test bools
$d = @(1,3) # test arrays
$e = "anoeduntodeu" #test strings
$f = 'asntoheusth' #test strings
$a = 1 #test numbers
$b = 1.3
$c = $false #test bools
$d = @(1,3) # test arrays
$e = "anoeduntodeu" #test strings
$f = 'asntoheusth' #test strings
Get-Member -InputObject $a | Should Not BeNullOrEmpty
Get-Member -InputObject $b | Should Not BeNullOrEmpty
Get-Member -InputObject $c | Should Not BeNullOrEmpty
Get-Member -InputObject $d | Should Not BeNullOrEmpty
Get-Member -InputObject $e | Should Not BeNullOrEmpty
Get-Member -InputObject $f | Should Not BeNullOrEmpty
Get-Member -InputObject $a | Should Not BeNullOrEmpty
Get-Member -InputObject $b | Should Not BeNullOrEmpty
Get-Member -InputObject $c | Should Not BeNullOrEmpty
Get-Member -InputObject $d | Should Not BeNullOrEmpty
Get-Member -InputObject $e | Should Not BeNullOrEmpty
Get-Member -InputObject $f | Should Not BeNullOrEmpty
}
It "Should be able to extract a field from string objects, ints, arrays, etc" {
$a = 1 #test numbers
$b = 1.3
$c = $false #test bools
$d = @(1,3) # test arrays
$e = "anoeduntodeu" #test strings
$f = 'asntoheusth' #test strings
$a = 1 #test numbers
$b = 1.3
$c = $false #test bools
$d = @(1,3) # test arrays
$e = "anoeduntodeu" #test strings
$f = 'asntoheusth' #test strings
$a.GetType().Name | Should Be 'Int32'
$b.GetType().Name | Should Be 'Double'
$c.GetType().Name | Should Be 'Boolean'
$d.GetType().Name | Should Be 'Object[]'
$e.GetType().Name | Should Be 'String'
$f.GetType().Name | Should Be 'String'
$a.GetType().Name | Should Be 'Int32'
$b.GetType().Name | Should Be 'Double'
$c.GetType().Name | Should Be 'Boolean'
$d.GetType().Name | Should Be 'Object[]'
$e.GetType().Name | Should Be 'String'
$f.GetType().Name | Should Be 'String'
}
It "Should be able to be called on a newly created PSObject" {
$o = New-Object psobject
# this creates a dependency on the Add-Member cmdlet.
Add-Member -InputObject $o -MemberType NoteProperty -Name proppy -Value "superVal"
$o = New-Object psobject
# this creates a dependency on the Add-Member cmdlet.
Add-Member -InputObject $o -MemberType NoteProperty -Name proppy -Value "superVal"
Get-Member -InputObject $o | Should Not BeNullOrEmpty
Get-Member -InputObject $o | Should Not BeNullOrEmpty
}
}
+21 -21
View File
@@ -1,47 +1,47 @@
Describe "Get-PSDrive" {
It "Should not throw" {
Get-PSDrive | Should Not BeNullOrEmpty
Get-PSDrive | Should Not BeNullOrEmpty
}
It "Should have a name and a length property" {
(Get-PSDrive).Name | Should Not BeNullOrEmpty
(Get-PSDrive).Root.Length | Should Not BeLessThan 1
(Get-PSDrive).Name | Should Not BeNullOrEmpty
(Get-PSDrive).Root.Length | Should Not BeLessThan 1
}
It "Should be able to be called with the gdr alias" {
{ gdr } | Should Not Throw
{ gdr } | Should Not Throw
gdr | Should Not BeNullOrEmpty
gdr | Should Not BeNullOrEmpty
}
It "Should be the same output between Get-PSDrive and gdr" {
$alias = gdr
$actual = Get-PSDrive
$alias = gdr
$actual = Get-PSDrive
$alias | Should Be $actual
$alias | Should Be $actual
}
It "Should return drive info"{
(Get-PSDrive Env).Name | Should Be Env
(Get-PSDrive Cert).Root | Should Be \
(Get-PSDrive Env).Name | Should Be Env
(Get-PSDrive Cert).Root | Should Be \
if ($IsWindows)
{
(Get-PSDrive C).Provider.Name | Should Be FileSystem
}
else
{
(Get-PSDrive /).Provider.Name | Should Be FileSystem
}
if ($IsWindows)
{
(Get-PSDrive C).Provider.Name | Should Be FileSystem
}
else
{
(Get-PSDrive /).Provider.Name | Should Be FileSystem
}
}
It "Should be able to access a drive using the PSProvider switch" {
(Get-PSDrive -PSProvider FileSystem).Name.Length | Should BeGreaterThan 0
(Get-PSDrive -PSProvider FileSystem).Name.Length | Should BeGreaterThan 0
}
It "Should return true that a drive that does not exist"{
!(Get-PSDrive fake -ErrorAction SilentlyContinue) | Should Be $True
Get-PSDrive fake -ErrorAction SilentlyContinue | Should BeNullOrEmpty
!(Get-PSDrive fake -ErrorAction SilentlyContinue) | Should Be $True
Get-PSDrive fake -ErrorAction SilentlyContinue | Should BeNullOrEmpty
}
}
+8 -8
View File
@@ -1,25 +1,25 @@
Describe "Get-PSProvider" {
It "Should be able to call with no parameters without error" {
{ Get-PSProvider } | Should Not Throw
{ Get-PSProvider } | Should Not Throw
}
It "Should be able to call the filesystem provider" {
{ Get-PSProvider FileSystem } | Should Not Throw
{ Get-PSProvider FileSystem } | Should Not Throw
$actual = Get-PSProvider FileSystem
$actual = Get-PSProvider FileSystem
$actual.Name | Should Be "FileSystem"
$actual.Name | Should Be "FileSystem"
$actual.Capabilities | Should Be "Filter, ShouldProcess, Credentials"
$actual.Capabilities | Should Be "Filter, ShouldProcess, Credentials"
}
It "Should be able to call a provider with a wildcard expression" {
{ Get-PSProvider File*m } | Should Not Throw
{ Get-PSProvider File*m } | Should Not Throw
}
It "Should be able to pipe the output" {
$actual = Get-PSProvider
$actual = Get-PSProvider
{ $actual | Format-List } | Should Not Throw
{ $actual | Format-List } | Should Not Throw
}
}
+44 -44
View File
@@ -1,82 +1,82 @@
Describe "Get-Random" {
It "Should return a random number greater than -1 " {
Get-Random | Should BeGreaterThan -1
Get-Random | Should BeGreaterThan -1
}
It "Should return a random number less than 100 " {
Get-Random -Maximum 100 | Should BeLessThan 100
Get-Random -Maximum 100 | Should BeGreaterThan -1
Get-Random -Maximum 100 | Should BeLessThan 100
Get-Random -Maximum 100 | Should BeGreaterThan -1
}
It "Should return a random number less than 100 and greater than -100 " {
$randomNumber = Get-Random -Minimum -100 -Maximum 100
$randomNumber | Should BeLessThan 100
$randomNumber | Should BeGreaterThan -101
$randomNumber = Get-Random -Minimum -100 -Maximum 100
$randomNumber | Should BeLessThan 100
$randomNumber | Should BeGreaterThan -101
}
It "Should return a random number less than 20.93 and greater than 10.7 " {
$randomNumber = Get-Random -Minimum 10.7 -Maximum 20.93
$randomNumber | Should BeLessThan 20.93
$randomNumber | Should BeGreaterThan 10.7
$randomNumber = Get-Random -Minimum 10.7 -Maximum 20.93
$randomNumber | Should BeLessThan 20.93
$randomNumber | Should BeGreaterThan 10.7
}
It "Should return same number for both Get-Random when switch SetSeed is used " {
$firstRandomNumber = Get-Random -Maximum 100 -SetSeed 23
$secondRandomNumber = Get-Random -Maximum 100 -SetSeed 23
$firstRandomNumber | Should be $secondRandomNumber
$firstRandomNumber = Get-Random -Maximum 100 -SetSeed 23
$secondRandomNumber = Get-Random -Maximum 100 -SetSeed 23
$firstRandomNumber | Should be $secondRandomNumber
}
It "Should return a number from 1,2,3,5,8,13 " {
$randomNumber = Get-Random -InputObject 1, 2, 3, 5, 8, 13
$randomNumber | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber = Get-Random -InputObject 1, 2, 3, 5, 8, 13
$randomNumber | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
}
It "Should return an array " {
$randomNumber = Get-Random -InputObject 1, 2, 3, 5, 8, 13 -Count 3
$randomNumber.GetType().BaseType | Should Be array
$randomNumber = Get-Random -InputObject 1, 2, 3, 5, 8, 13 -Count 3
$randomNumber.GetType().BaseType | Should Be array
}
It "Should return three random numbers for array of 1,2,3,5,8,13 " {
$randomNumber = Get-Random -InputObject 1, 2, 3, 5, 8, 13 -Count 3
$randomNumber[0] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[1] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[2] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[3] | Should BeNullOrEmpty
$randomNumber = Get-Random -InputObject 1, 2, 3, 5, 8, 13 -Count 3
$randomNumber[0] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[1] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[2] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[3] | Should BeNullOrEmpty
}
It "Should return all the numbers for array of 1,2,3,5,8,13 in no particular order" {
$randomNumber = Get-Random -InputObject 1, 2, 3, 5, 8, 13 -Count ([int]::MaxValue)
$randomNumber[0] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[1] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[2] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[3] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[4] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[5] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[6] | Should BeNullOrEmpty
$randomNumber = Get-Random -InputObject 1, 2, 3, 5, 8, 13 -Count ([int]::MaxValue)
$randomNumber[0] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[1] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[2] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[3] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[4] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[5] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[6] | Should BeNullOrEmpty
}
It "Should return for a string collection " {
$randomNumber = Get-Random -InputObject "red", "yellow", "blue"
$randomNumber | Should Be ("red" -or "yellow" -or "blue")
It "Should return for a string collection " {
$randomNumber = Get-Random -InputObject "red", "yellow", "blue"
$randomNumber | Should Be ("red" -or "yellow" -or "blue")
}
It "Should return a number for hexdecimal " {
$randomNumber = Get-Random 0x07FFFFFFFFF
$randomNumber | Should BeLessThan 549755813887
$randomNumber | Should BeGreaterThan 0
It "Should return a number for hexdecimal " {
$randomNumber = Get-Random 0x07FFFFFFFFF
$randomNumber | Should BeLessThan 549755813887
$randomNumber | Should BeGreaterThan 0
}
It "Should return false, check two random numbers are not equal when not using the SetSeed switch " {
$firstRandomNumber = Get-Random
$secondRandomNumber = Get-Random
$firstRandomNumber | Should Not Be $secondRandomNumber
$firstRandomNumber = Get-Random
$secondRandomNumber = Get-Random
$firstRandomNumber | Should Not Be $secondRandomNumber
}
It "Should return the same number for hexidemical number and regular number when the switch SetSeed it used " {
$firstRandomNumber = Get-Random 0x07FFFFFFFF -SetSeed 20
$secondRandomNumber = Get-Random 34359738367 -SetSeed 20
$firstRandomNumber | Should Be @secondRandomNumber
$firstRandomNumber = Get-Random 0x07FFFFFFFF -SetSeed 20
$secondRandomNumber = Get-Random 34359738367 -SetSeed 20
$firstRandomNumber | Should Be @secondRandomNumber
}
It "Should throw an error because the hexidecial number is to large " {
{ Get-Random 0x07FFFFFFFFFFFFFFFF } | Should Throw "Value was either too large or too small for a UInt32"
It "Should throw an error because the hexidecial number is to large " {
{ Get-Random 0x07FFFFFFFFFFFFFFFF } | Should Throw "Value was either too large or too small for a UInt32"
}
}
+4 -4
View File
@@ -2,9 +2,9 @@ Describe "Get-RunspaceDebug" {
Context "Check return types of RunspaceDebug" {
It "Should return Microsoft.Powershell.Commands.PSRunspaceDebug as the return type" {
$rs = Get-RunspaceDebug
$rs[0].GetType().Name | Should Be PSRunspaceDebug
}
It "Should return Microsoft.Powershell.Commands.PSRunspaceDebug as the return type" {
$rs = Get-RunspaceDebug
$rs[0].GetType().Name | Should Be PSRunspaceDebug
}
}
}
+2 -2
View File
@@ -1,9 +1,9 @@
Describe "Get-UICulture" {
It "Should return a type of CultureInfo as the name of the type" {
(Get-UICulture).GetType().Name | Should Match CultureInfo
(Get-UICulture).GetType().Name | Should Match CultureInfo
}
It "Should have $ PsUICulture variable be equivalent to Get-UICulture object" {
(Get-UICulture).Name | Should Be $PsUICulture
(Get-UICulture).Name | Should Be $PsUICulture
}
}
+35 -35
View File
@@ -1,70 +1,70 @@
Describe "Get-Unique" {
$sortedList1 = 1,2,2,3,3,4,5
It "Should be able to use the Get-Unique cmdlet without error with inputObject switch" {
{ Get-Unique -InputObject $sortedList1 } | Should Not Throw
{ Get-Unique -InputObject $sortedList1 } | Should Not Throw
}
It "Should be able to uset the gu alias without error" {
{ gu -InputObject $sortedList1 } | Should Not Throw
{ gu -InputObject $sortedList1 } | Should Not Throw
}
It "Should output an array" {
$(Get-Unique -InputObject $sortedList1).GetType().BaseType | Should Be Array
$(Get-Unique -InputObject $sortedList1).GetType().BaseType | Should Be Array
}
It "Should output an array of unchanged items when the InputObject switch is used" {
$actual = Get-Unique -InputObject $sortedList1
$actual = Get-Unique -InputObject $sortedList1
$actual[0] | Should Be $sortedList1[0]
$actual[1] | Should Be $sortedList1[1]
$actual[2] | Should Be $sortedList1[2]
$actual[3] | Should Be $sortedList1[3]
$actual[4] | Should Be $sortedList1[4]
$actual[5] | Should Be $sortedList1[5]
$actual[6] | Should Be $sortedList1[6]
$actual[0] | Should Be $sortedList1[0]
$actual[1] | Should Be $sortedList1[1]
$actual[2] | Should Be $sortedList1[2]
$actual[3] | Should Be $sortedList1[3]
$actual[4] | Should Be $sortedList1[4]
$actual[5] | Should Be $sortedList1[5]
$actual[6] | Should Be $sortedList1[6]
$actual.Length | Should Be 7
$actual.Length | Should Be 7
}
It "Should accept piped input" {
{ $actualOutput = $sortedList1 | Get-Unique } | Should Not Throw
{ $actualOutput = $sortedList1 | Get-Unique } | Should Not Throw
}
It "Should have the expected output when piped input is used" {
$actualOutput = $sortedList1 | Get-Unique
$expectedOutput = 1,2,3,4,5
$actualOutput = $sortedList1 | Get-Unique
$expectedOutput = 1,2,3,4,5
$actualOutput.Length | Should Be $expectedOutput.Length
$actualOutput.Length | Should Be $expectedOutput.Length
$actualOutput[0] | Should Be $expectedOutput[0]
$actualOutput[1] | Should Be $expectedOutput[1]
$actualOutput[2] | Should Be $expectedOutput[2]
$actualOutput[3] | Should Be $expectedOutput[3]
$actualOutput[4] | Should Be $expectedOutput[4]
$actualOutput[0] | Should Be $expectedOutput[0]
$actualOutput[1] | Should Be $expectedOutput[1]
$actualOutput[2] | Should Be $expectedOutput[2]
$actualOutput[3] | Should Be $expectedOutput[3]
$actualOutput[4] | Should Be $expectedOutput[4]
}
It "Should be able to input a collection in the inputObject switch" {
$collection = "a", "b", "b", "d"
$actual = Get-Unique -InputObject $collection
$collection = "a", "b", "b", "d"
$actual = Get-Unique -InputObject $collection
$actual.Length | Should Be $collection.Length
$actual.Length | Should Be $collection.Length
$actual[0] | Should Be $collection[0]
$actual[1] | Should Be $collection[1]
$actual[2] | Should Be $collection[2]
$actual[3] | Should Be $collection[3]
$actual[0] | Should Be $collection[0]
$actual[1] | Should Be $collection[1]
$actual[2] | Should Be $collection[2]
$actual[3] | Should Be $collection[3]
}
It "Should get the unique items when piped collection input is used" {
$collection = "a", "b", "b", "d"
$expectedOutput = "a", "b", "d"
$collection = "a", "b", "b", "d"
$expectedOutput = "a", "b", "d"
$actual = Get-Unique -InputObject $collection
$actual = Get-Unique -InputObject $collection
$actual.Length | Should Be $collection.Length
$actual.Length | Should Be $collection.Length
$actual[0] | Should Be $collection[0]
$actual[1] | Should Be $collection[1]
$actual[2] | Should Be $collection[2]
$actual[0] | Should Be $collection[0]
$actual[1] | Should Be $collection[1]
$actual[2] | Should Be $collection[2]
}
}
+78 -78
View File
@@ -1,140 +1,140 @@
Describe "Get-Variable" {
It "Should be able to call with no parameters without error" {
{ Get-Variable } | Should Not Throw
{ Get-Variable } | Should Not Throw
}
It "Should return environment variables when called with no parameters" {
(Get-Variable).Name -contains "$" | Should Be $true
(Get-Variable).Name -contains "?" | Should Be $true
(Get-Variable).Name -contains "HOST" | Should Be $true
(Get-Variable).Name -contains "PWD" | Should Be $true
(Get-Variable).Name -contains "PID" | Should Be $true
(Get-Variable).Name -contains "^" | Should Be $true
(Get-Variable).Name -contains "$" | Should Be $true
(Get-Variable).Name -contains "?" | Should Be $true
(Get-Variable).Name -contains "HOST" | Should Be $true
(Get-Variable).Name -contains "PWD" | Should Be $true
(Get-Variable).Name -contains "PID" | Should Be $true
(Get-Variable).Name -contains "^" | Should Be $true
}
It "Should return the value of an object" {
New-Variable -Name tempVar -Value 1
(Get-Variable tempVar).Value | Should Be (1)
New-Variable -Name tempVar -Value 1
(Get-Variable tempVar).Value | Should Be (1)
}
It "Should be able to call using the gv alias" {
{ gv } | Should Not Throw
{ gv } | Should Not Throw
}
It "Should be able to call using the Name switch" {
New-Variable -Name var1 -Value 4
New-Variable -Name var1 -Value 4
{ Get-Variable -Name var1 } | Should Not Throw
{ Get-Variable -Name var1 } | Should Not Throw
(Get-Variable -Name var1).Value | Should Be 4
(Get-Variable -Name var1).Value | Should Be 4
Remove-Variable var1
Remove-Variable var1
}
It "Should be able to use wildcard characters in the Name field" {
New-Variable -Name var1 -Value 4
New-Variable -Name var2 -Value "test"
New-Variable -Name var1 -Value 4
New-Variable -Name var2 -Value "test"
(Get-Variable -Name var*).Value[0] | Should be 4
(Get-Variable -Name var*).Value[1] | Should be "test"
(Get-Variable -Name var*).Value[0] | Should be 4
(Get-Variable -Name var*).Value[1] | Should be "test"
Remove-Variable var1
Remove-Variable var2
Remove-Variable var1
Remove-Variable var2
}
It "Should return only the value if the value switch is used" {
New-Variable -Name var1 -Value 4
New-Variable -Name var1 -Value 4
Get-Variable -Name var1 -ValueOnly | Should be 4
Get-Variable -Name var1 -ValueOnly | Should be 4
Remove-Variable var1
Remove-Variable var1
}
It "Should pipe string to the name field without the Name field being specified"{
New-Variable -Name var1 -Value 3
New-Variable -Name var1 -Value 3
("var1" | Get-Variable ).Value | Should Be 3
("var1" | Get-Variable ).Value | Should Be 3
Remove-Variable var1
Remove-Variable var1
}
It "Should be able to include a set of variables to get" {
New-Variable -Name var1 -Value 4
New-Variable -Name var2 -Value 2
New-Variable -Name var1 -Value 4
New-Variable -Name var2 -Value 2
$actual = Get-Variable -Include var1, var2
$actual = Get-Variable -Include var1, var2
$actual[0].Name | Should Be var1
$actual[1].Name | Should Be var2
$actual[0].Name | Should Be var1
$actual[1].Name | Should Be var2
$actual[0].Value | Should Be 4
$actual[1].Value | Should Be 2
$actual[0].Value | Should Be 4
$actual[1].Value | Should Be 2
Remove-Variable var1
Remove-Variable var2
Remove-Variable var1
Remove-Variable var2
}
It "Should be able to exclude a set of variables to get" {
New-Variable -Name var1 -Value 4
New-Variable -Name var2 -Value 2
New-Variable -Name var3 -Value "test"
New-Variable -Name var1 -Value 4
New-Variable -Name var2 -Value 2
New-Variable -Name var3 -Value "test"
$actual = Get-Variable -Exclude var1, var2
$actual = Get-Variable -Exclude var1, var2
$actual | Where-Object { $_.Name -eq "var3" } | Should Not BeNullOrEmpty
$actual | Where-Object { $_.Name -eq "var3" } | Should Not BeNullOrEmpty
}
Context "Scope Tests" {
# This will violate the DRY principle. Tread softly.
It "Should be able to get a global scope variable using the global switch" {
New-Variable globalVar -Value 1 -Scope global -Force
Context "Scope Tests" {
# This will violate the DRY principle. Tread softly.
It "Should be able to get a global scope variable using the global switch" {
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)[0].Value | Should Be 1
}
It "Should not be able to clear a global scope variable using the local switch" {
New-Variable globalVar -Value 1 -Scope global -Force
It "Should not be able to clear a global scope variable using the local switch" {
New-Variable globalVar -Value 1 -Scope global -Force
Get-Variable -Name globalVar -Scope local -ErrorAction SilentlyContinue | Should Throw
}
Get-Variable -Name globalVar -Scope local -ErrorAction SilentlyContinue | Should Throw
}
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 2 -Scope script -Force }
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 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" {
{
New-Variable localVar -Value 1 -Scope local -Force
It "Should be able to get an item locally using the local switch" {
{
New-Variable localVar -Value 1 -Scope local -Force
Get-Variable -Name localVar -Scope local
} | Should Not Throw
}
Get-Variable -Name localVar -Scope local
} | Should Not Throw
}
It "Should be able to get a variable created in the global scope when there's one in local scope" {
New-Variable localVar -Value 1 -Scope local -Force
It "Should be able to get a variable created in the global scope when there's one in local scope" {
New-Variable localVar -Value 1 -Scope local -Force
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" {
{
New-Variable scriptVar -Value 1 -Scope script -Force
It "Should be able to get a script variable created using the script switch" {
{
New-Variable scriptVar -Value 1 -Scope script -Force
Get-Variable -Name scriptVar -Scope script
} | Should Not Throw
}
Get-Variable -Name scriptVar -Scope script
} | Should Not Throw
}
It "Should be able to clear a global script variable that was created using the script scope switch" {
{
New-Variable scriptVar -Value 1 -Scope script -Force
It "Should be able to clear a global script variable that was created using the script scope switch" {
{
New-Variable scriptVar -Value 1 -Scope script -Force
Get-Variable -Name scriptVar -Scope script
} | Should Not Throw
}
Get-Variable -Name scriptVar -Scope script
} | Should Not Throw
}
}
}
+29 -29
View File
@@ -2,86 +2,86 @@ Describe "Group-Object" {
$testObject = Get-ChildItem
It "Should be called using an object as piped without error with no switches" {
{$testObject | Group-Object } | Should Not Throw
{$testObject | Group-Object } | Should Not Throw
}
It "Should be called using the InputObject without error with no other switches" {
{ Group-Object -InputObject $testObject } | Should Not Throw
{ Group-Object -InputObject $testObject } | Should Not Throw
}
It "Should return three columns- count, name, and group" {
$actual = Group-Object -InputObject $testObject
$actual = Group-Object -InputObject $testObject
$actual.Count | Should BeGreaterThan 0
$actual.Name.Count | Should BeGreaterThan 0
$actual.Group.Count | Should BeGreaterThan 0
$actual.Count | Should BeGreaterThan 0
$actual.Name.Count | Should BeGreaterThan 0
$actual.Group.Count | Should BeGreaterThan 0
}
It "Should use the group alias" {
{ group -InputObject $testObject } | Should Not Throw
{ group -InputObject $testObject } | Should Not Throw
}
It "Should create a collection when the inputObject parameter is used" {
$actualParam = Group-Object -InputObject $testObject
$actualParam = Group-Object -InputObject $testObject
$actualParam.Group.GetType().Name | Should Be "Collection``1"
$actualParam.Group.GetType().Name | Should Be "Collection``1"
}
It "Should output an array when piped input is used" {
$actual = $testObject | Group-Object
$actual = $testObject | Group-Object
$actual.Group.GetType().BaseType | Should Be Array
$actual.Group.GetType().BaseType | Should Be Array
}
It "Should have the same output between the group alias and the group-object cmdlet" {
$actualAlias = group -InputObject $testObject
$actualCmdlet = Group-Object -InputObject $testObject
$actualAlias = group -InputObject $testObject
$actualCmdlet = Group-Object -InputObject $testObject
$actualAlias.Name[0] | Should Be $actualCmdlet.Name[0]
$actualAlias.Group[0] | Should Be $actualCmdlet.Group[0]
$actualAlias.Name[0] | Should Be $actualCmdlet.Name[0]
$actualAlias.Group[0] | Should Be $actualCmdlet.Group[0]
}
It "Should be able to use the property switch without error" {
{ $testObject | Group-Object -Property Attributes } | Should Not Throw
{ $testObject | Group-Object -Property Attributes } | Should Not Throw
$actual = $testObject | Group-Object -Property Attributes
$actual = $testObject | Group-Object -Property Attributes
$actual.Group.Count | Should BeGreaterThan 0
$actual.Group.Count | Should BeGreaterThan 0
}
It "Should be able to use the property switch on multiple properties without error" {
{ $testObject | Group-Object -Property Attributes, Length }
{ $testObject | Group-Object -Property Attributes, Length }
$actual = $testObject | Group-Object -Property Attributes, Length
$actual = $testObject | Group-Object -Property Attributes, Length
$actual.Group.Count | Should BeGreaterThan 0
$actual.Group.Count | Should BeGreaterThan 0
}
It "Should be able to omit members of a group using the NoElement switch without error" {
{ $testObject | Group-Object -NoElement } | Should Not Throw
{ $testObject | Group-Object -NoElement } | Should Not Throw
($testObject | Group-Object -NoElement).Group | Should BeNullOrEmpty
($testObject | Group-Object -NoElement).Group | Should BeNullOrEmpty
}
It "Should be able to output a hashtable datatype" {
$actual = $testObject | Group-Object -AsHashTable
$actual = $testObject | Group-Object -AsHashTable
$actual.GetType().Name | Should be "Hashtable"
$actual.GetType().Name | Should be "Hashtable"
}
It "Should be able to access when output as hash table" {
$actual = $testObject | Group-Object -AsHashTable
$actual = $testObject | Group-Object -AsHashTable
$actual.Keys | Should Not BeNullOrEmpty
$actual.Keys | Should Not BeNullOrEmpty
}
It "Should throw when attempting to use AsString without AsHashTable" {
{ $testObject | Group-Object -AsString } | Should Throw
{ $testObject | Group-Object -AsString } | Should Throw
}
It "Should not throw error when using AsString when the AsHashTable was added" {
{ $testObject | Group-Object -AsHashTable -AsString } | Should Not Throw
{ $testObject | Group-Object -AsHashTable -AsString } | Should Not Throw
}
}
+7 -7
View File
@@ -1,6 +1,6 @@
Describe "Import-Alias" {
$pesteraliasfile = Join-Path -Path (Join-Path $PSScriptRoot -ChildPath assets) -ChildPath pesteralias.txt
Context "Validate ability to import alias file" {
It "Should be able to import an alias file successfully" {
@@ -8,18 +8,18 @@ Describe "Import-Alias" {
}
It "Should be able to import file via the Import-Alias alias of ipal" {
{ ipal $pesteraliasfile } | Should Not throw
}
{ ipal $pesteraliasfile } | Should Not throw
}
It "Should be able to import an alias file and perform imported aliased echo cmd" {
It "Should be able to import an alias file and perform imported aliased echo cmd" {
(Import-Alias $pesteraliasfile)
(pesterecho pestertesting) | Should Be "pestertesting"
}
It "Should be able to use ipal alias to import an alias file and perform cmd" {
(ipal $pesteraliasfile)
It "Should be able to use ipal alias to import an alias file and perform cmd" {
(ipal $pesteraliasfile)
(pesterecho pestertesting) | Should be "pestertesting"
}
}
}
+27 -27
View File
@@ -2,50 +2,50 @@ Describe "Import-Csv" {
$testCsv = Join-Path -Path (Join-Path $PSScriptRoot -ChildPath assets) -ChildPath TestCsv.csv
It "Should be able to call without error" {
{ Import-Csv $testCsv } | Should Not Throw
{ Import-Csv $testCsv } | Should Not Throw
}
It "Should be able to assign to a variable" {
$actual = Import-Csv $testCsv
$actual = Import-Csv $testCsv
$actual | Should Not BeNullOrEmpty
$actual.GetType().BaseType | Should Be array
$actual | Should Not BeNullOrEmpty
$actual.GetType().BaseType | Should Be array
}
It "Should have the data from the csv file" {
$actualContent = $(Get-Content $testCsv)[0]
$testContent = $($(Import-Csv $testCsv) | Get-Member) | ? { $_.MemberType -eq "NoteProperty" } | % { $_.Name } | Select-Object -First 1
$actualContent = $(Get-Content $testCsv)[0]
$testContent = $($(Import-Csv $testCsv) | Get-Member) | ? { $_.MemberType -eq "NoteProperty" } | % { $_.Name } | Select-Object -First 1
$actualContent.IndexOf($testContent) | Should BeGreaterThan -1
$actualContent.IndexOf($testContent) | Should BeGreaterThan -1
}
It "Should be able to prepend a custom header" {
$header = "test1","test2","test3"
$header = "test1","test2","test3"
$originalContent = $($(Import-Csv $testCsv) | Get-Member) | ? { $_.MemberType -eq "NoteProperty" } | % { $_.Name } | Select-Object -First 1
$originalContent = $($(Import-Csv $testCsv) | Get-Member) | ? { $_.MemberType -eq "NoteProperty" } | % { $_.Name } | Select-Object -First 1
$testContent = $($(Import-Csv $testCsv -Header $header) | Get-Member) | ? { $_.MemberType -eq "NoteProperty" } | % { $_.Name } | Select-Object -First 3
$testContent = $($(Import-Csv $testCsv -Header $header) | Get-Member) | ? { $_.MemberType -eq "NoteProperty" } | % { $_.Name } | Select-Object -First 3
# the original csv file doesn't contain the headers
$originalContent.IndexOf($header[0]) | Should Be -1
# the original csv file doesn't contain the headers
$originalContent.IndexOf($header[0]) | Should Be -1
# but it does with the -Header switch!
$testContent[0] | Should Be $header[0]
$testContent[1] | Should Be $header[1]
$testContent[2] | Should Be $header[2]
}
# but it does with the -Header switch!
$testContent[0] | Should Be $header[0]
$testContent[1] | Should Be $header[1]
$testContent[2] | Should Be $header[2]
}
It "Should be able to use the alias without error" {
{ Import-Csv $testCsv } | Should Not Throw
}
It "Should be able to use the alias without error" {
{ Import-Csv $testCsv } | Should Not Throw
}
It "Should have the same output between the alias and the full cmdlet name" {
$alias = $($(ipcsv $testCsv) | Get-Member) | ? { $_.MemberType -eq "NoteProperty" } | % { $_.Name } | Select-Object -First 1
$cmdlet = $($(Import-Csv $testCsv) | Get-Member) | ? { $_.MemberType -eq "NoteProperty" } | % { $_.Name } | Select-Object -First 1
It "Should have the same output between the alias and the full cmdlet name" {
$alias = $($(ipcsv $testCsv) | Get-Member) | ? { $_.MemberType -eq "NoteProperty" } | % { $_.Name } | Select-Object -First 1
$cmdlet = $($(Import-Csv $testCsv) | Get-Member) | ? { $_.MemberType -eq "NoteProperty" } | % { $_.Name } | Select-Object -First 1
$alias[0] | Should Be $cmdlet[0]
$alias[1] | Should Be $cmdlet[1]
$alias[2] | Should Be $cmdlet[2]
$alias[0] | Should Be $cmdlet[0]
$alias[1] | Should Be $cmdlet[1]
$alias[2] | Should Be $cmdlet[2]
}
}
}
+21 -21
View File
@@ -3,33 +3,33 @@ $assetsDir = Join-Path -Path $PSScriptRoot -ChildPath assets
Describe "Import-LocalizedData" {
BeforeAll {
$script = "localized.ps1"
$sunday = "Sunday"
$sundayInGerman = $sunday + " (in German)"
$script = "localized.ps1"
$sunday = "Sunday"
$sundayInGerman = $sunday + " (in German)"
}
It "Should be able to import string using default culture" {
# Set-Culture is broken, but let's verify that default culture is en-US
$culture = Get-Culture
$culture.Name | Should Be "en-US"
# Set-Culture is broken, but let's verify that default culture is en-US
$culture = Get-Culture
$culture.Name | Should Be "en-US"
$d = Import-LocalizedData -FileName $script -BaseDirectory $assetsDir
$d.d0 | Should be $sunday
}
$d = Import-LocalizedData -FileName $script -BaseDirectory $assetsDir
$d.d0 | Should be $sunday
}
It "Should be able to import string using en-US culture" {
$d = Import-LocalizedData -FileName $script -BaseDirectory $assetsDir -UICulture en-US
$d.d0 | Should be $sunday
}
It "Should be able to import string using en-US culture" {
$d = Import-LocalizedData -FileName $script -BaseDirectory $assetsDir -UICulture en-US
$d.d0 | Should be $sunday
}
It "Should be able to import string using de-DE culture" {
$d = Import-LocalizedData -FileName $script -BaseDirectory $assetsDir -UICulture de-DE
$d.d0 | Should be $sundayInGerman
}
It "Should be able to import string using de-DE culture" {
$d = Import-LocalizedData -FileName $script -BaseDirectory $assetsDir -UICulture de-DE
$d.d0 | Should be $sundayInGerman
}
It "Should be able to import string and store in binding variable" {
Import-LocalizedData -FileName $script -BaseDirectory $assetsDir -UICulture de-DE -BindingVariable d
$d.d0 | Should be $sundayInGerman
}
It "Should be able to import string and store in binding variable" {
Import-LocalizedData -FileName $script -BaseDirectory $assetsDir -UICulture de-DE -BindingVariable d
$d.d0 | Should be $sundayInGerman
}
}
+21 -21
View File
@@ -1,29 +1,29 @@
Describe "Invoke-Expression" {
Context "Should execute the invoked command validly" {
It "Should return the echoed text" {
(Invoke-Expression -command "echo pestertest1") | Should be "pestertest1"
}
It "Should return the echoed text" {
(Invoke-Expression -command "echo pestertest1") | Should be "pestertest1"
}
It "Should return the echoed text for the alias" {
(iex -command "echo pestertest2") | Should Be "pestertest2"
}
It "Should return the echoed text for the alias" {
(iex -command "echo pestertest2") | Should Be "pestertest2"
}
It "Should return the echoed text from a script" {
$testfile = Join-Path -Path (Join-Path $PSScriptRoot -ChildPath assets) -ChildPath echoscript.ps1
$testcommand = "echo pestertestscript"
$testcommand | Add-Content -Path $testfile
(Invoke-Expression $testfile) | Should Be "pestertestscript"
Remove-Item $testfile
}
It "Should return the echoed text from a script" {
$testfile = Join-Path -Path (Join-Path $PSScriptRoot -ChildPath assets) -ChildPath echoscript.ps1
$testcommand = "echo pestertestscript"
$testcommand | Add-Content -Path $testfile
(Invoke-Expression $testfile) | Should Be "pestertestscript"
Remove-Item $testfile
}
It "Should return the echoed text from a script from the alias" {
$testfile = Join-Path -Path (Join-Path $PSScriptRoot -ChildPath assets) -ChildPath echoscript.ps1
$testcommand = "echo pestertestscript"
$testcommand | Add-Content -Path $testfile
(iex $testfile) | Should Be "pestertestscript"
Remove-Item $testfile
}
It "Should return the echoed text from a script from the alias" {
$testfile = Join-Path -Path (Join-Path $PSScriptRoot -ChildPath assets) -ChildPath echoscript.ps1
$testcommand = "echo pestertestscript"
$testcommand | Add-Content -Path $testfile
(iex $testfile) | Should Be "pestertestscript"
Remove-Item $testfile
}
}
}
+11 -11
View File
@@ -7,41 +7,41 @@
Describe "Json.NET LINQ Parsing" {
# load third party Json.NET library
if ([string]::IsNullOrEmpty($env:CORE_ROOT)) {
$base = [System.AppContext]::BaseDirectory
$base = [System.AppContext]::BaseDirectory
} else {
$base = $env:CORE_ROOT
$base = $env:CORE_ROOT
}
$path = Join-Path $base Newtonsoft.Json.dll
[Microsoft.PowerShell.CoreCLR.AssemblyExtensions]::LoadFrom($path)
BeforeEach {
$jsonFile = Join-Path -Path (Join-Path $PSScriptRoot -ChildPath assets) -ChildPath TestJson.json
$jsonData = (Get-Content $jsonFile | Out-String)
$json = [Newtonsoft.Json.Linq.JObject]::Parse($jsonData)
$jsonFile = Join-Path -Path (Join-Path $PSScriptRoot -ChildPath assets) -ChildPath TestJson.json
$jsonData = (Get-Content $jsonFile | Out-String)
$json = [Newtonsoft.Json.Linq.JObject]::Parse($jsonData)
}
It "Should return data via Item()" {
[string]$json.Item("Name") | Should Be "Zaphod Beeblebrox"
[string]$json.Item("Name") | Should Be "Zaphod Beeblebrox"
}
It "Should return data via []" {
[string]$json["Planet"] | Should Be "Betelgeuse"
[string]$json["Planet"] | Should Be "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 Be "One hoopy frood"
}
}
+14 -14
View File
@@ -2,25 +2,25 @@ Describe "Measure-Command" {
Context "Validate return types for Measure-Command" {
It "Should return TimeSpan as the return type" {
(Measure-Command { Get-Date }).GetType() | Should Be timespan
}
It "Should return TimeSpan as the return type" {
(Measure-Command { Get-Date }).GetType() | Should Be timespan
}
}
Context "Validate that it is executing commands correctly" {
It "Should return TimeSpan after executing a script" {
(Measure-Command { echo hi }).GetType() | Should Be timespan
}
It "Should return TimeSpan after executing a script" {
(Measure-Command { echo hi }).GetType() | Should Be timespan
}
It "Should return TimeSpan after executing a cmdlet" {
$pesterscript = Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath echoscript.ps1
$testfile = $pesterscript
$testcommand = "echo pestertestscript"
$testcommand | Add-Content -Path $testfile
It "Should return TimeSpan after executing a cmdlet" {
$pesterscript = Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath echoscript.ps1
$testfile = $pesterscript
$testcommand = "echo pestertestscript"
$testcommand | Add-Content -Path $testfile
(Measure-Command { $pesterscript }).GetType() | Should Be timespan
Remove-Item $testfile
}
(Measure-Command { $pesterscript }).GetType() | Should Be timespan
Remove-Item $testfile
}
}
}
+99 -99
View File
@@ -2,153 +2,153 @@ Describe "Measure-Object" {
$testObject = 1,3,4
It "Should be able to be called without error" {
{ Measure-Object | Out-Null } | Should Not Throw
{ Measure-Object | Out-Null } | Should Not Throw
}
It "Should be able to call on piped input" {
{ $testObject | Measure-Object } | Should Not Throw
{ $testObject | Measure-Object } | Should Not Throw
}
It "Should be able to count the number of objects input to it" {
$($testObject | Measure-Object).Count | Should Be $testObject.Length
$($testObject | Measure-Object).Count | Should Be $testObject.Length
}
It "Should be able to count using the Property switch" {
$expected = $(Get-ChildItem).Length
$actual = $(Get-ChildItem | Measure-Object -Property Length).Count
$expected = $(Get-ChildItem).Length
$actual = $(Get-ChildItem | Measure-Object -Property Length).Count
$actual | Should Be $expected
$actual | Should Be $expected
}
It "Should be able to get additional stats" {
$actual = Get-Process | Measure-Object -Property workingset64 -Minimum -Maximum -Average
$actual = Get-Process | Measure-Object -Property workingset64 -Minimum -Maximum -Average
$actual.Average | Should BeGreaterThan 0
$actual.Characters | Should BeNullOrEmpty
$actual.Lines | Should BeNullOrEmpty
$actual.Maximum | Should Not BeNullOrEmpty
$actual.Minimum | Should Not BeNullOrEmpty
$actual.Sum | Should BeNullOrEmpty
$actual.Average | Should BeGreaterThan 0
$actual.Characters | Should BeNullOrEmpty
$actual.Lines | Should BeNullOrEmpty
$actual.Maximum | Should Not BeNullOrEmpty
$actual.Minimum | Should Not BeNullOrEmpty
$actual.Sum | Should BeNullOrEmpty
}
Context "Numeric tests" {
It "Should be able to sum" {
$actual = $testObject | Measure-Object -Sum
$expected = 0
It "Should be able to sum" {
$actual = $testObject | Measure-Object -Sum
$expected = 0
foreach ( $obj in $testObject )
{
$expected += $obj
}
foreach ( $obj in $testObject )
{
$expected += $obj
}
$actual.Sum | Should Be $expected
}
$actual.Sum | Should Be $expected
}
It "Should be able to average" {
$actual = $testObject | Measure-Object -Average
$expected = 0
It "Should be able to average" {
$actual = $testObject | Measure-Object -Average
$expected = 0
foreach ( $obj in $testObject )
{
$expected += $obj
}
foreach ( $obj in $testObject )
{
$expected += $obj
}
$expected /= $testObject.length
$expected /= $testObject.length
$actual.Average | Should Be $expected
}
$actual.Average | Should Be $expected
}
It "Should be able to return a minimum" {
$actual = $testObject | Measure-Object -Minimum
$expected = $testObject[0]
It "Should be able to return a minimum" {
$actual = $testObject | Measure-Object -Minimum
$expected = $testObject[0]
for ($i=0; $i -lt $testObject.length; $i++)
{
if ( $testObject[$i] -lt $expected )
{
for ($i=0; $i -lt $testObject.length; $i++)
{
if ( $testObject[$i] -lt $expected )
{
$expected = $testObject[$i]
}
}
$expected = $testObject[$i]
}
}
$actual.Minimum | Should Be $expected
}
$actual.Minimum | Should Be $expected
}
It "Should be able to return a minimum when multiple objects are the minimum" {
$testMinimum = 1,1,2,4
$actual = $testMinimum | Measure-Object -Minimum
$expected = $testMinimum[0]
It "Should be able to return a minimum when multiple objects are the minimum" {
$testMinimum = 1,1,2,4
$actual = $testMinimum | Measure-Object -Minimum
$expected = $testMinimum[0]
for ($i=1; $i -lt $testMinimum.length; $i++)
{
if ( $testMinimum[$i] -lt $expected )
{
for ($i=1; $i -lt $testMinimum.length; $i++)
{
if ( $testMinimum[$i] -lt $expected )
{
$expected = $testMinimum[$i]
}
}
$expected = $testMinimum[$i]
}
}
$actual.Minimum | Should Be $expected
}
$actual.Minimum | Should Be $expected
}
It "Should be able to return a maximum" {
$actual = $testObject | Measure-Object -Maximum
$expected = $testObject[0]
It "Should be able to return a maximum" {
$actual = $testObject | Measure-Object -Maximum
$expected = $testObject[0]
for ($i=1; $i -lt $testObject.length; $i++)
{
if ( $testObject[$i] -gt $expected )
{
for ($i=1; $i -lt $testObject.length; $i++)
{
if ( $testObject[$i] -gt $expected )
{
$expected = $testObject[$i]
}
}
$expected = $testObject[$i]
}
}
$actual.Maximum | Should Be $expected
}
$actual.Maximum | Should Be $expected
}
It "Should be able to return a maximum when multiple objects are the maximum" {
$testMaximum = 1,3,5,5
$actual = $testMaximum | Measure-Object -Maximum
$expected = $testMaximum[0]
It "Should be able to return a maximum when multiple objects are the maximum" {
$testMaximum = 1,3,5,5
$actual = $testMaximum | Measure-Object -Maximum
$expected = $testMaximum[0]
for ($i=1; $i -lt $testMaximum.length; $i++)
{
if ( $testMaximum[$i] -gt $expected )
{
for ($i=1; $i -lt $testMaximum.length; $i++)
{
if ( $testMaximum[$i] -gt $expected )
{
$expected = $testMaximum[$i]
}
}
$expected = $testMaximum[$i]
}
}
$actual.Maximum | Should Be $expected
}
$actual.Maximum | Should Be $expected
}
}
Context "String tests" {
$nl = [Environment]::NewLine
$nl = [Environment]::NewLine
$testString = "HAD I the heavens' embroidered cloths,$nl Enwrought with golden and silver light,$nl The blue and the dim and the dark cloths$nl Of night and light and the half light,$nl I would spread the cloths under your feet:$nl But I, being poor, have only my dreams;$nl I have spread my dreams under your feet;$nl Tread softly because you tread on my dreams."
$testString = "HAD I the heavens' embroidered cloths,$nl Enwrought with golden and silver light,$nl The blue and the dim and the dark cloths$nl Of night and light and the half light,$nl I would spread the cloths under your feet:$nl But I, being poor, have only my dreams;$nl I have spread my dreams under your feet;$nl Tread softly because you tread on my dreams."
It "Should be able to count the number of words in a string" {
$expectedLength = $testString.Replace($nl,"").Split().length
$actualLength = $testString | Measure-Object -Word
It "Should be able to count the number of words in a string" {
$expectedLength = $testString.Replace($nl,"").Split().length
$actualLength = $testString | Measure-Object -Word
$actualLength.Words | Should Be $expectedLength
}
$actualLength.Words | Should Be $expectedLength
}
It "Should be able to count the number of characters in a string" {
$expectedLength = $testString.length
$actualLength = $testString | Measure-Object -Character
It "Should be able to count the number of characters in a string" {
$expectedLength = $testString.length
$actualLength = $testString | Measure-Object -Character
$actualLength.Characters | Should Be $expectedLength
}
$actualLength.Characters | Should Be $expectedLength
}
It "Should be able to count the number of lines in a string" {
$expectedLength = $testString.Split($nl, [System.StringSplitOptions]::RemoveEmptyEntries).length
$actualLength = $testString | Measure-Object -Line
It "Should be able to count the number of lines in a string" {
$expectedLength = $testString.Split($nl, [System.StringSplitOptions]::RemoveEmptyEntries).length
$actualLength = $testString | Measure-Object -Line
$actualLength.Lines | Should Be $expectedLength
}
$actualLength.Lines | Should Be $expectedLength
}
}
}
+18 -18
View File
@@ -1,34 +1,34 @@
Describe "New-Alias" {
It "Should be able to be called using the name and value parameters without error" {
{ New-Alias -Name testAlias -Value 100 } | Should Not Throw
{ New-Alias -Name testAlias -Value 100 } | Should Not Throw
}
It "Should have the same output between the alias and the original cmdlet" {
New-Alias -Name testAlias -Value Get-Process
New-Alias -Name testAlias -Value Get-Process
$aliasId = $(testAlias).Id
$cmdletId = $(Get-Process).Id
foreach ($IdNumber in $aliasId)
{
$aliasId[$IdNumber] | Should Be $cmdletId[$IdNumber]
}
$aliasId = $(testAlias).Id
$cmdletId = $(Get-Process).Id
foreach ($IdNumber in $aliasId)
{
$aliasId[$IdNumber] | Should Be $cmdletId[$IdNumber]
}
}
It "Should be able to call the New-Alias cmdlet using the nal alias without error" {
{ nal -Name testAlias -Value 100 } | Should Not Throw
{ nal -Name testAlias -Value 100 } | Should Not Throw
}
It "Should have the same output between the nal alias and the New-Alias cmdlet" {
nal -Name testAlias -Value Get-Process
New-Alias -Name testalias2 -Value Get-Process
nal -Name testAlias -Value Get-Process
$aliasData = $(testAlias).Id
$cmdletData = $(testAlias2).Id
New-Alias -Name testalias2 -Value Get-Process
foreach ($IdNumber in $aliasData)
{
$aliasData[$IdNumber] | Should Be $cmdletData[$IdNumber]
}
$aliasData = $(testAlias).Id
$cmdletData = $(testAlias2).Id
foreach ($IdNumber in $aliasData)
{
$aliasData[$IdNumber] | Should Be $cmdletData[$IdNumber]
}
}
}
+6 -6
View File
@@ -1,9 +1,9 @@
Describe "New-Event" {
Context "Check return type of New-Event" {
It "Should return PSEventArgs as return type of New-Event" {
(New-Event -SourceIdentifier a).GetType() | Should Be System.Management.Automation.PSEventArgs
It "Should return PSEventArgs as return type of New-Event" {
(New-Event -SourceIdentifier a).GetType() | Should Be System.Management.Automation.PSEventArgs
}
}
@@ -14,9 +14,9 @@ Describe "New-Event" {
Remove-Event -sourceidentifier PesterTimer
}
It "Should return Sender as Windows.timer" {
(New-Event -sourceidentifier PesterTimer -sender Windows.timer -messagedata "PesterTestMessage")
(Get-Event -SourceIdentifier PesterTimer).Sender | Should be Windows.timer
It "Should return Sender as Windows.timer" {
(New-Event -sourceidentifier PesterTimer -sender Windows.timer -messagedata "PesterTestMessage")
(Get-Event -SourceIdentifier PesterTimer).Sender | Should be Windows.timer
Remove-Event -sourceIdentifier PesterTimer
}
}
+41 -41
View File
@@ -2,17 +2,17 @@ function Clean-State
{
if (Test-Path $FullyQualifiedLink)
{
Remove-Item $FullyQualifiedLink -Force
Remove-Item $FullyQualifiedLink -Force
}
if (Test-Path $FullyQualifiedFile)
{
Remove-Item $FullyQualifiedFile -Force
Remove-Item $FullyQualifiedFile -Force
}
if (Test-Path $FullyQualifiedFolder)
{
Remove-Item $FullyQualifiedFolder -Force
Remove-Item $FullyQualifiedFolder -Force
}
}
@@ -26,96 +26,96 @@ Describe "New-Item" {
$FullyQualifiedLink = Join-Path -Path $tmpDirectory -ChildPath $testlink
BeforeEach {
Clean-State
Clean-State
}
It "should call the function without error" {
{ New-Item -Name $testfile -Path $tmpDirectory -ItemType file } | Should Not Throw
{ New-Item -Name $testfile -Path $tmpDirectory -ItemType file } | Should Not Throw
}
It "Should create a file without error" {
New-Item -Name $testfile -Path $tmpDirectory -ItemType file
New-Item -Name $testfile -Path $tmpDirectory -ItemType file
Test-Path $FullyQualifiedFile | Should Be $true
Test-Path $FullyQualifiedFile | Should Be $true
}
It "Should create a folder without an error" {
New-Item -Name newDirectory -Path $tmpDirectory -ItemType directory
New-Item -Name newDirectory -Path $tmpDirectory -ItemType directory
Test-Path $FullyQualifiedFolder | Should Be $true
Test-Path $FullyQualifiedFolder | Should Be $true
}
It "Should create a file using the ni alias" {
ni -Name $testfile -Path $tmpDirectory -ItemType file
ni -Name $testfile -Path $tmpDirectory -ItemType file
Test-Path $FullyQualifiedFile | Should Be $true
Test-Path $FullyQualifiedFile | Should Be $true
}
It "Should create a file using the Type alias instead of ItemType" {
New-Item -Name $testfile -Path $tmpDirectory -Type file
New-Item -Name $testfile -Path $tmpDirectory -Type file
Test-Path $FullyQualifiedFile | Should Be $true
Test-Path $FullyQualifiedFile | Should Be $true
}
It "Should create a file with sample text inside the file using the Value switch" {
$expected = "This is test string"
New-Item -Name $testfile -Path $tmpDirectory -ItemType file -Value $expected
$expected = "This is test string"
New-Item -Name $testfile -Path $tmpDirectory -ItemType file -Value $expected
Test-Path $FullyQualifiedFile | Should Be $true
Test-Path $FullyQualifiedFile | Should Be $true
Get-Content $FullyQualifiedFile | Should Be $expected
Get-Content $FullyQualifiedFile | Should Be $expected
}
It "Should not create a file when the Name switch is not used and only a directory specified" {
#errorAction used because permissions issue in Windows
New-Item -Path $tmpDirectory -ItemType file -ErrorAction SilentlyContinue
#errorAction used because permissions issue in Windows
New-Item -Path $tmpDirectory -ItemType file -ErrorAction SilentlyContinue
Test-Path $FullyQualifiedFile | Should Be $false
Test-Path $FullyQualifiedFile | Should Be $false
}
It "Should create a file when the Name switch is not used but a fully qualified path is specified" {
New-Item -Path $FullyQualifiedFile -ItemType file
New-Item -Path $FullyQualifiedFile -ItemType file
Test-Path $FullyQualifiedFile | Should Be $true
Test-Path $FullyQualifiedFile | Should Be $true
}
It "Should be able to create a multiple items in different directories" {
$FullyQualifiedFile2 = Join-Path -Path $tmpDirectory -ChildPath test2.txt
New-Item -ItemType file -Path $FullyQualifiedFile, $FullyQualifiedFile2
$FullyQualifiedFile2 = Join-Path -Path $tmpDirectory -ChildPath test2.txt
New-Item -ItemType file -Path $FullyQualifiedFile, $FullyQualifiedFile2
Test-Path $FullyQualifiedFile | Should Be $true
Test-Path $FullyQualifiedFile2 | Should Be $true
Test-Path $FullyQualifiedFile | Should Be $true
Test-Path $FullyQualifiedFile2 | Should Be $true
Remove-Item $FullyQualifiedFile2
Remove-Item $FullyQualifiedFile2
}
It "Should be able to call the whatif switch without error" {
{ New-Item -Name testfile.txt -Path $tmpDirectory -ItemType file -WhatIf } | Should Not Throw
{ New-Item -Name testfile.txt -Path $tmpDirectory -ItemType file -WhatIf } | Should Not Throw
}
It "Should not create a new file when the whatif switch is used" {
New-Item -Name $testfile -Path $tmpDirectory -ItemType file -WhatIf
It "Should not create a new file when the whatif switch is used" {
New-Item -Name $testfile -Path $tmpDirectory -ItemType file -WhatIf
Test-Path $FullyQualifiedFile | Should Be $false
Test-Path $FullyQualifiedFile | Should Be $false
}
It "Should create a symbolic link of a file without error" -Skip:$IsWindows {
New-Item -Name $testfile -Path $tmpDirectory -ItemType file
Test-Path $FullyQualifiedFile | Should Be $true
New-Item -Name $testfile -Path $tmpDirectory -ItemType file
Test-Path $FullyQualifiedFile | Should Be $true
New-Item -ItemType SymbolicLink -Target $FullyQualifiedFile -Name $testlink -Path $tmpDirectory
Test-Path $FullyQualifiedLink | Should Be $true
New-Item -ItemType SymbolicLink -Target $FullyQualifiedFile -Name $testlink -Path $tmpDirectory
Test-Path $FullyQualifiedLink | Should Be $true
}
It "Should create a symbolic link from directory without error" -Skip:$IsWindows {
New-Item -Name $testFolder -Path $tmpDirectory -ItemType directory
Test-Path $FullyQualifiedFolder | Should Be $true
New-Item -Name $testFolder -Path $tmpDirectory -ItemType directory
Test-Path $FullyQualifiedFolder | Should Be $true
New-Item -ItemType SymbolicLink -Target $FullyQualifiedFolder -Name $testlink -Path $tmpDirectory
Test-Path $FullyQualifiedLink | Should Be $true
New-Item -ItemType SymbolicLink -Target $FullyQualifiedFolder -Name $testlink -Path $tmpDirectory
Test-Path $FullyQualifiedLink | Should Be $true
# Remove the link explicitly to avoid broken symlink issue
Remove-Item $FullyQualifiedLink -Force
# Remove the link explicitly to avoid broken symlink issue
Remove-Item $FullyQualifiedLink -Force
}
}
+10 -10
View File
@@ -1,16 +1,16 @@
Describe "New-Object" {
It "should create an object with 4 fields" {
$o = New-Object psobject
$val = $o.GetType()
$o = New-Object psobject
$val = $o.GetType()
$val.IsPublic | Should Not BeNullOrEmpty
$val.Name | Should Not BeNullOrEmpty
$val.IsSerializable | Should Not BeNullOrEmpty
$val.BaseType | Should Not BeNullOrEmpty
$val.IsPublic | Should Not BeNullOrEmpty
$val.Name | Should Not BeNullOrEmpty
$val.IsSerializable | Should Not BeNullOrEmpty
$val.BaseType | Should Not BeNullOrEmpty
$val.IsPublic | Should Be $true
$val.IsSerializable | Should Be $false
$val.Name | Should Be 'PSCustomObject'
$val.BaseType | Should Be 'System.Object'
$val.IsPublic | Should Be $true
$val.IsSerializable | Should Be $false
$val.Name | Should Be 'PSCustomObject'
$val.BaseType | Should Be 'System.Object'
}
}
+30 -30
View File
@@ -1,46 +1,46 @@
Describe "New-TimeSpan" {
It "Should be able to create a new timespan object" {
New-Variable -Name testObject -Value $(New-TimeSpan)
New-Variable -Name testObject -Value $(New-TimeSpan)
$testObject.GetType() | Should Be timespan
$testObject.GetType() | Should Be timespan
}
Context "Core Functionality Tests" {
New-Variable -Name testObject -Value $(New-TimeSpan -Days 2 -Hours 23 -Minutes 4 -Seconds 3) -Force
New-Variable -Name testObject -Value $(New-TimeSpan -Days 2 -Hours 23 -Minutes 4 -Seconds 3) -Force
$expectedOutput = @{ "Days" = "2";
"Hours" = "23";
"Minutes" = "4";
"Seconds" = "3";
"Milliseconds" = "0";
"Ticks" = "2558430000000";
"TotalDays" = "2.96114583333333";
"TotalHours" = "71.0675";
"TotalMinutes" = "4264.05";
"TotalSeconds" = "255843";
"TotalMilliseconds" = "255843000"
}
$expectedOutput = @{ "Days" = "2";
"Hours" = "23";
"Minutes" = "4";
"Seconds" = "3";
"Milliseconds" = "0";
"Ticks" = "2558430000000";
"TotalDays" = "2.96114583333333";
"TotalHours" = "71.0675";
"TotalMinutes" = "4264.05";
"TotalSeconds" = "255843";
"TotalMilliseconds" = "255843000"
}
$TEN_MILLION = 10000000
$TEN_MILLION = 10000000
It "Should have expected values for time properties set during creation" {
$testObject.Days | Should Be $expectedOutput["Days"]
$testObject.Hours | Should Be $expectedOutput["Hours"]
$testObject.Minutes | Should Be $expectedOutput["Minutes"]
$testObject.Seconds | Should Be $expectedOutput["Seconds"]
$testObject.Ticks | Should Be $expectedOutput["Ticks"]
}
It "Should have expected values for time properties set during creation" {
$testObject.Days | Should Be $expectedOutput["Days"]
$testObject.Hours | Should Be $expectedOutput["Hours"]
$testObject.Minutes | Should Be $expectedOutput["Minutes"]
$testObject.Seconds | Should Be $expectedOutput["Seconds"]
$testObject.Ticks | Should Be $expectedOutput["Ticks"]
}
}
It "Should have matching output when using the Start switch vs piping from another cmdlet" {
# this file is guaranteed to exist
$inputObject = (Get-ChildItem $PSScriptRoot/New-TimeSpan.Tests.ps1)
$inputParameter = New-TimeSpan -Start $inputObject.lastwritetime
$pipedInput = $inputObject | New-TimeSpan
# this file is guaranteed to exist
$inputObject = (Get-ChildItem $PSScriptRoot/New-TimeSpan.Tests.ps1)
$inputParameter = New-TimeSpan -Start $inputObject.lastwritetime
$pipedInput = $inputObject | New-TimeSpan
$difference = [math]::Abs($inputParameter.Milliseconds - $pipedInput.Milliseconds)
# The difference between commands should be minimal
$difference | Should BeLessThan 100
$difference = [math]::Abs($inputParameter.Milliseconds - $pipedInput.Milliseconds)
# The difference between commands should be minimal
$difference | Should BeLessThan 100
}
}
+98 -98
View File
@@ -2,184 +2,184 @@ Describe "New-Variable" {
$nl = [Environment]::NewLine
It "Should create a new variable with no parameters" {
{ New-Variable var1 } | Should Not Throw
{ New-Variable var1 } | Should Not Throw
}
It "Should be able to set variable name using the Name parameter" {
{ New-Variable -Name var1 } | Should Not Throw
{ New-Variable -Name var1 } | Should Not Throw
}
It "Should be able to assign a value to a variable using the value switch" {
New-Variable var1 -Value 4
New-Variable var1 -Value 4
$var1 | Should Be 4
$var1 | Should Be 4
}
It "Should be able to assign a value to a new variable without using the value switch" {
New-Variable var1 "test"
New-Variable var1 "test"
$var1 | Should Be "test"
$var1 | Should Be "test"
}
It "Should assign a description to a new variable using the description switch" {
New-Variable var1 100 -Description "Test Description"
New-Variable var1 100 -Description "Test Description"
(Get-Variable var1).Description | Should Be "Test Description"
(Get-Variable var1).Description | Should Be "Test Description"
}
It "Should be able to be called with the nv alias" {
{ nv var1 } | Should Not Throw
{ nv var1 2 } | Should Not Throw
{ nv var1 } | Should Not Throw
{ nv var1 2 } | Should Not Throw
}
It "Should not be able to set the name of a new variable to that of an old variable within same scope when the Force switch is missing" {
New-Variable var1
(New-Variable var1 -ErrorAction SilentlyContinue) | Should Throw
New-Variable var1
(New-Variable var1 -ErrorAction SilentlyContinue) | Should Throw
}
It "Should change the value of an already existing variable using the Force switch" {
New-Variable var1 -Value 1
New-Variable var1 -Value 1
$var1 | Should Be 1
$var1 | Should Be 1
New-Variable var1 -Value 2 -Force
New-Variable var1 -Value 2 -Force
$var1 | Should Be 2
$var1 | Should Not Be 1
$var1 | Should Be 2
$var1 | Should Not Be 1
}
It "Should be able to set the value of a variable by piped input" {
$in = "value"
$in = "value"
$in | New-Variable -Name var1
$in | New-Variable -Name var1
$var1 | Should Be $in
$var1 | Should Be $in
}
It "Should be able to pipe object properties to output using the PassThru switch" {
$in = Set-Variable -Name testVar -Value "test" -Description "test description" -PassThru
$in = Set-Variable -Name testVar -Value "test" -Description "test description" -PassThru
$output = $in | Format-List -Property Description | Out-String
$output = $in | Format-List -Property Description | Out-String
$output | Should Be "${nl}${nl}Description : test description${nl}${nl}${nl}${nl}"
$output | Should Be "${nl}${nl}Description : test description${nl}${nl}${nl}${nl}"
}
It "Should be able to set the value using the value switch" {
New-Variable -Name var1 -Value 2
New-Variable -Name var1 -Value 2
$var1 | Should Be 2
$var1 | Should Be 2
}
Context "Option tests" {
BeforeEach {
# verify that the test variable doesn't exist
!!$var1 | Should Be $false
}
It "Should be able to use the options switch without error" {
{ New-Variable -Name var1 -Value 2 -Option Unspecified } | Should Not Throw
}
BeforeEach {
# verify that the test variable doesn't exist
!!$var1 | Should Be $false
}
It "Should be able to use the options switch without error" {
{ New-Variable -Name var1 -Value 2 -Option Unspecified } | Should Not Throw
}
It "Should default to none as the value for options" {
New-Variable -Name var2 -Value 4 -PassThru| Format-List | Out-String | Should Match "Options : None"
}
It "Should default to none as the value for options" {
New-Variable -Name var2 -Value 4 -PassThru| Format-List | Out-String | Should Match "Options : None"
}
It "Should be able to set ReadOnly option" {
{ New-Variable -Name var1 -Value 2 -Option ReadOnly } | Should Not Throw
}
It "Should be able to set ReadOnly option" {
{ New-Variable -Name var1 -Value 2 -Option ReadOnly } | Should Not Throw
}
It "Should not be able to change variable created using the ReadOnly option when the Force switch is not used" {
New-Variable -Name var1 -Value 1 -Option ReadOnly
It "Should not be able to change variable created using the ReadOnly option when the Force switch is not used" {
New-Variable -Name var1 -Value 1 -Option ReadOnly
Set-Variable -Name var1 -Value 2 -ErrorAction SilentlyContinue
Set-Variable -Name var1 -Value 2 -ErrorAction SilentlyContinue
$var1 | Should Not Be 2
}
$var1 | Should Not Be 2
}
It "Should be able to set a new variable to constant" {
{ New-Variable -Name var1 -Option Constant } | Should Not Throw
}
It "Should be able to set a new variable to constant" {
{ New-Variable -Name var1 -Option Constant } | Should Not Throw
}
It "Should not be able to change an existing variable to constant" {
New-Variable -Name var1 -Value 1 -PassThru
It "Should not be able to change an existing variable to constant" {
New-Variable -Name var1 -Value 1 -PassThru
Set-Variable -Name var1 -Option Constant -ErrorAction SilentlyContinue
Set-Variable -Name var1 -Option Constant -ErrorAction SilentlyContinue
$var1 | Format-List | Out-String | Should Not Match "Options : None"
$var1 | Format-List | Out-String | Should Not Match "Options : None"
}
}
It "Should not be able to delete a constant variable" {
New-Variable -Name var1 -Value 2 -Option Constant
It "Should not be able to delete a constant variable" {
New-Variable -Name var1 -Value 2 -Option Constant
Remove-Variable -Name var1 -ErrorAction SilentlyContinue
Remove-Variable -Name var1 -ErrorAction SilentlyContinue
!!$var1 | Should Be $true
!!$var1 | Should Be $true
$var1 | Should Be 2
}
$var1 | Should Be 2
}
It "Should not be able to change a constant variable" {
New-Variable -Name var1 -Value 1 -Option Constant
It "Should not be able to change a constant variable" {
New-Variable -Name var1 -Value 1 -Option Constant
Set-Variable -Name var1 -Value 2 -ErrorAction SilentlyContinue
Set-Variable -Name var1 -Value 2 -ErrorAction SilentlyContinue
$var1 | Should Not Be 2
}
$var1 | Should Not Be 2
}
It "Should be able to create a variable as private without error" {
{ New-Variable -Name var1 -Option Private } | Should Not Throw
}
It "Should be able to create a variable as private without error" {
{ New-Variable -Name var1 -Option Private } | Should Not Throw
}
It "Should be able to see the value of a private variable when within scope" {
It "Should be able to see the value of a private variable when within scope" {
New-Variable -Name var1 -Value 100 -Option Private
New-Variable -Name var1 -Value 100 -Option Private
$var1 | Should Be 100
$var1 | Should Be 100
}
}
It "Should not be able to see the value of a private variable when out of scope" {
{
New-Variable -Name var1 -Value 1 -Option Private
}
It "Should not be able to see the value of a private variable when out of scope" {
{
New-Variable -Name var1 -Value 1 -Option Private
}
$var1 | Should Be # Nothing, since it's not defined in scope
$var1 | Should Be # Nothing, since it's not defined in scope
}
}
It "Should be able to use the AllScope switch without error" {
{ New-Variable -Name var1 -Option AllScope } | Should Not Throw
}
It "Should be able to use the AllScope switch without error" {
{ New-Variable -Name var1 -Option AllScope } | Should Not Throw
}
It "Should be able to see variable created using the AllScope switch in a child scope" {
New-Variable -Name var1 -Value 1 -Option AllScope
function myFunction {
if ( $var1 -eq 1 ) {
$var1 = 2
}
}
myFunction
It "Should be able to see variable created using the AllScope switch in a child scope" {
New-Variable -Name var1 -Value 1 -Option AllScope
function myFunction {
if ( $var1 -eq 1 ) {
$var1 = 2
}
}
myFunction
$var1 | Should Be 2
$var1 | Should Be 2
}
}
}
Context "Scope Tests" {
It "Should be able to create a global scope variable using the global switch" {
{ New-Variable globalVar -Value 1 -Scope global -Force } | Should Not Throw
}
Context "Scope Tests" {
It "Should be able to create a global scope variable using the global switch" {
{ New-Variable globalVar -Value 1 -Scope global -Force } | Should Not Throw
}
It "Should be able to create a local scope variable using the local switch" {
{ New-Variable localVar -Value 1 -Scope local -Force } | Should Not Throw
}
It "Should be able to create a local scope variable using the local switch" {
{ New-Variable localVar -Value 1 -Scope local -Force } | Should Not Throw
}
It "Should be able to create a script scope variable using the script switch" {
{ New-Variable scriptVar -Value 1 -Scope script -Force } | Should Not Throw
}
It "Should be able to create a script scope variable using the script switch" {
{ New-Variable scriptVar -Value 1 -Scope script -Force } | Should Not Throw
}
}
}
+59 -59
View File
@@ -4,108 +4,108 @@ Describe "Out-File" {
$testfile = Join-Path -Path $TestDrive -ChildPath outfileTest.txt
AfterEach {
Remove-Item -Path $testfile -Force
Remove-Item -Path $testfile -Force
}
It "Should be able to be called without error" {
{ Out-File -FilePath $testfile } | Should Not Throw
{ Out-File -FilePath $testfile } | Should Not Throw
}
It "Should be able to accept string input via piping" {
{ $expectedContent | Out-File -FilePath $testfile } | Should Not Throw
{ $expectedContent | Out-File -FilePath $testfile } | Should Not Throw
$actual = Get-Content $testfile
$actual = Get-Content $testfile
$actual | Should Be $expectedContent
$actual | Should Be $expectedContent
}
It "Should be able to accept string input via the InputObject swictch" {
{ Out-File -FilePath $testfile -InputObject $expectedContent } | Should Not Throw
{ Out-File -FilePath $testfile -InputObject $expectedContent } | Should Not Throw
$actual = Get-Content $testfile
$actual = Get-Content $testfile
$actual | Should Be $expectedContent
$actual | Should Be $expectedContent
}
It "Should be able to accept object input" {
{ $inObject | Out-File -FilePath $testfile } | Should Not Throw
{ $inObject | Out-File -FilePath $testfile } | Should Not Throw
{ Out-File -FilePath $testfile -InputObject $inObject } | Should Not Throw
{ Out-File -FilePath $testfile -InputObject $inObject } | Should Not Throw
}
It "Should not overwrite when the noclobber switch is used" {
Out-File -FilePath $testfile -InputObject $inObject
Out-File -FilePath $testfile -InputObject $inObject
{ Out-File -FilePath $testfile -InputObject $inObject -NoClobber -ErrorAction SilentlyContinue } | Should Throw "already exists."
{ Out-File -FilePath $testfile -InputObject $inObject -NoOverWrite -ErrorAction SilentlyContinue } | Should Throw "already exists."
{ Out-File -FilePath $testfile -InputObject $inObject -NoClobber -ErrorAction SilentlyContinue } | Should Throw "already exists."
{ Out-File -FilePath $testfile -InputObject $inObject -NoOverWrite -ErrorAction SilentlyContinue } | Should Throw "already exists."
$actual = Get-Content $testfile
$actual = Get-Content $testfile
$actual[0] | Should Be ""
$actual[1] | Should Match "text"
$actual[2] | Should Match "----"
$actual[3] | Should Match "some test text"
$actual[0] | Should Be ""
$actual[1] | Should Match "text"
$actual[2] | Should Match "----"
$actual[3] | Should Match "some test text"
}
It "Should Append a new line when the append switch is used" {
{ Out-File -FilePath $testfile -InputObject $inObject } | Should Not Throw
{ Out-File -FilePath $testfile -InputObject $inObject -Append } | Should Not Throw
{ Out-File -FilePath $testfile -InputObject $inObject } | Should Not Throw
{ Out-File -FilePath $testfile -InputObject $inObject -Append } | Should Not Throw
$actual = Get-Content $testfile
$actual = Get-Content $testfile
$actual[0] | Should Be ""
$actual[1] | Should Match "text"
$actual[2] | Should Match "----"
$actual[3] | Should Match "some test text"
$actual[4] | Should Be ""
$actual[5] | Should Be ""
$actual[6] | Should Be ""
$actual[7] | Should Match "text"
$actual[8] | Should Match "----"
$actual[9] | Should Match "some test text"
$actual[10] | Should Be ""
$actual[11] | Should Be ""
$actual[0] | Should Be ""
$actual[1] | Should Match "text"
$actual[2] | Should Match "----"
$actual[3] | Should Match "some test text"
$actual[4] | Should Be ""
$actual[5] | Should Be ""
$actual[6] | Should Be ""
$actual[7] | Should Match "text"
$actual[8] | Should Match "----"
$actual[9] | Should Match "some test text"
$actual[10] | Should Be ""
$actual[11] | Should Be ""
}
It "Should limit each line to the specified number of characters when the width switch is used on objects" {
Out-File -FilePath $testfile -Width 10 -InputObject $inObject
Out-File -FilePath $testfile -Width 10 -InputObject $inObject
$actual = Get-Content $testfile
$actual = Get-Content $testfile
$actual[0] | Should Be ""
$actual[1] | Should Be "text "
$actual[2] | Should Be "---- "
$actual[3] | Should Be "some te..."
$actual[0] | Should Be ""
$actual[1] | Should Be "text "
$actual[2] | Should Be "---- "
$actual[3] | Should Be "some te..."
}
It "Should allow the cmdlet to overwrite an existing read-only file" {
# create a read-only text file
{ Out-File -FilePath $testfile -InputObject $inObject } | Should Not Throw
Set-ItemProperty -Path $testfile -Name IsReadOnly -Value $true
# create a read-only text file
{ Out-File -FilePath $testfile -InputObject $inObject } | Should Not Throw
Set-ItemProperty -Path $testfile -Name IsReadOnly -Value $true
# write information to the RO file
{ Out-File -FilePath $testfile -InputObject $inObject -Append -Force } | Should Not Throw
# write information to the RO file
{ Out-File -FilePath $testfile -InputObject $inObject -Append -Force } | Should Not Throw
$actual = Get-Content $testfile
$actual = Get-Content $testfile
$actual[0] | Should Be ""
$actual[1] | Should Match "text"
$actual[2] | Should Match "----"
$actual[3] | Should Match "some test text"
$actual[4] | Should Be ""
$actual[5] | Should Be ""
$actual[6] | Should Be ""
$actual[7] | Should Match "text"
$actual[8] | Should Match "----"
$actual[9] | Should Match "some test text"
$actual[10] | Should Be ""
$actual[11] | Should Be ""
$actual[0] | Should Be ""
$actual[1] | Should Match "text"
$actual[2] | Should Match "----"
$actual[3] | Should Match "some test text"
$actual[4] | Should Be ""
$actual[5] | Should Be ""
$actual[6] | Should Be ""
$actual[7] | Should Match "text"
$actual[8] | Should Match "----"
$actual[9] | Should Match "some test text"
$actual[10] | Should Be ""
$actual[11] | Should Be ""
# reset to not read only so it can be deleted
Set-ItemProperty -Path $testfile -Name IsReadOnly -Value $false
# reset to not read only so it can be deleted
Set-ItemProperty -Path $testfile -Name IsReadOnly -Value $false
}
}
+15 -15
View File
@@ -2,36 +2,36 @@ Describe "Out-String" {
$nl = [Environment]::NewLine
It "Should accumulate the strings and returns them as a single string" {
$testArray = "a", " b"
$testArray = "a", " b"
$testArray.GetType().BaseType | Should Be array
$testArray.GetType().BaseType | Should Be array
$testArray | Out-String | Should Be "a$nl b$nl"
$testArray | Out-String | Should Be "a$nl b$nl"
$($testArray | Out-String).GetType() | Should Be string
$($testArray | Out-String).GetType() | Should Be string
}
It "Should be able to return an array of strings using the stream switch" {
$testInput = "a", "b"
$testInput = "a", "b"
$($testInput | Out-String).GetType() | Should Be string
$($testInput | Out-String).GetType() | Should Be string
$($testInput | Out-String -Stream).GetType().BaseType.Name | Should Be array
$($testInput | Out-String -Stream).GetType().BaseType.Name | Should Be array
}
It "Should send all objects through a pipeline when not using the stream switch" {
$testInput = "a", "b"
$streamoutputlength = $($testInput | Out-String -Stream).Length
$nonstreamoutputlength = $($testInput | Out-String).Length
$testInput = "a", "b"
$streamoutputlength = $($testInput | Out-String -Stream).Length
$nonstreamoutputlength = $($testInput | Out-String).Length
$nonstreamoutputlength| Should BeGreaterThan $streamoutputlength
$nonstreamoutputlength| Should BeGreaterThan $streamoutputlength
}
It "Should send a single object through a pipeline when the stream switch is used" {
$testInput = "a", "b"
$streamoutputlength = $($testInput | Out-String -Stream).Length
$nonstreamoutputlength = $($testInput | Out-String).Length
$testInput = "a", "b"
$streamoutputlength = $($testInput | Out-String -Stream).Length
$nonstreamoutputlength = $($testInput | Out-String).Length
$streamoutputlength | Should BeLessThan $nonstreamoutputlength
$streamoutputlength | Should BeLessThan $nonstreamoutputlength
}
}
+18 -18
View File
@@ -1,30 +1,30 @@
Describe "PSVersionTable" {
It "Should have version table entries" {
$PSVersionTable.Count | Should Be 8
$PSVersionTable.Count | Should Be 8
}
It "Should have the right version table entries" {
$PSVersionTable.ContainsKey("PSVersion") | Should Be True
$PSVersionTable.ContainsKey("PSEdition") | Should Be True
$PSVersionTable.ContainsKey("WSManStackVersion") | Should Be True
$PSVersionTable.ContainsKey("SerializationVersion") | Should Be True
$PSVersionTable.ContainsKey("CLRVersion") | Should Be True
$PSVersionTable.ContainsKey("BuildVersion") | Should Be True
$PSVersionTable.ContainsKey("PSCompatibleVersions") | Should Be True
$PSVersionTable.ContainsKey("PSRemotingProtocolVersion") | Should Be True
$PSVersionTable.ContainsKey("PSVersion") | Should Be True
$PSVersionTable.ContainsKey("PSEdition") | Should Be True
$PSVersionTable.ContainsKey("WSManStackVersion") | Should Be True
$PSVersionTable.ContainsKey("SerializationVersion") | Should Be True
$PSVersionTable.ContainsKey("CLRVersion") | Should Be True
$PSVersionTable.ContainsKey("BuildVersion") | Should Be True
$PSVersionTable.ContainsKey("PSCompatibleVersions") | Should Be True
$PSVersionTable.ContainsKey("PSRemotingProtocolVersion") | Should Be True
}
It "Should have the correct edition" -Skip:(!$IsCore) {
$expected =
if ($IsLinux -Or $IsOSX) {
"Linux"
} elseif ($IsWindows) {
"Core"
} else {
throw [PlatformNotSupportedException]
}
$expected =
if ($IsLinux -Or $IsOSX) {
"Linux"
} elseif ($IsWindows) {
"Core"
} else {
throw [PlatformNotSupportedException]
}
$PSVersionTable["PSEdition"] | Should Be $expected
$PSVersionTable["PSEdition"] | Should Be $expected
}
}
+9 -9
View File
@@ -4,23 +4,23 @@ Describe "Pop-Location" {
BeforeEach { Set-Location $startDirectory }
It "Should be able to be called without error" {
{ Pop-Location } | Should Not Throw
{ Pop-Location } | Should Not Throw
}
It "Should not take a parameter" {
{ Pop-Location .. } | Should Throw
{ Pop-Location .. } | Should Throw
}
It "Should be able pop multiple times" {
Push-Location ..
Push-Location ..
Push-Location ..
Push-Location ..
Push-Location ..
Push-Location ..
Pop-Location
Pop-Location
Pop-Location
Pop-Location
Pop-Location
Pop-Location
$(Get-Location).Path | Should Be $startDirectory
$(Get-Location).Path | Should Be $startDirectory
}
+17 -17
View File
@@ -4,50 +4,50 @@ Describe "Test-Push-Location" {
BeforeEach { cd $startDirectory }
It "Should be called without error" {
{ Push-Location } | Should Not Throw
{ Push-Location } | Should Not Throw
}
It "Should be able to push to the root directory" {
# this works cross-platform
{ Push-Location / } | Should Not Throw
# this works cross-platform
{ Push-Location / } | Should Not Throw
}
It "Should be able to use relative path to parent" {
{ Push-Location .. } | Should Not Throw
{ Push-Location .. } | Should Not Throw
}
It "Should be able to use relative path to grandparent" {
Test-Path ../.. | Should Be $true
Test-Path ../.. | Should Be $true
{ Push-Location ../.. } | Should Not Throw
{ Push-Location ../.. } | Should Not Throw
}
It "Should be able to push twice" {
{ Push-Location .. } | Should Not Throw
{ Push-Location .. } | Should Not Throw
{ Push-Location .. } | Should Not Throw
{ Push-Location .. } | Should Not Throw
}
It "Should be able to take a piped variable" {
{ ".." | Push-Location } | Should Not Throw
{ ".." | Push-Location } | Should Not Throw
}
It "Should be able to call the pushd alias" {
{ pushd } | Should Not Throw
{ pushd } | Should Not Throw
}
It "Should be able to push to the same location between the alias and the cmdlet" {
pushd ..
$aliasDirectory = $(Get-Location).Path
pushd ..
$aliasDirectory = $(Get-Location).Path
cd $startDirectory
Push-Location ..
$cmdletDirectory = $(Get-Location).Path
cd $startDirectory
Push-Location ..
$cmdletDirectory = $(Get-Location).Path
$aliasDirectory | Should Be $cmdletDirectory
$aliasDirectory | Should Be $cmdletDirectory
}
It "Should produce a pathinfo object when the passthru parameter is used" {
Push-Location .. -PassThru | ForEach-Object { $_.GetType().Name | Should Be PathInfo }
Push-Location .. -PassThru | ForEach-Object { $_.GetType().Name | Should Be PathInfo }
}
# final cleanup
@@ -1,9 +1,9 @@
Describe "Register-EngineEvent" {
Context "Check return type of Register-ObjectEvent" {
It "Should return System.Management.Automation.PSEventJob as return type of Register-EngineEvent" {
( Register-EngineEvent -SourceIdentifier PesterTestRegister -Action {echo registerengineevent} ).GetType() | Should Be System.Management.Automation.PSEventJob
Unregister-Event -sourceidentifier PesterTestRegister
Context "Check return type of Register-ObjectEvent" {
It "Should return System.Management.Automation.PSEventJob as return type of Register-EngineEvent" {
( Register-EngineEvent -SourceIdentifier PesterTestRegister -Action {echo registerengineevent} ).GetType() | Should Be System.Management.Automation.PSEventJob
Unregister-Event -sourceidentifier PesterTestRegister
}
}
}
@@ -1,16 +1,16 @@
Describe "Register-ObjectEvent" {
BeforeEach {
$pesterobject = (New-Object System.Collections.ObjectModel.ObservableCollection[object])
}
AfterEach {
Unregister-Event -SourceIdentifier PesterTestRegister -ErrorAction SilentlyContinue
}
$pesterobject = (New-Object System.Collections.ObjectModel.ObservableCollection[object])
}
AfterEach {
Unregister-Event -SourceIdentifier PesterTestRegister -ErrorAction SilentlyContinue
}
Context "Check return type of Register-ObjectEvent" {
It "Should return System.Management.Automation.PSEventSubscriber as return type of New-Event with the registered sourceidentifier" {
It "Should return System.Management.Automation.PSEventSubscriber as return type of New-Event with the registered sourceidentifier" {
Register-ObjectEvent -InputObject $pesterobject -EventName CollectionChanged -SourceIdentifier PesterTestRegister
(Get-EventSubscriber -SourceIdentifier PesterTestRegister).GetType() | Should Be System.Management.Automation.PSEventSubscriber
}
@@ -22,7 +22,7 @@ Describe "Register-ObjectEvent" {
(Get-EventSubscriber -SourceIdentifier PesterTestRegister).SourceIdentifier | Should Be "PesterTestRegister"
}
It "Should return an integer greater than 0 for the SubscriptionId" {
It "Should return an integer greater than 0 for the SubscriptionId" {
Register-ObjectEvent -InputObject $pesterobject -EventName CollectionChanged -SourceIdentifier PesterTestRegister
(Get-EventSubscriber -SourceIdentifier PesterTestRegister).SubscriptionId | Should BeGreaterThan 0
+22 -22
View File
@@ -1,38 +1,38 @@
Describe "Remove-Event" {
BeforeEach {
New-Event -sourceidentifier PesterTimer -sender Windows.timer -messagedata "PesterTestMessage"
New-Event -sourceidentifier PesterTimer -sender Windows.timer -messagedata "PesterTestMessage"
}
AfterEach {
Remove-Event -sourceidentifier PesterTimer -ErrorAction SilentlyContinue
Remove-Event -sourceidentifier PesterTimer -ErrorAction SilentlyContinue
}
Context "Check Remove-Event can validly remove events" {
It "Should remove an event given a sourceidentifier" {
{ Remove-Event -sourceidentifier PesterTimer }
{ Get-Event -ErrorAction SilentlyContinue | Should Not Contain PesterTimer }
}
It "Should remove an event given a sourceidentifier" {
{ Remove-Event -sourceidentifier PesterTimer }
{ Get-Event -ErrorAction SilentlyContinue | Should Not Contain PesterTimer }
}
It "Should remove an event given an event identifier" {
{ $events = Get-Event -sourceidentifier PesterTimer }
{ $events = $events.EventIdentifier }
{ Remove-Event -EventIdentifier $events }
{ $events = Get-Event -ErrorAction SilentlyContinue}
{ $events.SourceIdentifier | Should Not Contain "PesterTimer" }
}
It "Should remove an event given an event identifier" {
{ $events = Get-Event -sourceidentifier PesterTimer }
{ $events = $events.EventIdentifier }
{ Remove-Event -EventIdentifier $events }
{ $events = Get-Event -ErrorAction SilentlyContinue}
{ $events.SourceIdentifier | Should Not Contain "PesterTimer" }
}
It "Should be able to remove an event given a pipe from Get-Event" {
{ Get-Event -sourceidentifier PesterTimer | Remove-Event }
{ Get-Event -ErrorAction SilentlyContinue | Should Not Contain "PesterTimer" }
It "Should be able to remove an event given a pipe from Get-Event" {
{ Get-Event -sourceidentifier PesterTimer | Remove-Event }
{ Get-Event -ErrorAction SilentlyContinue | Should Not Contain "PesterTimer" }
}
}
It "Should NOT remove an event given the whatif flag" {
{ Remove-Event -sourceidentifier PesterTimer -whatif }
{ $events = Get-Event }
{ $events.SourceIdentifier | Should Contain "PesterTimer" }
}
It "Should NOT remove an event given the whatif flag" {
{ Remove-Event -sourceidentifier PesterTimer -whatif }
{ $events = Get-Event }
{ $events.SourceIdentifier | Should Contain "PesterTimer" }
}
}
}
+93 -93
View File
@@ -3,137 +3,137 @@ Describe "Remove-Item" {
$testfile = "testfile.txt"
$testfilepath = Join-Path -Path $testpath -ChildPath $testfile
Context "File removal Tests" {
BeforeEach {
New-Item -Name $testfile -Path $testpath -ItemType "file" -Value "lorem ipsum" -Force
BeforeEach {
New-Item -Name $testfile -Path $testpath -ItemType "file" -Value "lorem ipsum" -Force
Test-Path $testfilepath | Should Be $true
Test-Path $testfilepath | Should Be $true
}
}
It "Should be able to be called on a regular file without error using the Path switch" {
{ Remove-Item -Path $testfilepath } | Should Not Throw
It "Should be able to be called on a regular file without error using the Path switch" {
{ Remove-Item -Path $testfilepath } | Should Not Throw
Test-Path $testfilepath | Should Be $false
}
Test-Path $testfilepath | Should Be $false
}
It "Should be able to be called on a file without the Path switch" {
{ Remove-Item $testfilepath } | Should Not Throw
It "Should be able to be called on a file without the Path switch" {
{ Remove-Item $testfilepath } | Should Not Throw
Test-Path $testfilepath | Should Be $false
}
Test-Path $testfilepath | Should Be $false
}
It "Should be able to call the rm alias" {
{ rm $testfilepath } | Should Not Throw
It "Should be able to call the rm alias" {
{ rm $testfilepath } | Should Not Throw
Test-Path $testfilepath | Should Be $false
}
Test-Path $testfilepath | Should Be $false
}
It "Should be able to call the del alias" {
{ del $testfilepath } | Should Not Throw
It "Should be able to call the del alias" {
{ del $testfilepath } | Should Not Throw
Test-Path $testfilepath | Should Be $false
}
Test-Path $testfilepath | Should Be $false
}
It "Should be able to call the erase alias" {
{ erase $testfilepath } | Should Not Throw
It "Should be able to call the erase alias" {
{ erase $testfilepath } | Should Not Throw
Test-Path $testfilepath | Should Be $false
}
Test-Path $testfilepath | Should Be $false
}
It "Should be able to call the ri alias" {
{ ri $testfilepath } | Should Not Throw
It "Should be able to call the ri alias" {
{ ri $testfilepath } | Should Not Throw
Test-Path $testfilepath | Should Be $false
}
Test-Path $testfilepath | Should Be $false
}
It "Should not be able to remove a read-only document without using the force switch" {
# Set to read only
Set-ItemProperty -Path $testfilepath -Name IsReadOnly -Value $true
It "Should not be able to remove a read-only document without using the force switch" {
# Set to read only
Set-ItemProperty -Path $testfilepath -Name IsReadOnly -Value $true
# attempt to remove the file
{ Remove-Item $testfilepath -ErrorAction SilentlyContinue } | Should Not Throw
# attempt to remove the file
{ Remove-Item $testfilepath -ErrorAction SilentlyContinue } | Should Not Throw
# validate
Test-Path $testfilepath | Should Be $true
# validate
Test-Path $testfilepath | Should Be $true
# remove using the -force switch on the readonly object
Remove-Item $testfilepath -Force
# remove using the -force switch on the readonly object
Remove-Item $testfilepath -Force
# Validate
Test-Path $testfilepath | Should Be $false
}
# Validate
Test-Path $testfilepath | Should Be $false
}
It "Should be able to remove all files matching a regular expression with the include switch" {
# Create multiple files with specific string
New-Item -Name file1.txt -Path $testpath -ItemType "file" -Value "lorem ipsum"
New-Item -Name file2.txt -Path $testpath -ItemType "file" -Value "lorem ipsum"
New-Item -Name file3.txt -Path $testpath -ItemType "file" -Value "lorem ipsum"
# Create a single file that does not match that string - already done in BeforeEach
It "Should be able to remove all files matching a regular expression with the include switch" {
# Create multiple files with specific string
New-Item -Name file1.txt -Path $testpath -ItemType "file" -Value "lorem ipsum"
New-Item -Name file2.txt -Path $testpath -ItemType "file" -Value "lorem ipsum"
New-Item -Name file3.txt -Path $testpath -ItemType "file" -Value "lorem ipsum"
# Create a single file that does not match that string - already done in BeforeEach
# Delete the specific string
Remove-Item (Join-Path -Path $testpath -ChildPath "*") -Include file*.txt
# validate that the string under test was deleted, and the nonmatching strings still exist
Test-path (Join-Path -Path $testpath -ChildPath file1.txt) | Should Be $false
Test-path (Join-Path -Path $testpath -ChildPath file2.txt) | Should Be $false
Test-path (Join-Path -Path $testpath -ChildPath file3.txt) | Should Be $false
Test-Path $testfilepath | Should Be $true
# Delete the specific string
Remove-Item (Join-Path -Path $testpath -ChildPath "*") -Include file*.txt
# validate that the string under test was deleted, and the nonmatching strings still exist
Test-path (Join-Path -Path $testpath -ChildPath file1.txt) | Should Be $false
Test-path (Join-Path -Path $testpath -ChildPath file2.txt) | Should Be $false
Test-path (Join-Path -Path $testpath -ChildPath file3.txt) | Should Be $false
Test-Path $testfilepath | Should Be $true
# Delete the non-matching strings
Remove-Item $testfilepath
# Delete the non-matching strings
Remove-Item $testfilepath
Test-Path $testfilepath | Should Be $false
}
Test-Path $testfilepath | Should Be $false
}
It "Should be able to not remove any files matching a regular expression with the exclude switch" {
# Create multiple files with specific string
New-Item -Name file1.wav -Path $testpath -ItemType "file" -Value "lorem ipsum"
New-Item -Name file2.wav -Path $testpath -ItemType "file" -Value "lorem ipsum"
It "Should be able to not remove any files matching a regular expression with the exclude switch" {
# Create multiple files with specific string
New-Item -Name file1.wav -Path $testpath -ItemType "file" -Value "lorem ipsum"
New-Item -Name file2.wav -Path $testpath -ItemType "file" -Value "lorem ipsum"
# Create a single file that does not match that string
New-Item -Name file1.txt -Path $testpath -ItemType "file" -Value "lorem ipsum"
# Create a single file that does not match that string
New-Item -Name file1.txt -Path $testpath -ItemType "file" -Value "lorem ipsum"
# Delete the specific string
Remove-Item (Join-Path -Path $testpath -ChildPath "file*") -Exclude *.wav -Include *.txt
# Delete the specific string
Remove-Item (Join-Path -Path $testpath -ChildPath "file*") -Exclude *.wav -Include *.txt
# validate that the string under test was deleted, and the nonmatching strings still exist
Test-Path (Join-Path -Path $testpath -ChildPath file1.wav) | Should Be $true
Test-Path (Join-Path -Path $testpath -ChildPath file2.wav) | Should Be $true
Test-Path (Join-Path -Path $testpath -ChildPath file1.txt) | Should Be $false
# validate that the string under test was deleted, and the nonmatching strings still exist
Test-Path (Join-Path -Path $testpath -ChildPath file1.wav) | Should Be $true
Test-Path (Join-Path -Path $testpath -ChildPath file2.wav) | Should Be $true
Test-Path (Join-Path -Path $testpath -ChildPath file1.txt) | Should Be $false
# Delete the non-matching strings
Remove-Item (Join-Path -Path $testpath -ChildPath file1.wav)
Remove-Item (Join-Path -Path $testpath -ChildPath file2.wav)
# Delete the non-matching strings
Remove-Item (Join-Path -Path $testpath -ChildPath file1.wav)
Remove-Item (Join-Path -Path $testpath -ChildPath file2.wav)
Test-Path (Join-Path -Path $testpath -ChildPath file1.wav) | Should Be $false
Test-Path (Join-Path -Path $testpath -ChildPath file2.wav) | Should Be $false
}
Test-Path (Join-Path -Path $testpath -ChildPath file1.wav) | Should Be $false
Test-Path (Join-Path -Path $testpath -ChildPath file2.wav) | Should Be $false
}
}
Context "Directory Removal Tests" {
$testdirectory = Join-Path -Path $testpath -ChildPath testdir
$testsubdirectory = Join-Path -Path $testdirectory -ChildPath subd
BeforeEach {
New-Item -Name "testdir" -Path $testpath -ItemType "directory" -Force
$testdirectory = Join-Path -Path $testpath -ChildPath testdir
$testsubdirectory = Join-Path -Path $testdirectory -ChildPath subd
BeforeEach {
New-Item -Name "testdir" -Path $testpath -ItemType "directory" -Force
Test-Path $testdirectory | Should Be $true
}
Test-Path $testdirectory | Should Be $true
}
It "Should be able to remove a directory" {
{ Remove-Item $testdirectory } | Should Not Throw
It "Should be able to remove a directory" {
{ Remove-Item $testdirectory } | Should Not Throw
Test-Path $testdirectory | Should Be $false
}
Test-Path $testdirectory | Should Be $false
}
It "Should be able to recursively delete subfolders" {
New-Item -Name "subd" -Path $testdirectory -ItemType "directory"
New-Item -Name $testfile -Path $testsubdirectory -ItemType "file" -Value "lorem ipsum"
It "Should be able to recursively delete subfolders" {
New-Item -Name "subd" -Path $testdirectory -ItemType "directory"
New-Item -Name $testfile -Path $testsubdirectory -ItemType "file" -Value "lorem ipsum"
$complexDirectory = Join-Path -Path $testsubdirectory -ChildPath $testfile
test-path $complexDirectory | Should Be $true
$complexDirectory = Join-Path -Path $testsubdirectory -ChildPath $testfile
test-path $complexDirectory | Should Be $true
{ Remove-Item $testdirectory -Recurse} | Should Not Throw
{ Remove-Item $testdirectory -Recurse} | Should Not Throw
Test-Path $testdirectory | Should Be $false
}
Test-Path $testdirectory | Should Be $false
}
}
}
+36 -36
View File
@@ -3,68 +3,68 @@ Describe "Remove-PSBreakpoint" {
$testScript = Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath psbreakpointtestscript.ps1
$script = "`$var = 1
`$var2 = Get-Process
`$var2 = Get-Process
# this is a comment
Get-Date
"
"
$script > $testScript
BeforeEach {
# set some breakpoints
$line = Set-PSBreakpoint -Line 1,2,3 -Script $testScript
$command = Set-PSBreakpoint -Command "Get-Date" -Script $testScript
$variable = Set-PSBreakpoint -Variable var2 -Script $testScript
# set some breakpoints
$line = Set-PSBreakpoint -Line 1,2,3 -Script $testScript
$command = Set-PSBreakpoint -Command "Get-Date" -Script $testScript
$variable = Set-PSBreakpoint -Variable var2 -Script $testScript
}
Context "Basic Removal Methods Tests" {
It "Should be able to remove a breakpoint by breakpoint Id" {
$NumberOfBreakpoints = $(Get-PSBreakpoint).Id.length
$BreakID = $(Get-PSBreakpoint).Id[0]
Remove-PSBreakpoint -Id $BreakID
It "Should be able to remove a breakpoint by breakpoint Id" {
$NumberOfBreakpoints = $(Get-PSBreakpoint).Id.length
$BreakID = $(Get-PSBreakpoint).Id[0]
Remove-PSBreakpoint -Id $BreakID
$(Get-PSBreakpoint).Id.length | Should Be ($NumberOfBreakpoints -1)
}
$(Get-PSBreakpoint).Id.length | Should Be ($NumberOfBreakpoints -1)
}
It "Should be able to remove a breakpoint by variable" {
$NumberOfBreakpoints = $(Get-PSBreakpoint).Id.length
Remove-PSBreakpoint -Breakpoint $variable
It "Should be able to remove a breakpoint by variable" {
$NumberOfBreakpoints = $(Get-PSBreakpoint).Id.length
Remove-PSBreakpoint -Breakpoint $variable
$(Get-PSBreakpoint).Id.length | Should Be ($NumberOfBreakpoints -1)
}
$(Get-PSBreakpoint).Id.length | Should Be ($NumberOfBreakpoints -1)
}
It "Should be able to remove a breakpoint by command" {
$NumberOfBreakpoints = $(Get-PSBreakpoint).Id.length
Remove-PSBreakpoint -Breakpoint $command
It "Should be able to remove a breakpoint by command" {
$NumberOfBreakpoints = $(Get-PSBreakpoint).Id.length
Remove-PSBreakpoint -Breakpoint $command
$(Get-PSBreakpoint).Id.length | Should Be ($NumberOfBreakpoints -1)
}
$(Get-PSBreakpoint).Id.length | Should Be ($NumberOfBreakpoints -1)
}
It "Should be able to pipe breakpoint objects to Remove-PSBreakpoint" {
$NumberOfBreakpoints = $(Get-PSBreakpoint).Id.length
$variable | Remove-PSBreakpoint
It "Should be able to pipe breakpoint objects to Remove-PSBreakpoint" {
$NumberOfBreakpoints = $(Get-PSBreakpoint).Id.length
$variable | Remove-PSBreakpoint
$(Get-PSBreakpoint).Id.length | Should Be ($NumberOfBreakpoints -1)
}
$(Get-PSBreakpoint).Id.length | Should Be ($NumberOfBreakpoints -1)
}
}
Context "Alias Tests" {
It "Should remove a breakpoint using the rbp alias" {
$NumberOfBreakpoints = $(Get-PSBreakpoint).Id.length
$BreakID = $(Get-PSBreakpoint).Id[0]
rbp -Id $BreakID
It "Should remove a breakpoint using the rbp alias" {
$NumberOfBreakpoints = $(Get-PSBreakpoint).Id.length
$BreakID = $(Get-PSBreakpoint).Id[0]
rbp -Id $BreakID
$(Get-PSBreakpoint).Id.length | Should Be ($NumberOfBreakpoints -1)
}
$(Get-PSBreakpoint).Id.length | Should Be ($NumberOfBreakpoints -1)
}
}
It "Should Remove all breakpoints" {
$(Get-PSBreakpoint).Id.Length | Should Not BeNullOrEmpty
$(Get-PSBreakpoint).Id.Length | Should Not BeNullOrEmpty
Get-PSBreakpoint | Remove-PSBreakpoint
Get-PSBreakpoint | Remove-PSBreakpoint
$(Get-PSBreakpoint).Id.Length | Should Be 0
$(Get-PSBreakpoint).Id.Length | Should Be 0
}
+104 -104
View File
@@ -3,191 +3,191 @@ Remove-Variable -Name var1 -ErrorAction SilentlyContinue -Force
Describe "Remove-Variable" {
It "Should throw an error when a dollar sign is used in the variable name place" {
New-Variable -Name var1 -Value 4
New-Variable -Name var1 -Value 4
Remove-Variable $var1 -ErrorAction SilentlyContinue | Should Throw
Remove-Variable $var1 -ErrorAction SilentlyContinue | Should Throw
}
It "Should not throw error when used without the Name field, and named variable is properly specified and exists" {
New-Variable -Name var1 -Value 4
New-Variable -Name var1 -Value 4
Remove-Variable var1
Remove-Variable var1
$var1 | Should Be #nothing. it should be Nothing at all.
$var1 | Should Be #nothing. it should be Nothing at all.
}
It "Should not throw error when used with the Name field, and named variable is specified and exists" {
New-Variable -Name var1 -Value 2
New-Variable -Name var1 -Value 2
Remove-Variable -Name var1
Remove-Variable -Name var1
$var1 | Should Be #nothing. it should be Nothing at all.
$var1 | Should Be #nothing. it should be Nothing at all.
}
It "Should throw error when used with Name field, and named variable does not exist" {
Remove-Variable -Name nonexistantVariable -ErrorAction SilentlyContinue | Should Throw
Remove-Variable -Name nonexistantVariable -ErrorAction SilentlyContinue | Should Throw
}
It "Should be able to remove a variable using the rv alias" {
New-Variable var1 -Value 2
New-Variable var1 -Value 2
$var1 | Should Be 2
$var1 | Should Be 2
rv -Name var1
rv -Name var1
$var1 | Should Be #nothing. it should be Nothing at all.
$var1 | Should Be #nothing. it should be Nothing at all.
}
It "Should be able to remove a set of variables using wildcard characters" {
New-Variable tmpvar1 -Value "tempvalue"
New-Variable tmpvar2 -Value 2
New-Variable tmpmyvar1 -Value 234
New-Variable tmpvar1 -Value "tempvalue"
New-Variable tmpvar2 -Value 2
New-Variable tmpmyvar1 -Value 234
$tmpvar1 | Should Be "tempvalue"
$tmpvar2 | Should Be 2
$tmpmyvar1 | Should Be 234
$tmpvar1 | Should Be "tempvalue"
$tmpvar2 | Should Be 2
$tmpmyvar1 | Should Be 234
Remove-Variable -Name tmp*
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 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.
}
It "Should be able to exclude a set of variables to remove using the Exclude switch" {
New-Variable tmpvar1 -Value "tempvalue"
New-Variable tmpvar2 -Value 2
New-Variable tmpmyvar1 -Value 234
New-Variable tmpvar1 -Value "tempvalue"
New-Variable tmpvar2 -Value 2
New-Variable tmpmyvar1 -Value 234
$tmpvar1 | Should Be "tempvalue"
$tmpvar2 | Should Be 2
$tmpmyvar1 | Should Be 234
$tmpvar1 | Should Be "tempvalue"
$tmpvar2 | Should Be 2
$tmpmyvar1 | Should Be 234
Remove-Variable -Name tmp* -Exclude *my*
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.
$tmpmyvar1 | Should Be 234
$tmpvar1 | Should Be #nothing. it should be Nothing at all.
$tmpvar2 | Should Be #nothing. it should be Nothing at all.
$tmpmyvar1 | Should Be 234
}
It "Should be able to include a set of variables to remove using the Include switch" {
New-Variable tmpvar1 -Value "tempvalue"
New-Variable tmpvar2 -Value 2
New-Variable tmpmyvar1 -Value 234
New-Variable thevar -Value 1
New-Variable tmpvar1 -Value "tempvalue"
New-Variable tmpvar2 -Value 2
New-Variable tmpmyvar1 -Value 234
New-Variable thevar -Value 1
$tmpvar1 | Should Be "tempvalue"
$tmpvar2 | Should Be 2
$tmpmyvar1 | Should Be 234
$thevar | Should Be 1
$tmpvar1 | Should Be "tempvalue"
$tmpvar2 | Should Be 2
$tmpmyvar1 | Should Be 234
$thevar | Should Be 1
Remove-Variable -Name tmp* -Include *my*
Remove-Variable -Name tmp* -Include *my*
$tmpvar1 | Should Be "tempvalue"
$tmpvar2 | Should Be 2
$tmpmyvar1 | Should Be #nothing. it should be Nothing at all.
$thevar | should Be 1
$tmpvar1 | Should Be "tempvalue"
$tmpvar2 | Should Be 2
$tmpmyvar1 | Should Be #nothing. it should be Nothing at all.
$thevar | should Be 1
Remove-Variable tmpvar1
Remove-Variable tmpvar2
Remove-Variable thevar
Remove-Variable tmpvar1
Remove-Variable tmpvar2
Remove-Variable thevar
}
It "Should throw an error when attempting to remove a read-only variable and the Force switch is not used" {
New-Variable -Name var1 -Value 2 -Option ReadOnly
New-Variable -Name var1 -Value 2 -Option ReadOnly
Remove-Variable -Name var1 -ErrorAction SilentlyContinue | Should Throw
Remove-Variable -Name var1 -ErrorAction SilentlyContinue | Should Throw
$var1 | Should Be 2
$var1 | Should Be 2
Remove-Variable -Name var1 -Force
Remove-Variable -Name var1 -Force
}
It "Should not throw an error when attempting to remove a read-only variable and the Force switch is used" {
New-Variable -Name var1 -Value 2 -Option ReadOnly
New-Variable -Name var1 -Value 2 -Option ReadOnly
Remove-Variable -Name var1 -Force
Remove-Variable -Name var1 -Force
$var1 | Should Be # Nothing. It should be nothing at all.
$var1 | Should Be # Nothing. It should be nothing at all.
}
Context "Scope Tests" {
It "Should be able to remove a global variable using the global switch" {
New-Variable -Name var1 -Value "context" -Scope global
It "Should be able to remove a global variable using the global switch" {
New-Variable -Name var1 -Value "context" -Scope global
Remove-Variable -Name var1 -Scope global
Remove-Variable -Name var1 -Scope global
$var1 | Should Be #Nothing.
}
$var1 | Should Be #Nothing.
}
It "Should not be able to clear a global variable using the local switch" {
New-Variable -Name var1 -Value "context" -Scope global
It "Should not be able to clear a global variable using the local switch" {
New-Variable -Name var1 -Value "context" -Scope global
Remove-Variable -Name var1 -Scope local -ErrorAction SilentlyContinue | Should Throw
Remove-Variable -Name var1 -Scope local -ErrorAction SilentlyContinue | Should Throw
$var1 | Should Be "context"
$var1 | Should Be "context"
Remove-Variable -Name var1 -Scope global
$var1 | Should Be # Nothing
}
Remove-Variable -Name var1 -Scope global
$var1 | Should Be # Nothing
}
It "Should not be able to clear a global variable using the script switch" {
New-Variable -Name var1 -Value "context" -Scope global
It "Should not be able to clear a global variable using the script switch" {
New-Variable -Name var1 -Value "context" -Scope global
Remove-Variable -Name var1 -Scope local -ErrorAction SilentlyContinue | Should Throw
Remove-Variable -Name var1 -Scope local -ErrorAction SilentlyContinue | Should Throw
$var1 | Should Be "context"
$var1 | Should Be "context"
Remove-Variable -Name var1 -Scope global
$var1 | Should Be # Nothing
}
Remove-Variable -Name var1 -Scope global
$var1 | Should Be # Nothing
}
It "Should be able to remove an item locally using the local switch" {
New-Variable -Name var1 -Value "context" -Scope local
It "Should be able to remove an item locally using the local switch" {
New-Variable -Name var1 -Value "context" -Scope local
Remove-Variable -Name var1 -Scope local -ErrorAction SilentlyContinue | Should Throw
Remove-Variable -Name var1 -Scope local -ErrorAction SilentlyContinue | Should Throw
$var1 | Should Be # Nothing
}
$var1 | Should Be # Nothing
}
It "Should be able to remove an item locally using the global switch" {
New-Variable -Name var1 -Value "context" -Scope local
It "Should be able to remove an item locally using the global switch" {
New-Variable -Name var1 -Value "context" -Scope local
Remove-Variable -Name var1 -Scope global -ErrorAction SilentlyContinue | Should Throw
Remove-Variable -Name var1 -Scope global -ErrorAction SilentlyContinue | Should Throw
$var1 | Should Be "context"
$var1 | Should Be "context"
Remove-Variable -Name var1 -Scope local
$var1 | Should Be # Nothing
}
Remove-Variable -Name var1 -Scope local
$var1 | Should Be # Nothing
}
It "Should be able to remove a local variable using the script scope switch" {
New-Variable -Name var1 -Value "context" -Scope local
It "Should be able to remove a local variable using the script scope switch" {
New-Variable -Name var1 -Value "context" -Scope local
Remove-Variable -Name var1 -Scope script -ErrorAction SilentlyContinue | Should Throw
Remove-Variable -Name var1 -Scope script -ErrorAction SilentlyContinue | Should Throw
$var1 | Should Be "context"
$var1 | Should Be "context"
Remove-Variable -Name var1 -Scope local
$var1 | Should Be # Nothing
}
Remove-Variable -Name var1 -Scope local
$var1 | Should Be # Nothing
}
It "Should be able to remove a script variable created using the script switch" {
New-Variable -Name var1 -Value "context" -Scope script
It "Should be able to remove a script variable created using the script switch" {
New-Variable -Name var1 -Value "context" -Scope script
Remove-Variable -Name var1 -Scope script | Should Throw
Remove-Variable -Name var1 -Scope script | Should Throw
$var1 | Should Be # Nothing
}
$var1 | Should Be # Nothing
}
It "Should not be able to remove a global script variable that was created using the script scope switch" {
New-Variable -Name var1 -Value "context" -Scope script
It "Should not be able to remove a global script variable that was created using the script scope switch" {
New-Variable -Name var1 -Value "context" -Scope script
Remove-Variable -Name var1 -Scope global -ErrorAction SilentlyContinue | Should Throw
Remove-Variable -Name var1 -Scope global -ErrorAction SilentlyContinue | Should Throw
$var1 | Should Be "context"
}
$var1 | Should Be "context"
}
}
}
+56 -58
View File
@@ -2,115 +2,113 @@
Describe "Select-Object" {
BeforeEach {
$dirObject = GetFileMock
$TestLength = 3
$dirObject = GetFileMock
$TestLength = 3
}
It "Handle piped input without error" {
{ $dirObject | Select-Object } | Should Not Throw
}
{ $dirObject | Select-Object } | Should Not Throw
}
It "Should treat input as a single object with the inputObject parameter" {
$result = $(Select-Object -inputObject $dirObject -last $TestLength).Length
$expected = $dirObject.Length
$result = $(Select-Object -inputObject $dirObject -last $TestLength).Length
$expected = $dirObject.Length
$result | Should Be $expected
$result | Should Be $expected
}
It "Should be able to use the alias" {
{ $dirObject | select } | Should Not Throw
{ $dirObject | select } | Should Not Throw
}
It "Should have same result when using alias" {
$result = $dirObject | select
$expected = $dirObject | Select-Object
$result = $dirObject | select
$expected = $dirObject | Select-Object
$result | Should Be $expected
$result | Should Be $expected
}
It "Should return correct object with First parameter" {
$result = $dirObject | Select-Object -First $TestLength
$result = $dirObject | Select-Object -First $TestLength
$result.Length | Should Be $TestLength
$result.Length | Should Be $TestLength
for ($i=0; $i -lt $TestLength; $i++)
{
$result[$i].Name | Should Be $dirObject[$i].Name
}
for ($i=0; $i -lt $TestLength; $i++)
{
$result[$i].Name | Should Be $dirObject[$i].Name
}
}
It "Should return correct object with Last parameter" {
$result = $dirObject | Select-Object -Last $TestLength
$result = $dirObject | Select-Object -Last $TestLength
$result.Length | Should Be $TestLength
$result.Length | Should Be $TestLength
for ($i=0; $i -lt $TestLength; $i++)
{
$result[$i].Name | Should Be $dirObject[$dirObject.Length - $TestLength + $i].Name
}
for ($i=0; $i -lt $TestLength; $i++)
{
$result[$i].Name | Should Be $dirObject[$dirObject.Length - $TestLength + $i].Name
}
}
It "Should work correctly with Unique parameter" {
$result = ("a","b","c","a","a","a" | Select-Object -Unique).Length
$expected = 3
$result = ("a","b","c","a","a","a" | Select-Object -Unique).Length
$expected = 3
$result | Should Be $expected
$result | Should Be $expected
}
It "Should return correct object with Skip parameter" {
$result = $dirObject | Select-Object -Skip $TestLength
$result = $dirObject | Select-Object -Skip $TestLength
$result.Length | Should Be ($dirObject.Length - $TestLength)
$result.Length | Should Be ($dirObject.Length - $TestLength)
for ($i=0; $i -lt $TestLength; $i++)
{
$result[$i].Name | Should Be $dirObject[$TestLength + $i].Name
}
for ($i=0; $i -lt $TestLength; $i++)
{
$result[$i].Name | Should Be $dirObject[$TestLength + $i].Name
}
}
It "Should return an object with selected columns" {
$result = $dirObject | Select-Object -Property Name, Size
$result = $dirObject | Select-Object -Property Name, Size
$result.Length | Should Be $dirObject.Length
$result[0].Name | Should Be $dirObject[0].Name
$result[0].Size | Should Be $dirObject[0].Size
$result[0].Mode | Should BeNullOrEmpty
$result.Length | Should Be $dirObject.Length
$result[0].Name | Should Be $dirObject[0].Name
$result[0].Size | Should Be $dirObject[0].Size
$result[0].Mode | Should BeNullOrEmpty
}
It "Should send output to pipe properly" {
{$dirObject | Select-Object -Unique | pipelineConsume} | Should Not Throw
}
{$dirObject | Select-Object -Unique | pipelineConsume} | Should Not Throw
}
It "Should select array indices with Index parameter" {
$firstIndex = 2
$secondIndex = 4
$result = $dirObject | Select-Object -Index $firstIndex, $secondIndex
$firstIndex = 2
$secondIndex = 4
$result = $dirObject | Select-Object -Index $firstIndex, $secondIndex
$result[0].Name | Should Be $dirObject[$firstIndex].Name
$result[1].Name | Should Be $dirObject[$secondIndex].Name
$result[0].Name | Should Be $dirObject[$firstIndex].Name
$result[1].Name | Should Be $dirObject[$secondIndex].Name
}
# Note that these two tests will modify original values of $dirObject
It "Should not wait when used without -Wait option" {
$orig1 = $dirObject[0].Size
$orig2 = $dirObject[$TestLength].Size
$result = $dirObject | addOneToSizeProperty | Select-Object -First $TestLength
$orig1 = $dirObject[0].Size
$orig2 = $dirObject[$TestLength].Size
$result = $dirObject | addOneToSizeProperty | Select-Object -First $TestLength
$result[0].Size | Should Be ($orig1 + 1)
$dirObject[0].Size | Should Be ($orig1 + 1)
$dirObject[$TestLength].Size | Should Be $orig2
$result[0].Size | Should Be ($orig1 + 1)
$dirObject[0].Size | Should Be ($orig1 + 1)
$dirObject[$TestLength].Size | Should Be $orig2
}
It "Should wait when used with -Wait option" {
$orig1 = $dirObject[0].Size
$orig2 = $dirObject[$TestLength].Size
$result = $dirObject | addOneToSizeProperty | Select-Object -First $TestLength -Wait
$orig1 = $dirObject[0].Size
$orig2 = $dirObject[$TestLength].Size
$result = $dirObject | addOneToSizeProperty | Select-Object -First $TestLength -Wait
$result[0].Size | Should Be ($orig1 + 1)
$dirObject[0].Size | Should Be ($orig1 + 1)
$dirObject[$TestLength].Size | Should Be ($orig2 + 1)
$result[0].Size | Should Be ($orig1 + 1)
$dirObject[0].Size | Should Be ($orig1 + 1)
$dirObject[$TestLength].Size | Should Be ($orig2 + 1)
}
}
+133 -133
View File
@@ -2,186 +2,186 @@ Describe "Select-String" {
$nl = [Environment]::NewLine
$currentDirectory = $pwd.Path
Context "String actions" {
$testinputone = "hello","Hello","goodbye"
$testinputtwo = "hello","Hello"
$testinputone = "hello","Hello","goodbye"
$testinputtwo = "hello","Hello"
it "Should be called without errors" {
{ $testinputone | Select-String -Pattern "hello" } | Should Not Throw
}
it "Should be called without errors" {
{ $testinputone | Select-String -Pattern "hello" } | Should Not Throw
}
it "Should be called without error using the sls alias" {
{ $testinputone | sls -Pattern "hello" } | Should Not Throw
}
it "Should be called without error using the sls alias" {
{ $testinputone | sls -Pattern "hello" } | Should Not Throw
}
it "Should return an array data type when multiple matches are found" {
( $testinputtwo | Select-String -Pattern "hello").gettype().basetype | Should Be Array
}
it "Should return an array data type when multiple matches are found" {
( $testinputtwo | Select-String -Pattern "hello").gettype().basetype | Should Be Array
}
it "Should return the same result for the alias sls and Select-String " {
$firstMatch = $testinputone | Select-String -Pattern "hello"
$secondMatch = $testinputone | sls -Pattern "hello"
it "Should return the same result for the alias sls and Select-String " {
$firstMatch = $testinputone | Select-String -Pattern "hello"
$secondMatch = $testinputone | sls -Pattern "hello"
$equal = @(compare-object $firstMatch $secondMatch).Length -eq 0
$equal | Should Be True
}
$equal = @(compare-object $firstMatch $secondMatch).Length -eq 0
$equal | Should Be True
}
it "Should return an object type when one match is found" {
( $testinputtwo | Select-String -Pattern "hello" -CaseSensitive).gettype().basetype | Should Be System.Object
}
it "Should return an object type when one match is found" {
( $testinputtwo | Select-String -Pattern "hello" -CaseSensitive).gettype().basetype | Should Be System.Object
}
it "Should return matchinfo type" {
( $testinputtwo | Select-String -Pattern "hello" -CaseSensitive).gettype().name | Should Be MatchInfo
}
it "Should return matchinfo type" {
( $testinputtwo | Select-String -Pattern "hello" -CaseSensitive).gettype().name | Should Be MatchInfo
}
it "Should be called without an error using ca for casesensitive " {
{$testinputone | Select-String -Pattern "hello" -ca } | Should Not Throw
}
it "Should be called without an error using ca for casesensitive " {
{$testinputone | Select-String -Pattern "hello" -ca } | Should Not Throw
}
it "Should use the ca alias for casesenstive" {
$firstMatch = $testinputtwo | Select-String -Pattern "hello" -CaseSensitive
$secondMatch = $testinputtwo | Select-String -Pattern "hello" -ca
it "Should use the ca alias for casesenstive" {
$firstMatch = $testinputtwo | Select-String -Pattern "hello" -CaseSensitive
$secondMatch = $testinputtwo | Select-String -Pattern "hello" -ca
$equal = @(Compare-Object $firstMatch $secondMatch).Length -eq 0
$equal | Should Be True
}
$equal = @(Compare-Object $firstMatch $secondMatch).Length -eq 0
$equal | Should Be True
}
it "Should only return the case sensitive match when the casesensitive switch is used" {
$testinputtwo | Select-String -Pattern "hello" -CaseSensitive | Should Be "hello"
}
it "Should only return the case sensitive match when the casesensitive switch is used" {
$testinputtwo | Select-String -Pattern "hello" -CaseSensitive | Should Be "hello"
}
it "Should accept a collection of strings from the input object" {
{ Select-String -InputObject "some stuff", "other stuff" -Pattern "other" } | Should Not Throw
}
it "Should accept a collection of strings from the input object" {
{ Select-String -InputObject "some stuff", "other stuff" -Pattern "other" } | Should Not Throw
}
it "Should return system.object when the input object switch is used on a collection" {
( Select-String -InputObject "some stuff", "other stuff" -pattern "other" ).gettype().basetype | Should Be System.Object
}
it "Should return system.object when the input object switch is used on a collection" {
( Select-String -InputObject "some stuff", "other stuff" -pattern "other" ).gettype().basetype | Should Be System.Object
}
it "Should return null or empty when the input object switch is used on a collection and the pattern does not exist" {
Select-String -InputObject "some stuff", "other stuff" -Pattern "neither" | Should BeNullOrEmpty
}
it "Should return null or empty when the input object switch is used on a collection and the pattern does not exist" {
Select-String -InputObject "some stuff", "other stuff" -Pattern "neither" | Should BeNullOrEmpty
}
it "Should return a bool type when the quiet switch is used" {
($testinputtwo | Select-String -Quiet "hello" -CaseSensitive).gettype() | Should Be Bool
}
it "Should return a bool type when the quiet switch is used" {
($testinputtwo | Select-String -Quiet "hello" -CaseSensitive).gettype() | Should Be Bool
}
it "Should be true when select string returns a positive result when the quiet switch is used" {
($testinputtwo | Select-String -Quiet "hello" -CaseSensitive) | Should Be $True
}
it "Should be true when select string returns a positive result when the quiet switch is used" {
($testinputtwo | Select-String -Quiet "hello" -CaseSensitive) | Should Be $True
}
it "Should be empty when select string does not return a result when the quiet switch is used" {
$testinputtwo | Select-String -Quiet "goodbye" | Should BeNullOrEmpty
}
it "Should be empty when select string does not return a result when the quiet switch is used" {
$testinputtwo | Select-String -Quiet "goodbye" | Should BeNullOrEmpty
}
it "Should return an array of non matching strings when the switch of NotMatch is used and the string do not match" {
$testinputone | Select-String -Pattern "goodbye" -NotMatch | Should Be "hello", "hello"
}
it "Should return an array of non matching strings when the switch of NotMatch is used and the string do not match" {
$testinputone | Select-String -Pattern "goodbye" -NotMatch | Should Be "hello", "hello"
}
it "Should return the same as NotMatch" {
$firstMatch = $testinputone | Select-String -pattern "goodbye" -NotMatch
$secondMatch = $testinputone | Select-String -pattern "goodbye" -n
it "Should return the same as NotMatch" {
$firstMatch = $testinputone | Select-String -pattern "goodbye" -NotMatch
$secondMatch = $testinputone | Select-String -pattern "goodbye" -n
$equal = @(Compare-Object $firstMatch $secondMatch).Length -eq 0
$equal | Should Be True
}
$equal = @(Compare-Object $firstMatch $secondMatch).Length -eq 0
$equal | Should Be True
}
}
Context "Filesytem actions" {
$isWindows = [System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Windows)
$isWindows = [System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Windows)
$testDirectory = $TestDrive
$testInputFile = Join-Path -Path $testDirectory -ChildPath testfile1.txt
$testDirectory = $TestDrive
$testInputFile = Join-Path -Path $testDirectory -ChildPath testfile1.txt
BeforeEach {
New-Item $testInputFile -Itemtype "file" -Force -Value "This is a text string, and another string${nl}This is the second line${nl}This is the third line${nl}This is the fourth line${nl}No matches"
}
BeforeEach {
New-Item $testInputFile -Itemtype "file" -Force -Value "This is a text string, and another string${nl}This is the second line${nl}This is the third line${nl}This is the fourth line${nl}No matches"
}
AfterEach {
Remove-Item $testInputFile -Force
}
AfterEach {
Remove-Item $testInputFile -Force
}
It "Should return an object when a match is found is the file on only one line" {
(Select-String $testInputFile -Pattern "string").GetType().BaseType | Should be System.Object
}
It "Should return an object when a match is found is the file on only one line" {
(Select-String $testInputFile -Pattern "string").GetType().BaseType | Should be System.Object
}
It "Should return an array when a match is found is the file on several lines" {
(Select-String $testInputFile -Pattern "in").GetType().BaseType | Should be array
(Select-String $testInputFile -Pattern "in")[0].GetType().Name | Should Be MatchInfo
}
It "Should return an array when a match is found is the file on several lines" {
(Select-String $testInputFile -Pattern "in").GetType().BaseType | Should be array
(Select-String $testInputFile -Pattern "in")[0].GetType().Name | Should Be MatchInfo
}
It "Should return the name of the file and the string that 'string' is found if there is only one lines that has a match" {
$expected = $testInputFile + ":1:This is a text string, and another string"
It "Should return the name of the file and the string that 'string' is found if there is only one lines that has a match" {
$expected = $testInputFile + ":1:This is a text string, and another string"
Select-String $(Split-Path $testInputFile -NoQualifier) -Pattern "string" | Should Be $expected
}
Select-String $(Split-Path $testInputFile -NoQualifier) -Pattern "string" | Should Be $expected
}
It "Should return all strings where 'second' is found in testfile1 if there is only one lines that has a match" {
$expected = $testInputFile + ":2:This is the second line"
It "Should return all strings where 'second' is found in testfile1 if there is only one lines that has a match" {
$expected = $testInputFile + ":2:This is the second line"
Select-String $testInputFile -Pattern "second"| Should Be $expected
}
Select-String $testInputFile -Pattern "second"| Should Be $expected
}
It "Should return all strings where 'in' is found in testfile1 pattern switch is not required" {
$expected1 = "This is a text string, and another string"
$expected2 = "This is the second line"
$expected3 = "This is the third line"
$expected4 = "This is the fourth line"
It "Should return all strings where 'in' is found in testfile1 pattern switch is not required" {
$expected1 = "This is a text string, and another string"
$expected2 = "This is the second line"
$expected3 = "This is the third line"
$expected4 = "This is the fourth line"
(Select-String in $testInputFile)[0].Line | Should Be $expected1
(Select-String in $testInputFile)[1].Line | Should Be $expected2
(Select-String in $testInputFile)[2].Line | Should Be $expected3
(Select-String in $testInputFile)[3].Line | Should Be $expected4
(Select-String in $testInputFile)[4].Line | Should BeNullOrEmpty
}
(Select-String in $testInputFile)[0].Line | Should Be $expected1
(Select-String in $testInputFile)[1].Line | Should Be $expected2
(Select-String in $testInputFile)[2].Line | Should Be $expected3
(Select-String in $testInputFile)[3].Line | Should Be $expected4
(Select-String in $testInputFile)[4].Line | Should BeNullOrEmpty
}
It "Should return empty because 'for' is not found in testfile1 " {
Select-String for $testInputFile | Should BeNullOrEmpty
}
It "Should return empty because 'for' is not found in testfile1 " {
Select-String for $testInputFile | Should BeNullOrEmpty
}
It "Should return the third line in testfile1 and the lines above and below it " {
$expectedLine = "testfile1.txt:2:This is the second line"
$expectedLineBefore = "testfile1.txt:3:This is the third line"
$expectedLineAfter = "testfile1.txt:4:This is the fourth line"
It "Should return the third line in testfile1 and the lines above and below it " {
$expectedLine = "testfile1.txt:2:This is the second line"
$expectedLineBefore = "testfile1.txt:3:This is the third line"
$expectedLineAfter = "testfile1.txt:4:This is the fourth line"
Select-String third $testInputFile -Context 1 | Should Match $expectedLine
Select-String third $testInputFile -Context 1 | Should Match $expectedLineBefore
Select-String third $testInputFile -Context 1 | Should Match $expectedLineAfter
}
Select-String third $testInputFile -Context 1 | Should Match $expectedLine
Select-String third $testInputFile -Context 1 | Should Match $expectedLineBefore
Select-String third $testInputFile -Context 1 | Should Match $expectedLineAfter
}
It "Should return the number of matches for 'is' in textfile1 " {
(Select-String is $testInputFile -CaseSensitive).count| Should Be 4
}
It "Should return the number of matches for 'is' in textfile1 " {
(Select-String is $testInputFile -CaseSensitive).count| Should Be 4
}
It "Should return the third line in testfile1 when a relative path is used" {
$expected = "testfile1.txt:3:This is the third line"
It "Should return the third line in testfile1 when a relative path is used" {
$expected = "testfile1.txt:3:This is the third line"
$relativePath = Join-Path -Path $testDirectory -ChildPath ".."
$relativePath = Join-Path -Path $relativePath -ChildPath ".."
$relativePath = Join-Path -Path $relativePath -ChildPath (Split-Path $testDirectory -NoQualifier)
$relativePath = Join-Path -Path $relativePath -ChildPath testfile1.txt
Select-String third $relativePath | Should Match $expected
}
$relativePath = Join-Path -Path $testDirectory -ChildPath ".."
$relativePath = Join-Path -Path $relativePath -ChildPath ".."
$relativePath = Join-Path -Path $relativePath -ChildPath (Split-Path $testDirectory -NoQualifier)
$relativePath = Join-Path -Path $relativePath -ChildPath testfile1.txt
Select-String third $relativePath | Should Match $expected
}
It "Should return the fourth line in testfile1 when a relative path is used" {
$expected = "testfile1.txt:5:No matches"
It "Should return the fourth line in testfile1 when a relative path is used" {
$expected = "testfile1.txt:5:No matches"
pushd $testDirectory
pushd $testDirectory
Select-String matches (Join-Path -Path $testDirectory -ChildPath testfile1.txt) | Should Match $expected
popd
}
Select-String matches (Join-Path -Path $testDirectory -ChildPath testfile1.txt) | Should Match $expected
popd
}
It "Should return the fourth line in testfile1 when a regular expression is used" {
$expected = "testfile1.txt:5:No matches"
It "Should return the fourth line in testfile1 when a regular expression is used" {
$expected = "testfile1.txt:5:No matches"
Select-String 'matc*' $testInputFile -CaseSensitive | Should Match $expected
}
Select-String 'matc*' $testInputFile -CaseSensitive | Should Match $expected
}
It "Should return the fourth line in testfile1 when a regular expression is used, using the alias for casesensitive" {
$expected = "testfile1.txt:5:No matches"
It "Should return the fourth line in testfile1 when a regular expression is used, using the alias for casesensitive" {
$expected = "testfile1.txt:5:No matches"
Select-String 'matc*' $testInputFile -ca | Should Match $expected
}
Select-String 'matc*' $testInputFile -ca | Should Match $expected
}
}
Push-Location $currentDirectory
}
+7 -7
View File
@@ -2,23 +2,23 @@ Describe "Set-Alias" {
Mock Get-Date { return "Friday, October 30, 2015 3:38:08 PM" }
It "Should be able to set alias without error" {
{ set-alias -Name gd -Value Get-Date } | Should Not Throw
{ set-alias -Name gd -Value Get-Date } | Should Not Throw
}
It "Should be able to have the same output between set-alias and the output of the function being aliased" {
set-alias -Name gd -Value Get-Date
gd | Should Be $(Get-Date)
set-alias -Name gd -Value Get-Date
gd | Should Be $(Get-Date)
}
It "Should be able to use the sal alias" {
{ sal gd Get-Date } | Should Not Throw
{ sal gd Get-Date } | Should Not Throw
}
It "Should have the same output between the sal alias and the original set-alias cmdlet" {
sal -Name gd -Value Get-Date
sal -Name gd -Value Get-Date
Set-Alias -Name gd2 -Value Get-Date
Set-Alias -Name gd2 -Value Get-Date
gd2 | Should Be $(gd)
gd2 | Should Be $(gd)
}
}
+18 -18
View File
@@ -3,64 +3,64 @@ Describe "Set-Location" {
if ($IsWindows)
{
$target = "C:\"
$target = "C:\"
}
else
{
$target = "/"
$target = "/"
}
It "Should be able to be called without error" {
{ Set-Location $target } | Should Not Throw
{ Set-Location $target } | Should Not Throw
}
It "Should be able to be called on different providers" {
{ Set-Location alias: } | Should Not Throw
{ Set-Location env: } | Should Not Throw
{ Set-Location alias: } | Should Not Throw
{ Set-Location env: } | Should Not Throw
}
It "Should be able use the cd alias without error" {
{ cd $target } | Should Not Throw
{ cd $target } | Should Not Throw
}
It "Should be able to use the chdir alias without error" {
{ chdir $target } | Should Not Throw
{ chdir $target } | Should Not Throw
}
It "Should be able to use the sl alias without error" {
{ sl $target } | Should Not Throw
{ sl $target } | Should Not Throw
}
It "Should have the correct current location when using the set-location cmdlet" {
Set-Location $startDirectory
Set-Location $startDirectory
$(Get-Location).Path | Should Be $startDirectory.Path
$(Get-Location).Path | Should Be $startDirectory.Path
}
It "Should have the correct current location when using the cd alias" {
cd $target
cd $target
$(Get-Location).Path | Should Be $target
$(Get-Location).Path | Should Be $target
}
It "Should have the correct current location when using the chdir alias" {
chdir $target
chdir $target
$(Get-Location).Path | Should Be $target
$(Get-Location).Path | Should Be $target
}
It "Should have the correct current location when using the chdir alias" {
sl $target
sl $target
$(Get-Location).Path | Should Be $target
$(Get-Location).Path | Should Be $target
}
It "Should be able to use the Path switch" {
{ Set-Location -Path $target } | Should Not Throw
{ Set-Location -Path $target } | Should Not Throw
}
It "Should generate a pathinfo object when using the Passthru switch" {
$(Set-Location $target -PassThru).GetType().Name | Should Be PathInfo
$(Set-Location $target -PassThru).GetType().Name | Should Be PathInfo
}
Set-Location $startDirectory
+16 -16
View File
@@ -5,32 +5,32 @@ Describe "Set-PSBreakpoint" {
"`$var = 1 " > $testScript
It "Should be able to set a psbreakpoint on a line" {
$lineNumber = 1
$brk = Set-PSBreakpoint -Line $lineNumber -Script $testScript
$brk.Line | Should Be $lineNumber
Remove-PSBreakPoint -Id $brk.Id
$lineNumber = 1
$brk = Set-PSBreakpoint -Line $lineNumber -Script $testScript
$brk.Line | Should Be $lineNumber
Remove-PSBreakPoint -Id $brk.Id
}
It "Should throw when a string is entered for a line number" {
{
$lineNumber = "one"
Set-PSBreakpoint -Line $lineNumber -Script $testScript
{
$lineNumber = "one"
Set-PSBreakpoint -Line $lineNumber -Script $testScript
} | Should Throw
} | Should Throw
}
It "Should be able to set a psbreakpoint on a Command" {
$command = "theCommand"
$brk = Set-PSBreakpoint -Command $command -Script $testScript
$brk.Command | Should Be $command
Remove-PSBreakPoint -Id $brk.Id
$command = "theCommand"
$brk = Set-PSBreakpoint -Command $command -Script $testScript
$brk.Command | Should Be $command
Remove-PSBreakPoint -Id $brk.Id
}
It "Should be able to set a psbreakpoint on a variable" {
$var = "theVariable"
$brk = Set-PSBreakpoint -Command $var -Script $testScript
$brk.Command | Should Be $var
Remove-PSBreakPoint -Id $brk.Id
$var = "theVariable"
$brk = Set-PSBreakpoint -Command $var -Script $testScript
$brk.Command | Should Be $var
Remove-PSBreakPoint -Id $brk.Id
}
# clean up after ourselves
+13 -13
View File
@@ -2,27 +2,27 @@ Describe "Set-PSDebug" {
# Because it is running through pester, no functions need to be called. Pester should provide plenty
# of output.
It "Should be able to be called without error" {
{ Set-PSDebug -Trace 0 } | Should Not Throw
{ Set-PSDebug -Trace 0 } | Should Not Throw
}
It "Should be able to be turned off without error" {
{ Set-PSDebug -Off } | Should Not Throw
{ Set-PSDebug -Off } | Should Not Throw
}
Context "Validate functionality" {
BeforeEach {
Set-PSDebug -Off
}
BeforeEach {
Set-PSDebug -Off
}
It "Should be able to go through the tracing options" {
{ Set-PSDebug -Trace 0 } | Should Not Throw
{ Set-PSDebug -Trace 1 } | Should Not Throw
{ Set-PSDebug -Trace 2 } | Should Not Throw
}
It "Should be able to go through the tracing options" {
{ Set-PSDebug -Trace 0 } | Should Not Throw
{ Set-PSDebug -Trace 1 } | Should Not Throw
{ Set-PSDebug -Trace 2 } | Should Not Throw
}
It "Should be able to set strict" {
{ Set-PSDebug -Strict } | Should Not Throw
}
It "Should be able to set strict" {
{ Set-PSDebug -Strict } | Should Not Throw
}
}
# final cleanup
+33 -33
View File
@@ -2,81 +2,81 @@ Describe "Set-Variable" {
${nl} = [Environment]::Newline
It "Should create a new variable with no parameters" {
{ Set-Variable testVar } | Should Not Throw
{ Set-Variable testVar } | Should Not Throw
}
It "Should assign a value to a variable it has to create" {
Set-Variable -Name testVar -Value 4
Set-Variable -Name testVar -Value 4
Get-Variable testVar -ValueOnly | Should Be 4
Get-Variable testVar -ValueOnly | Should Be 4
}
It "Should change the value of an already existing variable" {
$testVar=1
$testVar=1
$testVar | Should Not Be 2
$testVar | Should Not Be 2
Set-Variable testVar -Value 2
Set-Variable testVar -Value 2
$testVar | Should Be 2
$testVar | Should Be 2
}
It "Should be able to be called with the set alias" {
set testVar -Value 1
set testVar -Value 1
$testVar | Should Be 1
$testVar | Should Be 1
}
It "Should be able to be called with the sv alias" {
sv testVar -Value 2
sv testVar -Value 2
$testVar | Should Be 2
$testVar | Should Be 2
}
It "Should be able to set variable name using the Name parameter" {
Set-Variable -Name testVar -Value 1
Set-Variable -Name testVar -Value 1
$testVar | Should Be 1
$testVar | Should Be 1
}
It "Should be able to set the value of a variable by piped input" {
$testValue = "piped input"
$testValue = "piped input"
$testValue | Set-Variable -Name testVar
$testValue | Set-Variable -Name testVar
$testVar | Should Be $testValue
$testVar | Should Be $testValue
}
It "Should be able to pipe object properties to output using the PassThru switch" {
$in = Set-Variable -Name testVar -Value "test" -Description "test description" -PassThru
$in = Set-Variable -Name testVar -Value "test" -Description "test description" -PassThru
$output = $in | Format-List -Property Description | Out-String
$output = $in | Format-List -Property Description | Out-String
# This will cause errors running these tests in Windows
$output | Should Be "${nl}${nl}Description : test description${nl}${nl}${nl}${nl}"
# This will cause errors running these tests in Windows
$output | Should Be "${nl}${nl}Description : test description${nl}${nl}${nl}${nl}"
}
It "Should be able to set the value using the value switch" {
Set-Variable -Name testVar -Value 4
Set-Variable -Name testVar -Value 4
$testVar | Should Be 4
$testVar | Should Be 4
Set-Variable -Name testVar -Value "test"
Set-Variable -Name testVar -Value "test"
$testVar | Should Be "test"
$testVar | Should Be "test"
}
Context "Scope Tests" {
It "Should be able to set a global scope variable using the global switch" {
{ Set-Variable globalVar -Value 1 -Scope global -Force } | Should Not Throw
}
It "Should be able to set a global scope variable using the global switch" {
{ Set-Variable globalVar -Value 1 -Scope global -Force } | Should Not Throw
}
It "Should be able to set a global variable using the script scope switch" {
{ Set-Variable globalVar -Value 1 -Scope script -Force } | Should Not Throw
}
It "Should be able to set a global variable using the script scope switch" {
{ Set-Variable globalVar -Value 1 -Scope script -Force } | Should Not Throw
}
It "Should be able to set an item locally using the local switch" {
{ Set-Variable globalVar -Value 1 -Scope local -Force } | Should Not Throw
}
It "Should be able to set an item locally using the local switch" {
{ Set-Variable globalVar -Value 1 -Scope local -Force } | Should Not Throw
}
}
}
+59 -59
View File
@@ -1,106 +1,106 @@
Describe "Split-Path" {
if ($IsWindows)
{
$qualifier = "C:"
$qualifier = "C:"
}
else
{
$qualifier = "/"
$qualifier = "/"
}
It "Should return a string object when invoked" {
( Split-Path . ).GetType().Name | Should Be "String"
( Split-Path . -Leaf ).GetType().Name | Should Be "String"
( Split-Path . -Resolve ).GetType().Name | Should Be "String"
( Split-Path . ).GetType().Name | Should Be "String"
( Split-Path . -Leaf ).GetType().Name | Should Be "String"
( Split-Path . -Resolve ).GetType().Name | Should Be "String"
}
It "Should return the name of the drive when the qualifier switch is used" {
Split-Path $qualifier -Qualifier | Should Be "$qualifier"
Split-Path ${qualifier}usr/bin -Qualifier | Should Be "$qualifier"
Split-Path $qualifier -Qualifier | Should Be "$qualifier"
Split-Path ${qualifier}usr/bin -Qualifier | Should Be "$qualifier"
}
It "Should error when using the qualifier switch for a Windows path while on a non-Windows machine" {
# ErrorAction SilentlyContinue merely suppresses the error from the console.
# Throwing exceptions still seen by Pester.
# ErrorAction SilentlyContinue merely suppresses the error from the console.
# Throwing exceptions still seen by Pester.
if ($qualifier -eq "/")
{
Split-Path "C:\Users" -Qualifier -ErrorAction SilentlyContinue | Should Throw
}
else
{
Split-Path "/Users" -Qualifier -ErrorAction SilentlyContinue | Should Throw
if ($qualifier -eq "/")
{
Split-Path "C:\Users" -Qualifier -ErrorAction SilentlyContinue | Should Throw
}
else
{
Split-Path "/Users" -Qualifier -ErrorAction SilentlyContinue | Should Throw
}
}
}
It "Should error when no directory separator characters are used with a qualifier" {
Split-Path "abadTest" -Qualifier -ErrorAction SilentlyContinue | Should Throw
Split-Path "abadTest" -Qualifier -ErrorAction SilentlyContinue | Should Throw
}
It "Should return the path when the noqualifier switch is used on a Linux system" {
{ Split-Path ${qualifier}usr/bin -NoQualifier } | Should Not Throw
if ($IsWindows)
{
Split-Path ${qualifier}usr/bin -NoQualifier | Should Be "usr/bin"
}
else
{
Split-Path ${qualifier}usr/bin -NoQualifier | Should Be "/usr/bin"
}
{ Split-Path ${qualifier}usr/bin -NoQualifier } | Should Not Throw
if ($IsWindows)
{
Split-Path ${qualifier}usr/bin -NoQualifier | Should Be "usr/bin"
}
else
{
Split-Path ${qualifier}usr/bin -NoQualifier | Should Be "/usr/bin"
}
}
It "Should return the base name when the leaf switch is used" {
Split-Path ${qualifier}usr/bin -Leaf | Should be "bin"
Split-Path ${qualifier}usr/local/bin -Leaf | Should be "bin"
Split-Path usr/bin -Leaf | Should be "bin"
Split-Path ./bin -Leaf | Should be "bin"
Split-Path bin -Leaf | Should be "bin"
Split-Path ${qualifier}usr/bin -Leaf | Should be "bin"
Split-Path ${qualifier}usr/local/bin -Leaf | Should be "bin"
Split-Path usr/bin -Leaf | Should be "bin"
Split-Path ./bin -Leaf | Should be "bin"
Split-Path bin -Leaf | Should be "bin"
}
It "Should be able to accept regular expression input and output an array for multiple objects" {
$testDir = $TestDrive
$testFile1 = "testfile1.ps1"
$testFile2 = "testfile2.ps1"
$testFilePath1 = Join-Path -Path $testDir -ChildPath $testFile1
$testFilePath2 = Join-Path -Path $testDir -ChildPath $testFile2
$testDir = $TestDrive
$testFile1 = "testfile1.ps1"
$testFile2 = "testfile2.ps1"
$testFilePath1 = Join-Path -Path $testDir -ChildPath $testFile1
$testFilePath2 = Join-Path -Path $testDir -ChildPath $testFile2
New-Item -ItemType file -Path $testFilePath1, $testFilePath2 -Force
New-Item -ItemType file -Path $testFilePath1, $testFilePath2 -Force
Test-Path $testFilePath1 | Should Be $true
Test-Path $testFilePath2 | Should Be $true
Test-Path $testFilePath1 | Should Be $true
Test-Path $testFilePath2 | Should Be $true
$actual = ( Split-Path (Join-Path -Path $testDir -ChildPath "*file*.ps1") -Leaf -Resolve ) | Sort-Object
$actual.GetType().BaseType.Name | Should Be "Array"
$actual[0] | Should Be $testFile1
$actual[1] | Should Be $testFile2
$actual = ( Split-Path (Join-Path -Path $testDir -ChildPath "*file*.ps1") -Leaf -Resolve ) | Sort-Object
$actual.GetType().BaseType.Name | Should Be "Array"
$actual[0] | Should Be $testFile1
$actual[1] | Should Be $testFile2
}
It "Should be able to tell if a given path is an absolute path" {
( Split-Path ${qualifier}usr/bin -IsAbsolute ) | Should be $true
( Split-Path .. -IsAbsolute ) | Should be $false
( Split-Path ${qualifier}usr/.. -IsAbsolute ) | Should be $true
( Split-Path ${qualifier}usr/../ -IsAbsolute ) | Should be $true
( Split-Path ../ -IsAbsolute ) | Should be $false
( Split-Path . -IsAbsolute ) | Should be $false
( Split-Path ~/ -IsAbsolute ) | Should be $false
( Split-Path ~/.. -IsAbsolute ) | Should be $false
( Split-Path ~/../.. -IsAbsolute ) | Should be $false
( Split-Path ${qualifier}usr/bin -IsAbsolute ) | Should be $true
( Split-Path .. -IsAbsolute ) | Should be $false
( Split-Path ${qualifier}usr/.. -IsAbsolute ) | Should be $true
( Split-Path ${qualifier}usr/../ -IsAbsolute ) | Should be $true
( Split-Path ../ -IsAbsolute ) | Should be $false
( Split-Path . -IsAbsolute ) | Should be $false
( Split-Path ~/ -IsAbsolute ) | Should be $false
( Split-Path ~/.. -IsAbsolute ) | Should be $false
( Split-Path ~/../.. -IsAbsolute ) | Should be $false
}
It "Should support piping" {
$path = "${qualifier}usr/bin"
( $path | Split-Path ) | Should Be "${qualifier}usr"
$path = "${qualifier}usr/bin"
( $path | Split-Path ) | Should Be "${qualifier}usr"
}
It "Should return the path up to the parent of the directory when Parent switch is used" {
Split-Path "${qualifier}usr/bin" -Parent | Should Be "${qualifier}usr"
Split-Path "${qualifier}usr/local/bin" -Parent | Should Be $(Join-Path "${qualifier}usr" -ChildPath "local")
Split-Path "usr/local/bin" -Parent | Should Be $(Join-Path "usr" -ChildPath "local")
Split-Path "${qualifier}usr/bin" -Parent | Should Be "${qualifier}usr"
Split-Path "${qualifier}usr/local/bin" -Parent | Should Be $(Join-Path "${qualifier}usr" -ChildPath "local")
Split-Path "usr/local/bin" -Parent | Should Be $(Join-Path "usr" -ChildPath "local")
}
It "Should throw if a parameterSetName is incorrect" {
{ Split-Path "${qualifier}usr/bin/" -Parentaoeu } | Should Throw "A parameter cannot be found that matches parameter name"
{ Split-Path "${qualifier}usr/bin/" -Parentaoeu } | Should Throw "A parameter cannot be found that matches parameter name"
}
}
+27 -27
View File
@@ -5,66 +5,66 @@ Describe "Start-Process" {
$assetsFile = Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath SortTest.txt
if ($IsWindows)
{
$pingParam = "localhost -n 4"
$pingParam = "localhost -n 4"
}
else
{
$pingParam = "localhost -c 4"
$pingParam = "localhost -c 4"
}
It "Should process arguments without error" {
$process = Start-Process ping -ArgumentList $pingParam -PassThru
$process = Start-Process ping -ArgumentList $pingParam -PassThru
$process.Length | Should Be 1
$process.Id | Should BeGreaterThan 1
$process.ProcessName | Should Be "ping"
$process.Length | Should Be 1
$process.Id | Should BeGreaterThan 1
$process.ProcessName | Should Be "ping"
}
It "Should work correctly when used with full path name" {
$process = Start-Process $pingCommand -ArgumentList $pingParam -PassThru
$process = Start-Process $pingCommand -ArgumentList $pingParam -PassThru
$process.Length | Should Be 1
$process.Id | Should BeGreaterThan 1
$process.ProcessName | Should Be "ping"
$process.Length | Should Be 1
$process.Id | Should BeGreaterThan 1
$process.ProcessName | Should Be "ping"
}
It "Should invoke correct path when used with FilePath argument" {
$process = Start-Process -FilePath $pingCommand -ArgumentList $pingParam -PassThru
$process = Start-Process -FilePath $pingCommand -ArgumentList $pingParam -PassThru
$process.Length | Should Be 1
$process.Id | Should BeGreaterThan 1
$process.ProcessName | Should Be "ping"
$process.Length | Should Be 1
$process.Id | Should BeGreaterThan 1
$process.ProcessName | Should Be "ping"
}
It "Should wait for command completion if used with Wait argument" {
$process = Start-Process ping -ArgumentList $pingParam -Wait -PassThru
$process = Start-Process ping -ArgumentList $pingParam -Wait -PassThru
}
It "Should work correctly with WorkingDirectory argument" {
$process = Start-Process ping -WorkingDirectory $pingDirectory -ArgumentList $pingParam -PassThru
$process = Start-Process ping -WorkingDirectory $pingDirectory -ArgumentList $pingParam -PassThru
$process.Length | Should Be 1
$process.Id | Should BeGreaterThan 1
$process.ProcessName | Should Be "ping"
$process.Length | Should Be 1
$process.Id | Should BeGreaterThan 1
$process.ProcessName | Should Be "ping"
}
It "Should should handle stderr redirection without error" {
$process = Start-Process ping -ArgumentList $pingParam -PassThru -RedirectStandardError $tempFile
$process = Start-Process ping -ArgumentList $pingParam -PassThru -RedirectStandardError $tempFile
$process.Length | Should Be 1
$process.Id | Should BeGreaterThan 1
$process.ProcessName | Should Be "ping"
$process.Length | Should Be 1
$process.Id | Should BeGreaterThan 1
$process.ProcessName | Should Be "ping"
}
It "Should should handle stdout redirection without error" {
$process = Start-Process ping -ArgumentList $pingParam -Wait -RedirectStandardOutput $tempFile
$dirEntry = dir $tempFile
$process = Start-Process ping -ArgumentList $pingParam -Wait -RedirectStandardOutput $tempFile
$dirEntry = dir $tempFile
$dirEntry.Length | Should BeGreaterThan 0
}
It "Should should handle stdin redirection without error" {
$process = Start-Process sort -Wait -RedirectStandardOutput $tempFile -RedirectStandardInput $assetsFile
$dirEntry = dir $tempFile
$process = Start-Process sort -Wait -RedirectStandardOutput $tempFile -RedirectStandardInput $assetsFile
$dirEntry = dir $tempFile
$dirEntry.Length | Should BeGreaterThan 0
}
+8 -8
View File
@@ -1,14 +1,14 @@
Describe "Start-Sleep" {
Context "Validate Start-Sleep works properly" {
It "Should only sleep for at least 1 second" {
$result = Measure-Command { Start-Sleep -s 1 }
$result.TotalSeconds | Should BeGreaterThan 0.25
}
It "Should only sleep for at least 1 second" {
$result = Measure-Command { Start-Sleep -s 1 }
$result.TotalSeconds | Should BeGreaterThan 0.25
}
It "Should sleep for at least 1 second using the alias" {
$result = Measure-Command { sleep -s 1 }
$result.TotalSeconds | Should BeGreaterThan 0.25
}
It "Should sleep for at least 1 second using the alias" {
$result = Measure-Command { sleep -s 1 }
$result.TotalSeconds | Should BeGreaterThan 0.25
}
}
}
+22 -22
View File
@@ -2,34 +2,34 @@ Describe "Tee-Object" {
Context "Validate Tee-Object is correctly forking output" {
$testfile = Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath testfile.txt
It "Should return the output to the screen and to the variable" {
$teefile = $testfile
$testfile = Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath testfile.txt
It "Should return the output to the screen and to the variable" {
$teefile = $testfile
echo teeobjecttest1 | Tee-Object -variable teeresults
$teeresults | Should Be "teeobjecttest1"
Remove-Item $teefile -ErrorAction SilentlyContinue
}
It "Should return the output to the screen and to the variable from the alias" {
$teefile = $testfile
echo teeobjecttest2 | tee -variable teeresults
$teeresults | Should Be "teeobjecttest2"
Remove-Item $teefile -ErrorAction SilentlyContinue
}
It "Should return the output to the screen and to the variable from the alias" {
$teefile = $testfile
echo teeobjecttest2 | tee -variable teeresults
$teeresults | Should Be "teeobjecttest2"
Remove-Item $teefile -ErrorAction SilentlyContinue
}
It "Should tee the output to a file" {
$teefile = $testfile
echo teeobjecttest3 | Tee-Object $teefile
Get-Content $teefile | Should Be "teeobjecttest3"
Remove-Item $teefile -ErrorAction SilentlyContinue
}
It "Should tee the output to a file" {
$teefile = $testfile
echo teeobjecttest3 | Tee-Object $teefile
Get-Content $teefile | Should Be "teeobjecttest3"
Remove-Item $teefile -ErrorAction SilentlyContinue
}
It "Should tee the output to a file using the alias" {
$teefile = $testfile
echo teeobjecttest4 | tee $teefile
Get-Content $teefile | Should Be "teeobjecttest4"
Remove-item $teefile -ErrorAction SilentlyContinue
}
It "Should tee the output to a file using the alias" {
$teefile = $testfile
echo teeobjecttest4 | tee $teefile
Get-Content $teefile | Should Be "teeobjecttest4"
Remove-item $teefile -ErrorAction SilentlyContinue
}
}
}
+7 -7
View File
@@ -1,17 +1,17 @@
Function GetFileMock () {
Function GetFileMock () {
$objs = @( [pscustomobject]@{ Size=4533816; Mode="-a---l"; LastWriteTime="9/1/2015 11:15 PM"; Name="explorer.exe" },
[pscustomobject]@{ Size=994816; Mode="-a---l"; LastWriteTime="9/1/2015 11:13 PM"; Name="HelpPane.exe" },
[pscustomobject]@{ Size=316640; Mode="-a---l"; LastWriteTime="9/1/2015 11:17 PM"; Name="WMSysPr9.prx" },
[pscustomobject]@{ Size=215040; Mode="-a---l"; LastWriteTime="9/1/2015 11:20 PM"; Name="notepad.exe" },
[pscustomobject]@{ Size=207239; Mode="-a----"; LastWriteTime="10/7/2015 2:37 PM"; Name="setupact.log" },
[pscustomobject]@{ Size=181064; Mode="-a----"; LastWriteTime="9/9/2015 11:54 PM"; Name="PSEXESVC.EXE" })
[pscustomobject]@{ Size=994816; Mode="-a---l"; LastWriteTime="9/1/2015 11:13 PM"; Name="HelpPane.exe" },
[pscustomobject]@{ Size=316640; Mode="-a---l"; LastWriteTime="9/1/2015 11:17 PM"; Name="WMSysPr9.prx" },
[pscustomobject]@{ Size=215040; Mode="-a---l"; LastWriteTime="9/1/2015 11:20 PM"; Name="notepad.exe" },
[pscustomobject]@{ Size=207239; Mode="-a----"; LastWriteTime="10/7/2015 2:37 PM"; Name="setupact.log" },
[pscustomobject]@{ Size=181064; Mode="-a----"; LastWriteTime="9/9/2015 11:54 PM"; Name="PSEXESVC.EXE" })
return $objs
}
filter addOneToSizeProperty() {
$_.Size += 1
$_
}
}
filter pipelineConsume() {
$_
+44 -44
View File
@@ -1,122 +1,122 @@
Describe "Test-Path" {
BeforeAll {
$testdirectory = $TestDrive
$testfilename = New-Item -path $testdirectory -Name testfile.txt -ItemType file -Value 1 -force
$testdirectory = $TestDrive
$testfilename = New-Item -path $testdirectory -Name testfile.txt -ItemType file -Value 1 -force
# populate with additional files
New-Item -Path $testdirectory -Name datestfile -value 1 -ItemType file | Out-Null
New-Item -Path $testdirectory -Name gatestfile -value 1 -ItemType file | Out-Null
New-Item -Path $testdirectory -Name usr -value 1 -ItemType directory | Out-Null
# populate with additional files
New-Item -Path $testdirectory -Name datestfile -value 1 -ItemType file | Out-Null
New-Item -Path $testdirectory -Name gatestfile -value 1 -ItemType file | Out-Null
New-Item -Path $testdirectory -Name usr -value 1 -ItemType directory | Out-Null
$nonExistantDir = Join-Path -Path (Join-Path -Path $testdirectory -ChildPath usr) -ChildPath bin
$nonExistantPath = Join-Path -Path (Join-Path -Path (Join-Path -Path $testdirectory -ChildPath usr) -ChildPath bin) -ChildPath error
$nonExistantDir = Join-Path -Path (Join-Path -Path $testdirectory -ChildPath usr) -ChildPath bin
$nonExistantPath = Join-Path -Path (Join-Path -Path (Join-Path -Path $testdirectory -ChildPath usr) -ChildPath bin) -ChildPath error
}
It "Should be called on an existing path without error" {
{ Test-Path $testdirectory } | Should Not Throw
{ Test-Path -Path $testdirectory } | Should Not Throw
{ Test-Path -LiteralPath $testdirectory } | Should Not Throw
{ Test-Path $testdirectory } | Should Not Throw
{ Test-Path -Path $testdirectory } | Should Not Throw
{ Test-Path -LiteralPath $testdirectory } | Should Not Throw
}
It "Should allow piping objects to it" {
{ $testdirectory | Test-Path } | Should Not Throw
{ $testdirectory | Test-Path } | Should Not Throw
$testdirectory | Test-Path | Should Be $true
$nonExistantDir | Test-Path | Should Be $false
$testdirectory | Test-Path | Should Be $true
$nonExistantDir | Test-Path | Should Be $false
}
It "Should be called on a nonexistant path without error" {
{ Test-Path -Path $nonExistantPath } | Should Not Throw
{ Test-Path -Path $nonExistantPath } | Should Not Throw
}
It "Should return false for a nonexistant path" {
Test-Path -Path $nonExistantPath | Should Be $false
Test-Path -Path $nonExistantPath | Should Be $false
}
It "Should return true for an existing path" {
{ Test-Path -Path $testdirectory } | Should Be $true
{ Test-Path -Path $testdirectory } | Should Be $true
}
It "Should be able to accept a regular expression" {
{ Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u*") } | Should Not Throw
{ Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u[a-z]r") } | Should Not Throw
{ Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u*") } | Should Not Throw
{ Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u[a-z]r") } | Should Not Throw
}
It "Should be able to return the correct result when a regular expression is used" {
Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u*") | Should Be $true
Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u[a-z]*") | Should Be $true
Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u*") | Should Be $true
Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u[a-z]*") | Should Be $true
Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "aoeu*") | Should Be $false
Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u[A-Z]") | Should Be $false
Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "aoeu*") | Should Be $false
Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u[A-Z]") | Should Be $false
}
It "Should return false when the Leaf pathtype is used on a directory" {
Test-Path -Path $testdirectory -PathType Leaf | Should Be $false
Test-Path -Path $testdirectory -PathType Leaf | Should Be $false
}
It "Should return true when the Leaf pathtype is used on an existing endpoint" {
Test-Path -Path $testfilename -PathType Leaf | Should Be $true
Test-Path -Path $testfilename -PathType Leaf | Should Be $true
}
It "Should return false when the Leaf pathtype is used on a nonexistant file" {
Test-Path -Path "aoeu" -PathType Leaf | Should Be $false
Test-Path -Path "aoeu" -PathType Leaf | Should Be $false
}
It "Should return true when the Leaf pathtype is used on a file using the Type alias instead of PathType" {
Test-Path -Path $testfilename -Type Leaf | Should Be $true
Test-Path -Path $testfilename -Type Leaf | Should Be $true
}
It "Should be able to search multiple regular expressions using the include switch" {
{ Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "*") -Include t* } | Should Be $true
{ Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "*") -Include t* } | Should Be $true
}
It "Should be able to exclude a regular expression using the exclude switch" {
{ Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "*") -Exclude v* } | Should Be $true
{ Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "*") -Exclude v* } | Should Be $true
}
It "Should be able to exclude multiple regular expressions using the exclude switch" {
# tests whether there's any files in the usr directory that don't start with 'd' or 'g'
{ Test-Path -Path $testfilename -Exclude d*, g* } | Should Be $true
# tests whether there's any files in the usr directory that don't start with 'd' or 'g'
{ Test-Path -Path $testfilename -Exclude d*, g* } | Should Be $true
}
It "Should return true if the syntax of the path is correct when using the IsValid switch" {
{ Test-Path -Path $nonExistantPath -IsValid } | Should Be $true
{ Test-Path -Path $nonExistantPath -IsValid } | Should Be $true
}
It "Should return false if the syntax of the path is incorrect when using the IsValid switch" {
$badPath = " :;!@#$%^&*(){}?+|_-"
Test-Path -Path $badPath -IsValid | Should Be $false
$badPath = " :;!@#$%^&*(){}?+|_-"
Test-Path -Path $badPath -IsValid | Should Be $false
}
It "Should return true on paths containing spaces when the path is surrounded in quotes" {
Test-Path -Path "/totally a valid/path" -IsValid | Should Be $true
Test-Path -Path "/totally a valid/path" -IsValid | Should Be $true
}
It "Should throw on paths containing spaces when the path is not surrounded in quotes" {
{ Test-Path -Path /a path/without quotes/around/it -IsValid } | Should Throw
{ Test-Path -Path /a path/without quotes/around/it -IsValid } | Should Throw
}
It "Should return true if a directory leads or trails with a space when surrounded by quotes" {
Test-Path -Path "/a path / with/funkyspaces" -IsValid | Should Be $true
Test-Path -Path "/a path / with/funkyspaces" -IsValid | Should Be $true
}
It "Should return true on a valid path when the LiteralPath switch is used" {
Test-Path -LiteralPath $testfilename | Should Be $true
Test-Path -LiteralPath $testfilename | Should Be $true
}
It "Should return false if regular expressions are used with the LiteralPath switch" {
Test-Path -LiteralPath (Join-Path -Path $testdirectory -ChildPath "u*") | Should Be $false
Test-Path -LiteralPath (Join-Path -Path $testdirectory -ChildPath "u[a-z]r") | Should Be $false
Test-Path -LiteralPath (Join-Path -Path $testdirectory -ChildPath "u*") | Should Be $false
Test-Path -LiteralPath (Join-Path -Path $testdirectory -ChildPath "u[a-z]r") | Should Be $false
}
It "Should return false if regular expressions are used with the LiteralPath alias PSPath switch" {
Test-Path -PSPath (Join-Path -Path $testdirectory -ChildPath "u*") | Should Be $false
Test-Path -PSPath (Join-Path -Path $testdirectory -ChildPath "u[a-z]r") | Should Be $false
Test-Path -PSPath (Join-Path -Path $testdirectory -ChildPath "u*") | Should Be $false
Test-Path -PSPath (Join-Path -Path $testdirectory -ChildPath "u[a-z]r") | Should Be $false
}
It "Should return true if used on components other than filesystem objects" {
Test-Path Alias:\gci | Should Be $true
Test-Path Env:\PATH | Should Be $true
Test-Path Alias:\gci | Should Be $true
Test-Path Env:\PATH | Should Be $true
}
}
+2 -2
View File
@@ -2,12 +2,12 @@ Describe "Update-FormatData" {
Context "Validate Update-FormatData update correctly" {
It "Should not throw upon reloading previous formatting file" {
It "Should not throw upon reloading previous formatting file" {
{ Update-FormatData } | Should Not throw
}
It "Should validly load formatting data" {
{ Get-FormatData -typename System.Diagnostics.Process | Export-FormatData -Path "outputfile.ps1xml" }
{ Get-FormatData -typename System.Diagnostics.Process | Export-FormatData -Path "outputfile.ps1xml" }
{ Update-FormatData -prependPath "outputfile.ps1xml" | Should Not throw }
{ Remove-Item "outputfile.ps1xml" -ErrorAction SilentlyContinue }
}
+8 -8
View File
@@ -2,14 +2,14 @@ Describe "Update-TypeData" {
Context "Validate Update-Type updates correctly" {
It "Should not throw upon reloading previous formatting file" {
{ Update-TypeData } | Should Not throw
}
It "Should not throw upon reloading previous formatting file" {
{ Update-TypeData } | Should Not throw
}
It "Should validly load formatting data" {
{ Get-TypeData -typename System.Diagnostics.Process | Export-TypeData -Path "outputfile.ps1xml" }
{ Update-TypeData -prependPath "outputfile.ps1xml" | Should Not throw }
{ Remove-Item "outputfile.ps1xml" -ErrorAction SilentlyContinue }
}
It "Should validly load formatting data" {
{ Get-TypeData -typename System.Diagnostics.Process | Export-TypeData -Path "outputfile.ps1xml" }
{ Update-TypeData -prependPath "outputfile.ps1xml" | Should Not throw }
{ Remove-Item "outputfile.ps1xml" -ErrorAction SilentlyContinue }
}
}
}
+9 -9
View File
@@ -3,13 +3,13 @@ Describe "Wait-Event" {
Context "Validate Wait-Event is waiting for events" {
It "Should time out when it does not receive a FakeEvent" {
# Don't depend on Measure-Command
$stopwatch = [System.Diagnostics.Stopwatch]::startNew()
# Testing the the timeout, so wait for an event that will never be
# raised because it is fake
Wait-Event -Timeout 1 -SourceIdentifier "FakeEvent"
$stopwatch.Stop()
$stopwatch.ElapsedMilliseconds | Should BeGreaterThan 500
$stopwatch.ElapsedMilliseconds | Should BeLessThan 1500
}
}
$stopwatch = [System.Diagnostics.Stopwatch]::startNew()
# Testing the the timeout, so wait for an event that will never be
# raised because it is fake
Wait-Event -Timeout 1 -SourceIdentifier "FakeEvent"
$stopwatch.Stop()
$stopwatch.ElapsedMilliseconds | Should BeGreaterThan 500
$stopwatch.ElapsedMilliseconds | Should BeLessThan 1500
}
}
}
+20 -20
View File
@@ -1,35 +1,35 @@
Describe "Write-Error" {
It "Should be able to throw" {
Write-Error "test throw" -ErrorAction SilentlyContinue | Should Throw
Write-Error "test throw" -ErrorAction SilentlyContinue | Should Throw
}
It "Should throw a non-terminating error" {
Write-Error "test throw" -ErrorAction SilentlyContinue
Write-Error "test throw" -ErrorAction SilentlyContinue
1 + 1 | Should Be 2
1 + 1 | Should Be 2
}
It "Should trip an exception using the exception switch" {
$var = 0
try
{
Write-Error -Exception -Message "test throw"
}
catch [System.Exception]
{
$var++
}
finally
{
$var | Should Be 1
}
$var = 0
try
{
Write-Error -Exception -Message "test throw"
}
catch [System.Exception]
{
$var++
}
finally
{
$var | Should Be 1
}
}
It "Should output the error message to the `$error automatic variable" {
$theError = "Error: Too many input values."
write-error -message $theError -category InvalidArgument -ErrorAction SilentlyContinue
$theError = "Error: Too many input values."
write-error -message $theError -category InvalidArgument -ErrorAction SilentlyContinue
$error[0]| Should Be $theError
$error[0]| Should Be $theError
}
}
+42 -42
View File
@@ -1,68 +1,68 @@
Describe "Write-Output" {
$testString = $testString
Context "Input Tests" {
It "Should allow piped input" {
{ $testString | Write-Output } | Should Not Throw
}
It "Should allow piped input" {
{ $testString | Write-Output } | Should Not Throw
}
It "Should write output to the output stream when using piped input" {
$testString | Write-Output | Should Be $testString
}
It "Should write output to the output stream when using piped input" {
$testString | Write-Output | Should Be $testString
}
It "Should use inputobject switch" {
{ Write-Output -InputObject $testString } | Should Not Throw
}
It "Should use inputobject switch" {
{ Write-Output -InputObject $testString } | Should Not Throw
}
It "Should write output to the output stream when using inputobject switch" {
Write-Output -InputObject $testString | Should Be $testString
}
It "Should write output to the output stream when using inputobject switch" {
Write-Output -InputObject $testString | Should Be $testString
}
It "Should be able to write to a variable" {
Write-Output -InputObject $testString -OutVariable var
$var | Should Be $testString
}
It "Should be able to write to a variable" {
Write-Output -InputObject $testString -OutVariable var
$var | Should Be $testString
}
}
Context "Pipeline Command Tests" {
It "Should send object to the next command in the pipeline" {
Write-Output -InputObject (1+1) | Should Be 2
}
It "Should send object to the next command in the pipeline" {
Write-Output -InputObject (1+1) | Should Be 2
}
It "Should have the same result between inputobject switch and piped input" {
Write-Output -InputObject (1+1) | Should Be 2
It "Should have the same result between inputobject switch and piped input" {
Write-Output -InputObject (1+1) | Should Be 2
1+1 | Write-Output | Should Be 2
}
1+1 | Write-Output | Should Be 2
}
}
Context "Alias Tests" {
It "Should have the same result between the echo alias and the cmdlet" {
$alias = echo -InputObject $testString
$cmdlet = Write-Output -InputObject $testString
It "Should have the same result between the echo alias and the cmdlet" {
$alias = echo -InputObject $testString
$cmdlet = Write-Output -InputObject $testString
$alias | Should Be $cmdlet
}
$alias | Should Be $cmdlet
}
It "Should have the same result between the write alias and the cmdlet" {
$alias = write -InputObject $testString
$cmdlet = Write-Output -InputObject $testString
It "Should have the same result between the write alias and the cmdlet" {
$alias = write -InputObject $testString
$cmdlet = Write-Output -InputObject $testString
$alias | Should Be $cmdlet
}
$alias | Should Be $cmdlet
}
}
Context "Enumerate Objects" {
$enumerationObject = @(1,2,3)
It "Should see individual objects when not using the NoEnumerate switch" {
$singleCollection = $(Write-Output $enumerationObject| Measure-Object).Count
$enumerationObject = @(1,2,3)
It "Should see individual objects when not using the NoEnumerate switch" {
$singleCollection = $(Write-Output $enumerationObject| Measure-Object).Count
$singleCollection | Should Be $enumerationObject.length
}
$singleCollection | Should Be $enumerationObject.length
}
It "Should be able to treat a collection as a single object using the NoEnumerate switch" {
$singleCollection = $(Write-Output $enumerationObject -NoEnumerate | Measure-Object).Count
It "Should be able to treat a collection as a single object using the NoEnumerate switch" {
$singleCollection = $(Write-Output $enumerationObject -NoEnumerate | Measure-Object).Count
$singleCollection | Should Be 1
}
$singleCollection | Should Be 1
}
}
}
+38 -38
View File
@@ -5,67 +5,67 @@ Describe "Stream writer tests" {
# that would normally
function Write-Messages
{
[CmdletBinding()]
[CmdletBinding()]
param()
If ($PSBoundParameters['Debug']) { $DebugPreference = 'Continue' }
Write-Verbose "Verbose message"
param()
If ($PSBoundParameters['Debug']) { $DebugPreference = 'Continue' }
Write-Verbose "Verbose message"
Write-Debug "Debug message"
Write-Debug "Debug message"
}
function Get-OutputResults
{
# Get the contents of the targetfile.
# Make the array a string for less brittle testing
$output = $(Get-Content $args[0])
[String]::Join([Environment]::NewLine, $output )
# Get the contents of the targetfile.
# Make the array a string for less brittle testing
$output = $(Get-Content $args[0])
[String]::Join([Environment]::NewLine, $output )
return $output
return $output
}
Context "Redirect Stream Tests" {
# These tests validate that a stream is actually being written to by redirecting the output of that stream
# These tests validate that a stream is actually being written to by redirecting the output of that stream
AfterEach { Remove-Item $targetfile }
It "Should write warnings to the warning stream" {
Write-Warning "Test Warning" 3>&1 > $targetfile
AfterEach { Remove-Item $targetfile }
It "Should write warnings to the warning stream" {
Write-Warning "Test Warning" 3>&1 > $targetfile
Get-Content $targetfile | Should Be "Test Warning"
}
Get-Content $targetfile | Should Be "Test Warning"
}
It "Should write error messages to the error stream" {
Write-Error "Testing Error" 2>&1 > $targetfile
It "Should write error messages to the error stream" {
Write-Error "Testing Error" 2>&1 > $targetfile
$result = Get-OutputResults $targetfile
# The contents of the error stream should contain the expected text
$result -match ": Testing Error" | Should Be $true
}
$result = Get-OutputResults $targetfile
# The contents of the error stream should contain the expected text
$result -match ": Testing Error" | Should Be $true
}
It "Should write debug messages to the debug stream" {
Write-Messages -Debug -EA SilentlyContinue 5>&1 > $targetfile
It "Should write debug messages to the debug stream" {
Write-Messages -Debug -EA SilentlyContinue 5>&1 > $targetfile
$result = Get-OutputResults $targetfile
$result = Get-OutputResults $targetfile
# The contents of the debug stream should contain the expected text
$result -match "Debug Message" | Should Be $true
}
# The contents of the debug stream should contain the expected text
$result -match "Debug Message" | Should Be $true
}
It "Should write messages to the verbose stream" {
Write-Messages -Verbose 4>&1 > $targetfile
It "Should write messages to the verbose stream" {
Write-Messages -Verbose 4>&1 > $targetfile
$result = Get-OutputResults $targetfile
$result = Get-OutputResults $targetfile
# The contents of the debug stream should contain the expected text
$result -match "Verbose Message" | Should Be $true
}
# The contents of the debug stream should contain the expected text
$result -match "Verbose Message" | Should Be $true
}
}
Context "Error automatic variable" {
It "Should write error messages to the `$Error automatic variable" {
Write-Error "Test Error Message" -ErrorAction SilentlyContinue
It "Should write error messages to the `$Error automatic variable" {
Write-Error "Test Error Message" -ErrorAction SilentlyContinue
$Error[0] | Should Match "Test Error Message"
}
$Error[0] | Should Match "Test Error Message"
}
}
}
+9 -9
View File
@@ -1,29 +1,29 @@
Describe "Write-Verbose" {
It "Should be able to call cmdlet without error" {
{ Write-Verbose -Message "test" -ErrorAction SilentlyContinue } | Should Not Throw
{ Write-Verbose -Message "test" -ErrorAction SilentlyContinue } | Should Not Throw
}
It "Should not display verbose output by default" {
$VerbosePreference | Should Be SilentlyContinue
$VerbosePreference | Should Be SilentlyContinue
Write-Verbose -Message "test" | Should BeNullOrEmpty
Write-Verbose -Message "test" | Should BeNullOrEmpty
}
It "Should be able to set verbose output to display by changing the `$VerbosePreference automatic variable" {
$VerbosePreference = "Continue"
$VerbosePreference = "Continue"
Write-Verbose -Message "test" 4>&1 | Should Not BeNullOrEmpty
Write-Verbose -Message "test" 4>&1 | Should Not BeNullOrEmpty
$VerbosePreference = "SilentlyContinue"
$VerbosePreference = "SilentlyContinue"
}
It "Should be able to set verbose output to display by using the verbose switch" {
Write-Verbose -Message "test" -Verbose 4>&1 | Should Be "test"
Write-Verbose -Message "test" -Verbose 4>&1 | Should Be "test"
}
It "Should be able to set verbose switch using a colon and boolean" {
{ Write-Verbose -Message "test" -Verbose:$false } | Should Not Throw
{ Write-Verbose -Message "test" -Verbose:$false } | Should Not Throw
$(Write-Verbose -Message "test" -Verbose:$true) 4>&1 | Should Be "test"
$(Write-Verbose -Message "test" -Verbose:$true) 4>&1 | Should Be "test"
}
}