Convert Pester tests to ASCII
Instead of UTF-8 with BOM. Resolves #417.
This commit is contained in:
parent
901160cb78
commit
0aaf74bdcc
|
@ -1,4 +1,4 @@
|
|||
Describe "Clear-Variable" {
|
||||
Describe "Clear-Variable" {
|
||||
BeforeEach {
|
||||
$var1 = 3
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Compare-Object" {
|
||||
Describe "Compare-Object" {
|
||||
$nl = [Environment]::NewLine
|
||||
$slash = [System.IO.Path]::DirectorySeparatorChar
|
||||
$testDirectory = $HOME + $slash + "testDirectory"
|
||||
|
|
|
@ -1,52 +1,52 @@
|
|||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
|
||||
Describe "ConvertFrom-Csv" {
|
||||
$testObject = "a", "1"
|
||||
$testcsv = Join-Path -Path (Join-Path -Path $here -ChildPath assets) -ChildPath TestCsv2.csv
|
||||
$testName = "Zaphod BeebleBrox"
|
||||
$testColumns = @"
|
||||
a,b,c
|
||||
1,2,3
|
||||
"@
|
||||
It "Should be able to be called" {
|
||||
{ ConvertFrom-Csv -InputObject $testObject } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should be able to pipe" {
|
||||
{ $testObject | ConvertFrom-Csv } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should have expected results when using piped inputs" {
|
||||
$csvContent = Get-Content $testcsv
|
||||
$actualresult = $csvContent | ConvertFrom-Csv
|
||||
|
||||
$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
|
||||
}
|
||||
|
||||
It "Should be able to set a delimiter" {
|
||||
{ $testcsv | ConvertFrom-Csv -Delimiter ";" } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should actually delimit the output" {
|
||||
$csvContent = Get-Content $testcsv
|
||||
$actualresult = $csvContent | ConvertFrom-Csv -Delimiter ";"
|
||||
|
||||
$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)
|
||||
}
|
||||
|
||||
It "Should be able to have multiple columns" {
|
||||
$actualData = $testColumns | ConvertFrom-Csv
|
||||
|
||||
$actualLength = $($( $actualData | gm) | Where-Object {$_.MemberType -eq "NoteProperty" }).Length
|
||||
|
||||
$actualLength | Should Be 3
|
||||
}
|
||||
}
|
||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
|
||||
Describe "ConvertFrom-Csv" {
|
||||
$testObject = "a", "1"
|
||||
$testcsv = Join-Path -Path (Join-Path -Path $here -ChildPath assets) -ChildPath TestCsv2.csv
|
||||
$testName = "Zaphod BeebleBrox"
|
||||
$testColumns = @"
|
||||
a,b,c
|
||||
1,2,3
|
||||
"@
|
||||
It "Should be able to be called" {
|
||||
{ ConvertFrom-Csv -InputObject $testObject } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should be able to pipe" {
|
||||
{ $testObject | ConvertFrom-Csv } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should have expected results when using piped inputs" {
|
||||
$csvContent = Get-Content $testcsv
|
||||
$actualresult = $csvContent | ConvertFrom-Csv
|
||||
|
||||
$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
|
||||
}
|
||||
|
||||
It "Should be able to set a delimiter" {
|
||||
{ $testcsv | ConvertFrom-Csv -Delimiter ";" } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should actually delimit the output" {
|
||||
$csvContent = Get-Content $testcsv
|
||||
$actualresult = $csvContent | ConvertFrom-Csv -Delimiter ";"
|
||||
|
||||
$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)
|
||||
}
|
||||
|
||||
It "Should be able to have multiple columns" {
|
||||
$actualData = $testColumns | ConvertFrom-Csv
|
||||
|
||||
$actualLength = $($( $actualData | gm) | Where-Object {$_.MemberType -eq "NoteProperty" }).Length
|
||||
|
||||
$actualLength | Should Be 3
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,51 +1,51 @@
|
|||
Describe "ConvertFrom-StringData" {
|
||||
$sampleData = @'
|
||||
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
|
||||
}
|
||||
|
||||
It "Should return a 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
|
||||
}
|
||||
|
||||
It "Should return the data on the left side in the key" {
|
||||
$actualValue = ConvertFrom-StringData -StringData 'a=b'
|
||||
|
||||
$actualValue.Keys | Should Be "a"
|
||||
}
|
||||
|
||||
It "Should return the data on the right side in the value" {
|
||||
$actualValue = ConvertFrom-StringData -StringData 'a=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"
|
||||
}
|
||||
|
||||
It "Should return a valuecollection for the values" {
|
||||
$(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).Keys | Should Be "foo", "bar", "bazz"
|
||||
|
||||
$(ConvertFrom-StringData -StringData $sampleData).Values | Should Be "0","1","2"
|
||||
}
|
||||
Describe "ConvertFrom-StringData" {
|
||||
$sampleData = @'
|
||||
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
|
||||
}
|
||||
|
||||
It "Should return a 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
|
||||
}
|
||||
|
||||
It "Should return the data on the left side in the key" {
|
||||
$actualValue = ConvertFrom-StringData -StringData 'a=b'
|
||||
|
||||
$actualValue.Keys | Should Be "a"
|
||||
}
|
||||
|
||||
It "Should return the data on the right side in the value" {
|
||||
$actualValue = ConvertFrom-StringData -StringData 'a=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"
|
||||
}
|
||||
|
||||
It "Should return a valuecollection for the values" {
|
||||
$(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).Keys | Should Be "foo", "bar", "bazz"
|
||||
|
||||
$(ConvertFrom-StringData -StringData $sampleData).Values | Should Be "0","1","2"
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
Describe "DotNetAPI" {
|
||||
Describe "DotNetAPI" {
|
||||
$posh_E = 2.718281828459045
|
||||
$posh_pi = 3.14159265358979
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Environment-Variables" {
|
||||
Describe "Environment-Variables" {
|
||||
|
||||
It "Should have environment variables" {
|
||||
Get-Item ENV: | Should Not BeNullOrEmpty
|
||||
|
|
|
@ -1,33 +1,33 @@
|
|||
Describe "Export-Alias" {
|
||||
$testAliasDirectory = Join-Path -Path $TestDrive -ChildPath ExportAliasTestDirectory
|
||||
$testAliases = "TestAliases"
|
||||
$fulltestpath = Join-Path -Path $($testAliasDirectory) -ChildPath $($testAliases)
|
||||
|
||||
BeforeEach {
|
||||
New-Item -Path $testAliasDirectory -ItemType Directory -Force
|
||||
}
|
||||
|
||||
It "Should be able to create a file in the specified location"{
|
||||
Export-Alias $fulltestpath
|
||||
|
||||
Test-Path $fulltestpath | Should be $true
|
||||
}
|
||||
|
||||
It "Should create a file with the list of aliases that match the expected list" {
|
||||
Export-Alias $fulltestpath
|
||||
|
||||
Test-Path $fulltestpath | Should Be $true
|
||||
|
||||
$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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Remove-Item -Path $testAliasDirectory -Recurse -Force
|
||||
}
|
||||
Describe "Export-Alias" {
|
||||
$testAliasDirectory = Join-Path -Path $TestDrive -ChildPath ExportAliasTestDirectory
|
||||
$testAliases = "TestAliases"
|
||||
$fulltestpath = Join-Path -Path $($testAliasDirectory) -ChildPath $($testAliases)
|
||||
|
||||
BeforeEach {
|
||||
New-Item -Path $testAliasDirectory -ItemType Directory -Force
|
||||
}
|
||||
|
||||
It "Should be able to create a file in the specified location"{
|
||||
Export-Alias $fulltestpath
|
||||
|
||||
Test-Path $fulltestpath | Should be $true
|
||||
}
|
||||
|
||||
It "Should create a file with the list of aliases that match the expected list" {
|
||||
Export-Alias $fulltestpath
|
||||
|
||||
Test-Path $fulltestpath | Should Be $true
|
||||
|
||||
$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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Remove-Item -Path $testAliasDirectory -Recurse -Force
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Export-Csv" {
|
||||
Describe "Export-Csv" {
|
||||
$testObject = @("test","object","array")
|
||||
$testCsv = "output.csv"
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Format-Table" {
|
||||
Describe "Format-Table" {
|
||||
It "Should call format table on piped input without error" {
|
||||
{ Get-Process | Format-Table } | Should Not Throw
|
||||
|
||||
|
@ -36,4 +36,4 @@
|
|||
{ $v32 } | Should Not Throw
|
||||
{ $v42 } | Should Not Throw
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Format-Wide" {
|
||||
Describe "Format-Wide" {
|
||||
It "Should be able to call format wide without error" {
|
||||
{ Get-Process | Format-Wide } | Should Not Throw
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Get-Alias" {
|
||||
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*)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Get-ChildItem" {
|
||||
Describe "Get-ChildItem" {
|
||||
It "Should list the contents of the current folder" {
|
||||
(Get-ChildItem .).Name.Length | Should BeGreaterThan 0
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Get-Content" {
|
||||
Describe "Get-Content" {
|
||||
$testString = "This is a test content for a file"
|
||||
$nl = [Environment]::NewLine
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Get-Date" {
|
||||
Describe "Get-Date" {
|
||||
It "Should return a DateTime object upon being called" {
|
||||
(Get-Date).GetType().Name.Equals('DateTime') | Should Be $true
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Get-Item" {
|
||||
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[]'
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Get-ItemProperty" {
|
||||
Describe "Get-ItemProperty" {
|
||||
$currentDirectory = Split-Path $PSScriptRoot -Leaf
|
||||
$parentDirectory = Split-Path (Join-Path -Path $PSScriptRoot -ChildPath "..") -Leaf
|
||||
$tempDirectory = $TestDrive
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Get-Location" {
|
||||
Describe "Get-Location" {
|
||||
BeforeEach {
|
||||
pushd $env:HOME
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Get-Member" {
|
||||
Describe "Get-Member" {
|
||||
It "Should be able to be called on string objects, ints, arrays, etc" {
|
||||
$a = 1 #test numbers
|
||||
$b = 1.3
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Get-PSDrive" {
|
||||
Describe "Get-PSDrive" {
|
||||
|
||||
It "Should not throw" {
|
||||
Get-PSDrive | Should Not BeNullOrEmpty
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Get-PSProvider" {
|
||||
Describe "Get-PSProvider" {
|
||||
It "Should be able to call with no parameters without error" {
|
||||
{ Get-PSProvider } | Should Not Throw
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Get-Random" {
|
||||
Describe "Get-Random" {
|
||||
It "Should return a random number greater than -1 " {
|
||||
Get-Random | Should BeGreaterThan -1
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Get-Unique" {
|
||||
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
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Get-Variable" {
|
||||
Describe "Get-Variable" {
|
||||
It "Should be able to call with no parameters without error" {
|
||||
{ Get-Variable } | Should Not Throw
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Group-Object" {
|
||||
Describe "Group-Object" {
|
||||
$testObject = Get-ChildItem
|
||||
|
||||
It "Should be called using an object as piped without error with no switches" {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Import-Csv" {
|
||||
Describe "Import-Csv" {
|
||||
$testCsv = Join-Path -Path (Join-Path $PSScriptRoot -ChildPath assets) -ChildPath TestCsv.csv
|
||||
|
||||
It "Should be able to call without error" {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Measure-Object" {
|
||||
Describe "Measure-Object" {
|
||||
$testObject = 1,3,4
|
||||
|
||||
It "Should be able to be called without error" {
|
||||
|
@ -126,9 +126,9 @@
|
|||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "New-Alias" {
|
||||
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
|
||||
}
|
||||
|
@ -31,4 +31,4 @@
|
|||
$aliasData[$IdNumber] | Should Be $cmdletData[$IdNumber]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
function Clean-State
|
||||
function Clean-State
|
||||
{
|
||||
if (Test-Path $FullyQualifiedLink)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "New-Object" {
|
||||
Describe "New-Object" {
|
||||
It "should create an object with 4 fields" {
|
||||
$o = New-Object psobject
|
||||
$val = $o.GetType()
|
||||
|
|
|
@ -1,46 +1,46 @@
|
|||
Describe "New-TimeSpan" {
|
||||
It "Should be able to create a new timespan object" {
|
||||
New-Variable -Name testObject -Value $(New-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
|
||||
|
||||
$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
|
||||
|
||||
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
|
||||
|
||||
$difference = [math]::Abs($inputParameter.Milliseconds - $pipedInput.Milliseconds)
|
||||
# The difference between commands should be minimal
|
||||
$difference | Should BeLessThan 100
|
||||
}
|
||||
}
|
||||
Describe "New-TimeSpan" {
|
||||
It "Should be able to create a new timespan object" {
|
||||
New-Variable -Name testObject -Value $(New-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
|
||||
|
||||
$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
|
||||
|
||||
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
|
||||
|
||||
$difference = [math]::Abs($inputParameter.Milliseconds - $pipedInput.Milliseconds)
|
||||
# The difference between commands should be minimal
|
||||
$difference | Should BeLessThan 100
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "New-Variable" {
|
||||
Describe "New-Variable" {
|
||||
$nl = [Environment]::NewLine
|
||||
|
||||
It "Should create a new variable with no parameters" {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Out-File" {
|
||||
Describe "Out-File" {
|
||||
$expectedContent = "some test text"
|
||||
$inObject = New-Object psobject -Property @{text=$expectedContent}
|
||||
$testfile = Join-Path -Path $TestDrive -ChildPath outfileTest.txt
|
||||
|
|
|
@ -1,37 +1,37 @@
|
|||
Describe "Out-String" {
|
||||
$nl = [Environment]::NewLine
|
||||
|
||||
It "Should accumulate the strings and returns them as a single string" {
|
||||
$testArray = "a", " b"
|
||||
|
||||
$testArray.GetType().BaseType | Should Be array
|
||||
|
||||
$testArray | Out-String | Should Be "a$nl b$nl"
|
||||
|
||||
$($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 | Out-String).GetType() | Should Be string
|
||||
|
||||
$($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
|
||||
|
||||
$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
|
||||
|
||||
$streamoutputlength | Should BeLessThan $nonstreamoutputlength
|
||||
}
|
||||
}
|
||||
Describe "Out-String" {
|
||||
$nl = [Environment]::NewLine
|
||||
|
||||
It "Should accumulate the strings and returns them as a single string" {
|
||||
$testArray = "a", " b"
|
||||
|
||||
$testArray.GetType().BaseType | Should Be array
|
||||
|
||||
$testArray | Out-String | Should Be "a$nl b$nl"
|
||||
|
||||
$($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 | Out-String).GetType() | Should Be string
|
||||
|
||||
$($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
|
||||
|
||||
$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
|
||||
|
||||
$streamoutputlength | Should BeLessThan $nonstreamoutputlength
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "PSVersionTable" {
|
||||
Describe "PSVersionTable" {
|
||||
It "Should have version table entries" {
|
||||
$PSVersionTable.Count | Should Be 8
|
||||
}
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
Describe "Pop-Location" {
|
||||
$startDirectory = $(Get-Location).Path
|
||||
|
||||
BeforeEach { Set-Location $startDirectory }
|
||||
|
||||
It "Should be able to be called without error" {
|
||||
{ Pop-Location } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should not take a parameter" {
|
||||
{ Pop-Location .. } | Should Throw
|
||||
}
|
||||
|
||||
It "Should be able pop multiple times" {
|
||||
Push-Location ..
|
||||
Push-Location ..
|
||||
Push-Location ..
|
||||
|
||||
Pop-Location
|
||||
Pop-Location
|
||||
Pop-Location
|
||||
|
||||
$(Get-Location).Path | Should Be $startDirectory
|
||||
|
||||
}
|
||||
|
||||
Set-Location $startDirectory
|
||||
Describe "Pop-Location" {
|
||||
$startDirectory = $(Get-Location).Path
|
||||
|
||||
BeforeEach { Set-Location $startDirectory }
|
||||
|
||||
It "Should be able to be called without error" {
|
||||
{ Pop-Location } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should not take a parameter" {
|
||||
{ Pop-Location .. } | Should Throw
|
||||
}
|
||||
|
||||
It "Should be able pop multiple times" {
|
||||
Push-Location ..
|
||||
Push-Location ..
|
||||
Push-Location ..
|
||||
|
||||
Pop-Location
|
||||
Pop-Location
|
||||
Pop-Location
|
||||
|
||||
$(Get-Location).Path | Should Be $startDirectory
|
||||
|
||||
}
|
||||
|
||||
Set-Location $startDirectory
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Test-Push-Location" {
|
||||
Describe "Test-Push-Location" {
|
||||
New-Variable -Name startDirectory -Value $(Get-Location).Path -Scope Global -Force
|
||||
|
||||
BeforeEach { cd $startDirectory }
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Remove-Item" {
|
||||
Describe "Remove-Item" {
|
||||
$testpath = $TestDrive
|
||||
$testfile = "testfile.txt"
|
||||
$testfilepath = Join-Path -Path $testpath -ChildPath $testfile
|
||||
|
|
|
@ -1,74 +1,74 @@
|
|||
Describe "Remove-PSBreakpoint" {
|
||||
# Set up test script
|
||||
$testScript = Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath psbreakpointtestscript.ps1
|
||||
|
||||
$script = "`$var = 1
|
||||
`$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
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
$(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
|
||||
|
||||
$(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
|
||||
|
||||
$(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
|
||||
|
||||
$(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
|
||||
|
||||
$(Get-PSBreakpoint).Id.length | Should Be ($NumberOfBreakpoints -1)
|
||||
}
|
||||
}
|
||||
|
||||
It "Should Remove all breakpoints" {
|
||||
$(Get-PSBreakpoint).Id.Length | Should Not BeNullOrEmpty
|
||||
|
||||
Get-PSBreakpoint | Remove-PSBreakpoint
|
||||
|
||||
$(Get-PSBreakpoint).Id.Length | Should Be 0
|
||||
}
|
||||
|
||||
|
||||
#Clean up after ourselves
|
||||
|
||||
Remove-Item $testScript
|
||||
}
|
||||
Describe "Remove-PSBreakpoint" {
|
||||
# Set up test script
|
||||
$testScript = Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath psbreakpointtestscript.ps1
|
||||
|
||||
$script = "`$var = 1
|
||||
`$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
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
$(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
|
||||
|
||||
$(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
|
||||
|
||||
$(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
|
||||
|
||||
$(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
|
||||
|
||||
$(Get-PSBreakpoint).Id.length | Should Be ($NumberOfBreakpoints -1)
|
||||
}
|
||||
}
|
||||
|
||||
It "Should Remove all breakpoints" {
|
||||
$(Get-PSBreakpoint).Id.Length | Should Not BeNullOrEmpty
|
||||
|
||||
Get-PSBreakpoint | Remove-PSBreakpoint
|
||||
|
||||
$(Get-PSBreakpoint).Id.Length | Should Be 0
|
||||
}
|
||||
|
||||
|
||||
#Clean up after ourselves
|
||||
|
||||
Remove-Item $testScript
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# ensure the machine is in a clean state from the outset.
|
||||
# ensure the machine is in a clean state from the outset.
|
||||
Remove-Variable -Name var1 -ErrorAction SilentlyContinue -Force
|
||||
|
||||
Describe "Remove-Variable" {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
. (Join-Path -Path $PSScriptRoot -ChildPath Test-Mocks.ps1)
|
||||
. (Join-Path -Path $PSScriptRoot -ChildPath Test-Mocks.ps1)
|
||||
|
||||
Describe "Select-Object" {
|
||||
BeforeEach {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Select-String" {
|
||||
Describe "Select-String" {
|
||||
$nl = [Environment]::NewLine
|
||||
$currentDirectory = $pwd.Path
|
||||
Context "String actions" {
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
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
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
It "Should be able to use the sal alias" {
|
||||
{ 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
|
||||
|
||||
Set-Alias -Name gd2 -Value Get-Date
|
||||
|
||||
gd2 | Should Be $(gd)
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
It "Should be able to use the sal alias" {
|
||||
{ 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
|
||||
|
||||
Set-Alias -Name gd2 -Value Get-Date
|
||||
|
||||
gd2 | Should Be $(gd)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Set-Location" {
|
||||
Describe "Set-Location" {
|
||||
$startDirectory = Get-Location
|
||||
|
||||
if ($IsWindows)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Set-PSBreakpoint" {
|
||||
Describe "Set-PSBreakpoint" {
|
||||
# Set up test script
|
||||
$testScript = Join-Path -Path $PSScriptRoot -ChildPath psbreakpointtestscript.ps1
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Set-PSDebug" {
|
||||
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" {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Set-Variable" {
|
||||
Describe "Set-Variable" {
|
||||
${nl} = [Environment]::Newline
|
||||
|
||||
It "Should create a new variable with no parameters" {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Split-Path" {
|
||||
Describe "Split-Path" {
|
||||
if ($IsWindows)
|
||||
{
|
||||
$qualifier = "C:"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Describe "Start-Process" {
|
||||
Describe "Start-Process" {
|
||||
$pingCommand = (Get-Command -CommandType Application ping)[0].Definition
|
||||
$pingDirectory = Split-Path $pingCommand -Parent
|
||||
$tempFile = Join-Path -Path $TestDrive -ChildPath PSTest
|
||||
|
|
|
@ -1,35 +1,35 @@
|
|||
Describe "Write-Error" {
|
||||
It "Should be able to throw" {
|
||||
Write-Error "test throw" -ErrorAction SilentlyContinue | Should Throw
|
||||
}
|
||||
|
||||
It "Should throw a non-terminating error" {
|
||||
Write-Error "test throw" -ErrorAction SilentlyContinue
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
$error[0]| Should Be $theError
|
||||
}
|
||||
Describe "Write-Error" {
|
||||
It "Should be able to throw" {
|
||||
Write-Error "test throw" -ErrorAction SilentlyContinue | Should Throw
|
||||
}
|
||||
|
||||
It "Should throw a non-terminating error" {
|
||||
Write-Error "test throw" -ErrorAction SilentlyContinue
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
$error[0]| Should Be $theError
|
||||
}
|
||||
}
|
|
@ -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 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 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
|
||||
}
|
||||
}
|
||||
|
||||
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 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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
$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
|
||||
|
||||
$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
|
||||
|
||||
$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
|
||||
|
||||
$singleCollection | Should Be 1
|
||||
}
|
||||
}
|
||||
}
|
||||
Describe "Write-Output" {
|
||||
$testString = $testString
|
||||
Context "Input Tests" {
|
||||
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 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 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 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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
$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
|
||||
|
||||
$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
|
||||
|
||||
$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
|
||||
|
||||
$singleCollection | Should Be 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
It "Should not display verbose output by default" {
|
||||
$VerbosePreference | Should Be SilentlyContinue
|
||||
|
||||
Write-Verbose -Message "test" | Should BeNullOrEmpty
|
||||
}
|
||||
|
||||
It "Should be able to set verbose output to display by changing the `$VerbosePreference automatic variable" {
|
||||
$VerbosePreference = "Continue"
|
||||
|
||||
Write-Verbose -Message "test" 4>&1 | Should Not BeNullOrEmpty
|
||||
|
||||
$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"
|
||||
}
|
||||
|
||||
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:$true) 4>&1 | Should Be "test"
|
||||
}
|
||||
Describe "Write-Verbose" {
|
||||
It "Should be able to call cmdlet without error" {
|
||||
{ Write-Verbose -Message "test" -ErrorAction SilentlyContinue } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should not display verbose output by default" {
|
||||
$VerbosePreference | Should Be SilentlyContinue
|
||||
|
||||
Write-Verbose -Message "test" | Should BeNullOrEmpty
|
||||
}
|
||||
|
||||
It "Should be able to set verbose output to display by changing the `$VerbosePreference automatic variable" {
|
||||
$VerbosePreference = "Continue"
|
||||
|
||||
Write-Verbose -Message "test" 4>&1 | Should Not BeNullOrEmpty
|
||||
|
||||
$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"
|
||||
}
|
||||
|
||||
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:$true) 4>&1 | Should Be "test"
|
||||
}
|
||||
}
|
131
test/powershell/foo
Normal file
131
test/powershell/foo
Normal file
|
@ -0,0 +1,131 @@
|
|||
Describe "Measure-Object" {
|
||||
$testObject = 1,3,4
|
||||
|
||||
It "Should be able to be called without error" {
|
||||
{ Measure-Object | Out-Null } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should be able to call on piped input" {
|
||||
{ $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
|
||||
}
|
||||
|
||||
It "Should be able to count using the Property switch" {
|
||||
$expected = $(Get-ChildItem).Length
|
||||
$actual = $(Get-ChildItem | Measure-Object -Property Length).Count
|
||||
|
||||
$actual | Should Be $expected
|
||||
}
|
||||
|
||||
It "Should be able to get additional stats" {
|
||||
$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
|
||||
}
|
||||
|
||||
Context "Numeric tests" {
|
||||
It "Should be able to sum" {
|
||||
$actual = $testObject | Measure-Object -Sum
|
||||
$expected = 0
|
||||
|
||||
foreach ( $obj in $testObject )
|
||||
{
|
||||
$expected += $obj
|
||||
}
|
||||
|
||||
$actual.Sum | Should Be $expected
|
||||
}
|
||||
|
||||
It "Should be able to average" {
|
||||
$actual = $testObject | Measure-Object -Average
|
||||
$expected = 0
|
||||
|
||||
foreach ( $obj in $testObject )
|
||||
{
|
||||
$expected += $obj
|
||||
}
|
||||
|
||||
$expected /= $testObject.length
|
||||
|
||||
$actual.Average | Should Be $expected
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
|
||||
$expected = $testObject[$i]
|
||||
}
|
||||
}
|
||||
|
||||
$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]
|
||||
|
||||
for ($i=1; $i -lt $testMinimum.length; $i++)
|
||||
{
|
||||
if ( $testMinimum[$i] -lt $expected )
|
||||
{
|
||||
|
||||
$expected = $testMinimum[$i]
|
||||
}
|
||||
}
|
||||
|
||||
$actual.Minimum | Should Be $expected
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
|
||||
$expected = $testObject[$i]
|
||||
}
|
||||
}
|
||||
|
||||
$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]
|
||||
|
||||
for ($i=1; $i -lt $testMaximum.length; $i++)
|
||||
{
|
||||
if ( $testMaximum[$i] -gt $expected )
|
||||
{
|
||||
|
||||
$expected = $testMaximum[$i]
|
||||
}
|
||||
}
|
||||
|
||||
$actual.Maximum | Should Be $expected
|
||||
}
|
||||
}
|
||||
|
||||
Context "String tests" {
|
||||
$nl = [Environment]::NewLine
|
||||
|
||||
$testString = "HAD I the heavens
|
Loading…
Reference in a new issue