diff --git a/test/powershell/Clear-Variable.Tests.ps1 b/test/powershell/Clear-Variable.Tests.ps1 index 55340ce587..420cfebd13 100644 --- a/test/powershell/Clear-Variable.Tests.ps1 +++ b/test/powershell/Clear-Variable.Tests.ps1 @@ -1,4 +1,4 @@ -Describe "Clear-Variable" { +Describe "Clear-Variable" { BeforeEach { $var1 = 3 } diff --git a/test/powershell/Compare-Object.Tests.ps1 b/test/powershell/Compare-Object.Tests.ps1 index cc558b27bb..92d469c344 100644 --- a/test/powershell/Compare-Object.Tests.ps1 +++ b/test/powershell/Compare-Object.Tests.ps1 @@ -1,4 +1,4 @@ -Describe "Compare-Object" { +Describe "Compare-Object" { $nl = [Environment]::NewLine $slash = [System.IO.Path]::DirectorySeparatorChar $testDirectory = $HOME + $slash + "testDirectory" diff --git a/test/powershell/ConvertFrom-Csv.Tests.ps1 b/test/powershell/ConvertFrom-Csv.Tests.ps1 index 572ebafe5e..88e026c6c7 100644 --- a/test/powershell/ConvertFrom-Csv.Tests.ps1 +++ b/test/powershell/ConvertFrom-Csv.Tests.ps1 @@ -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 + } +} diff --git a/test/powershell/ConvertFrom-StringData.Tests.ps1 b/test/powershell/ConvertFrom-StringData.Tests.ps1 index c91b7cf1ad..b905040d30 100644 --- a/test/powershell/ConvertFrom-StringData.Tests.ps1 +++ b/test/powershell/ConvertFrom-StringData.Tests.ps1 @@ -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" + } } \ No newline at end of file diff --git a/test/powershell/DotNetAPI.Tests.ps1 b/test/powershell/DotNetAPI.Tests.ps1 index cb98ed7ab5..28b6c94eef 100644 --- a/test/powershell/DotNetAPI.Tests.ps1 +++ b/test/powershell/DotNetAPI.Tests.ps1 @@ -1,4 +1,4 @@ -Describe "DotNetAPI" { +Describe "DotNetAPI" { $posh_E = 2.718281828459045 $posh_pi = 3.14159265358979 diff --git a/test/powershell/Environment-Variables.Tests.ps1 b/test/powershell/Environment-Variables.Tests.ps1 index c0f26d5329..ec31cc46fa 100644 --- a/test/powershell/Environment-Variables.Tests.ps1 +++ b/test/powershell/Environment-Variables.Tests.ps1 @@ -1,4 +1,4 @@ -Describe "Environment-Variables" { +Describe "Environment-Variables" { It "Should have environment variables" { Get-Item ENV: | Should Not BeNullOrEmpty diff --git a/test/powershell/Export-Alias.Tests.ps1 b/test/powershell/Export-Alias.Tests.ps1 index 88a228b564..f756d43383 100644 --- a/test/powershell/Export-Alias.Tests.ps1 +++ b/test/powershell/Export-Alias.Tests.ps1 @@ -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 +} diff --git a/test/powershell/Export-Csv.Tests.ps1 b/test/powershell/Export-Csv.Tests.ps1 index bbcaef0a5e..1c8c3abd84 100644 --- a/test/powershell/Export-Csv.Tests.ps1 +++ b/test/powershell/Export-Csv.Tests.ps1 @@ -1,4 +1,4 @@ -Describe "Export-Csv" { +Describe "Export-Csv" { $testObject = @("test","object","array") $testCsv = "output.csv" diff --git a/test/powershell/Format-Table.Tests.ps1 b/test/powershell/Format-Table.Tests.ps1 index b34cfbe192..e0cdf6d1fb 100644 --- a/test/powershell/Format-Table.Tests.ps1 +++ b/test/powershell/Format-Table.Tests.ps1 @@ -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 } -} +} diff --git a/test/powershell/Format-Wide.Tests.ps1 b/test/powershell/Format-Wide.Tests.ps1 index 49b771ef8f..8e2ca9e8d2 100644 --- a/test/powershell/Format-Wide.Tests.ps1 +++ b/test/powershell/Format-Wide.Tests.ps1 @@ -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 } diff --git a/test/powershell/Get-Alias.Tests.ps1 b/test/powershell/Get-Alias.Tests.ps1 index 3c51fef2f3..41a8791d96 100644 --- a/test/powershell/Get-Alias.Tests.ps1 +++ b/test/powershell/Get-Alias.Tests.ps1 @@ -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*) diff --git a/test/powershell/Get-ChildItem.Tests.ps1 b/test/powershell/Get-ChildItem.Tests.ps1 index 2b55d1ec0b..10cf54d5df 100644 --- a/test/powershell/Get-ChildItem.Tests.ps1 +++ b/test/powershell/Get-ChildItem.Tests.ps1 @@ -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 } diff --git a/test/powershell/Get-Content.Tests.ps1 b/test/powershell/Get-Content.Tests.ps1 index fe4b16e635..a48edb754f 100644 --- a/test/powershell/Get-Content.Tests.ps1 +++ b/test/powershell/Get-Content.Tests.ps1 @@ -1,4 +1,4 @@ -Describe "Get-Content" { +Describe "Get-Content" { $testString = "This is a test content for a file" $nl = [Environment]::NewLine diff --git a/test/powershell/Get-Date.Tests.ps1 b/test/powershell/Get-Date.Tests.ps1 index ba9d144f5e..876900027f 100644 --- a/test/powershell/Get-Date.Tests.ps1 +++ b/test/powershell/Get-Date.Tests.ps1 @@ -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 } diff --git a/test/powershell/Get-Item.Tests.ps1 b/test/powershell/Get-Item.Tests.ps1 index 3dd6acafcb..b648af0fd3 100644 --- a/test/powershell/Get-Item.Tests.ps1 +++ b/test/powershell/Get-Item.Tests.ps1 @@ -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[]' diff --git a/test/powershell/Get-ItemProperty.Tests.ps1 b/test/powershell/Get-ItemProperty.Tests.ps1 index 33dfe8c612..4addf0023d 100644 --- a/test/powershell/Get-ItemProperty.Tests.ps1 +++ b/test/powershell/Get-ItemProperty.Tests.ps1 @@ -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 diff --git a/test/powershell/Get-Location.Tests.ps1 b/test/powershell/Get-Location.Tests.ps1 index 7a5dee9c61..45f04fddbd 100644 --- a/test/powershell/Get-Location.Tests.ps1 +++ b/test/powershell/Get-Location.Tests.ps1 @@ -1,4 +1,4 @@ -Describe "Get-Location" { +Describe "Get-Location" { BeforeEach { pushd $env:HOME } diff --git a/test/powershell/Get-Member.Tests.ps1 b/test/powershell/Get-Member.Tests.ps1 index 4bba9598ed..371b78ef19 100644 --- a/test/powershell/Get-Member.Tests.ps1 +++ b/test/powershell/Get-Member.Tests.ps1 @@ -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 diff --git a/test/powershell/Get-PSDrive.Tests.ps1 b/test/powershell/Get-PSDrive.Tests.ps1 index da4c87d830..0bd67260a4 100644 --- a/test/powershell/Get-PSDrive.Tests.ps1 +++ b/test/powershell/Get-PSDrive.Tests.ps1 @@ -1,4 +1,4 @@ -Describe "Get-PSDrive" { +Describe "Get-PSDrive" { It "Should not throw" { Get-PSDrive | Should Not BeNullOrEmpty diff --git a/test/powershell/Get-PSProvider.Tests.ps1 b/test/powershell/Get-PSProvider.Tests.ps1 index 4fe107e56f..a849e634e9 100644 --- a/test/powershell/Get-PSProvider.Tests.ps1 +++ b/test/powershell/Get-PSProvider.Tests.ps1 @@ -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 } diff --git a/test/powershell/Get-Random.Tests.ps1 b/test/powershell/Get-Random.Tests.ps1 index 01d4ee91f8..82080f7ac8 100644 --- a/test/powershell/Get-Random.Tests.ps1 +++ b/test/powershell/Get-Random.Tests.ps1 @@ -1,4 +1,4 @@ -Describe "Get-Random" { +Describe "Get-Random" { It "Should return a random number greater than -1 " { Get-Random | Should BeGreaterThan -1 } diff --git a/test/powershell/Get-Unique.Tests.ps1 b/test/powershell/Get-Unique.Tests.ps1 index cc549d75ac..cd1546cb96 100644 --- a/test/powershell/Get-Unique.Tests.ps1 +++ b/test/powershell/Get-Unique.Tests.ps1 @@ -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 diff --git a/test/powershell/Get-Variable.Tests.ps1 b/test/powershell/Get-Variable.Tests.ps1 index afe6fbf103..33ce309115 100644 --- a/test/powershell/Get-Variable.Tests.ps1 +++ b/test/powershell/Get-Variable.Tests.ps1 @@ -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 } diff --git a/test/powershell/Group-Object.Tests.ps1 b/test/powershell/Group-Object.Tests.ps1 index b699ddec43..f58834b97c 100644 --- a/test/powershell/Group-Object.Tests.ps1 +++ b/test/powershell/Group-Object.Tests.ps1 @@ -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" { diff --git a/test/powershell/Import-Csv.Tests.ps1 b/test/powershell/Import-Csv.Tests.ps1 index fc15ddea11..2a0559d1c2 100644 --- a/test/powershell/Import-Csv.Tests.ps1 +++ b/test/powershell/Import-Csv.Tests.ps1 @@ -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" { diff --git a/test/powershell/Measure-Object.Tests.ps1 b/test/powershell/Measure-Object.Tests.ps1 index ac1b471a3c..51c7ba3640 100644 --- a/test/powershell/Measure-Object.Tests.ps1 +++ b/test/powershell/Measure-Object.Tests.ps1 @@ -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 diff --git a/test/powershell/New-Alias.Tests.ps1 b/test/powershell/New-Alias.Tests.ps1 index 126eac8822..7ef193d372 100644 --- a/test/powershell/New-Alias.Tests.ps1 +++ b/test/powershell/New-Alias.Tests.ps1 @@ -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] } } -} +} diff --git a/test/powershell/New-Item.Tests.ps1 b/test/powershell/New-Item.Tests.ps1 index 57baa612c0..2a0db94e7a 100644 --- a/test/powershell/New-Item.Tests.ps1 +++ b/test/powershell/New-Item.Tests.ps1 @@ -1,4 +1,4 @@ -function Clean-State +function Clean-State { if (Test-Path $FullyQualifiedLink) { diff --git a/test/powershell/New-Object.Tests.ps1 b/test/powershell/New-Object.Tests.ps1 index a2bfaa14cc..f7c378abef 100644 --- a/test/powershell/New-Object.Tests.ps1 +++ b/test/powershell/New-Object.Tests.ps1 @@ -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() diff --git a/test/powershell/New-TimeSpan.Tests.ps1 b/test/powershell/New-TimeSpan.Tests.ps1 index 2e6fa358b9..6f936f593f 100644 --- a/test/powershell/New-TimeSpan.Tests.ps1 +++ b/test/powershell/New-TimeSpan.Tests.ps1 @@ -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 + } +} diff --git a/test/powershell/New-Variable.Tests.ps1 b/test/powershell/New-Variable.Tests.ps1 index adc4ef523d..1626d23cad 100644 --- a/test/powershell/New-Variable.Tests.ps1 +++ b/test/powershell/New-Variable.Tests.ps1 @@ -1,4 +1,4 @@ -Describe "New-Variable" { +Describe "New-Variable" { $nl = [Environment]::NewLine It "Should create a new variable with no parameters" { diff --git a/test/powershell/Out-File.Tests.ps1 b/test/powershell/Out-File.Tests.ps1 index 045293aafd..d107c8ce40 100644 --- a/test/powershell/Out-File.Tests.ps1 +++ b/test/powershell/Out-File.Tests.ps1 @@ -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 diff --git a/test/powershell/Out-String.Tests.ps1 b/test/powershell/Out-String.Tests.ps1 index 24400908ac..9e299db5e1 100644 --- a/test/powershell/Out-String.Tests.ps1 +++ b/test/powershell/Out-String.Tests.ps1 @@ -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 + } +} diff --git a/test/powershell/PSVersionTable.Tests.ps1 b/test/powershell/PSVersionTable.Tests.ps1 index 3487ccb3e2..564906de22 100644 --- a/test/powershell/PSVersionTable.Tests.ps1 +++ b/test/powershell/PSVersionTable.Tests.ps1 @@ -1,4 +1,4 @@ -Describe "PSVersionTable" { +Describe "PSVersionTable" { It "Should have version table entries" { $PSVersionTable.Count | Should Be 8 } diff --git a/test/powershell/Pop-Location.Tests.ps1 b/test/powershell/Pop-Location.Tests.ps1 index e7fbe4d96d..40ce07040a 100644 --- a/test/powershell/Pop-Location.Tests.ps1 +++ b/test/powershell/Pop-Location.Tests.ps1 @@ -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 } \ No newline at end of file diff --git a/test/powershell/Push-Location.Tests.ps1 b/test/powershell/Push-Location.Tests.ps1 index 2c6c9b2f21..f4ac6c8ae1 100644 --- a/test/powershell/Push-Location.Tests.ps1 +++ b/test/powershell/Push-Location.Tests.ps1 @@ -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 } diff --git a/test/powershell/Remove-Item.Tests.ps1 b/test/powershell/Remove-Item.Tests.ps1 index 2dcef4c9b8..164cfba439 100644 --- a/test/powershell/Remove-Item.Tests.ps1 +++ b/test/powershell/Remove-Item.Tests.ps1 @@ -1,4 +1,4 @@ -Describe "Remove-Item" { +Describe "Remove-Item" { $testpath = $TestDrive $testfile = "testfile.txt" $testfilepath = Join-Path -Path $testpath -ChildPath $testfile diff --git a/test/powershell/Remove-PSBreakpoint.Tests.ps1 b/test/powershell/Remove-PSBreakpoint.Tests.ps1 index e97a582d80..3189ed5aba 100644 --- a/test/powershell/Remove-PSBreakpoint.Tests.ps1 +++ b/test/powershell/Remove-PSBreakpoint.Tests.ps1 @@ -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 +} diff --git a/test/powershell/Remove-Variable.Tests.ps1 b/test/powershell/Remove-Variable.Tests.ps1 index 878ce62ae2..35dbab6b59 100644 --- a/test/powershell/Remove-Variable.Tests.ps1 +++ b/test/powershell/Remove-Variable.Tests.ps1 @@ -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" { diff --git a/test/powershell/Select-Object.Tests.ps1 b/test/powershell/Select-Object.Tests.ps1 index 639b230aa8..a05b00f001 100644 --- a/test/powershell/Select-Object.Tests.ps1 +++ b/test/powershell/Select-Object.Tests.ps1 @@ -1,4 +1,4 @@ -. (Join-Path -Path $PSScriptRoot -ChildPath Test-Mocks.ps1) +. (Join-Path -Path $PSScriptRoot -ChildPath Test-Mocks.ps1) Describe "Select-Object" { BeforeEach { diff --git a/test/powershell/Select-String.Tests.ps1 b/test/powershell/Select-String.Tests.ps1 index a32a3cca26..9f1855a2bc 100644 --- a/test/powershell/Select-String.Tests.ps1 +++ b/test/powershell/Select-String.Tests.ps1 @@ -1,4 +1,4 @@ -Describe "Select-String" { +Describe "Select-String" { $nl = [Environment]::NewLine $currentDirectory = $pwd.Path Context "String actions" { diff --git a/test/powershell/Set-Alias.Tests.ps1 b/test/powershell/Set-Alias.Tests.ps1 index 596e9f40ba..7d83426c7e 100644 --- a/test/powershell/Set-Alias.Tests.ps1 +++ b/test/powershell/Set-Alias.Tests.ps1 @@ -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) + } +} diff --git a/test/powershell/Set-Location.Tests.ps1 b/test/powershell/Set-Location.Tests.ps1 index e24f09e17b..1f73187fab 100644 --- a/test/powershell/Set-Location.Tests.ps1 +++ b/test/powershell/Set-Location.Tests.ps1 @@ -1,4 +1,4 @@ -Describe "Set-Location" { +Describe "Set-Location" { $startDirectory = Get-Location if ($IsWindows) diff --git a/test/powershell/Set-PSBreakpoint.Tests.ps1 b/test/powershell/Set-PSBreakpoint.Tests.ps1 index ebf11952e7..fd00271c5f 100644 --- a/test/powershell/Set-PSBreakpoint.Tests.ps1 +++ b/test/powershell/Set-PSBreakpoint.Tests.ps1 @@ -1,4 +1,4 @@ -Describe "Set-PSBreakpoint" { +Describe "Set-PSBreakpoint" { # Set up test script $testScript = Join-Path -Path $PSScriptRoot -ChildPath psbreakpointtestscript.ps1 diff --git a/test/powershell/Set-PSDebug.Tests.ps1 b/test/powershell/Set-PSDebug.Tests.ps1 index f97628e82c..24ad44150e 100644 --- a/test/powershell/Set-PSDebug.Tests.ps1 +++ b/test/powershell/Set-PSDebug.Tests.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" { diff --git a/test/powershell/Set-Variable.Tests.ps1 b/test/powershell/Set-Variable.Tests.ps1 index 9bfeabb511..cfa0edb3a5 100644 --- a/test/powershell/Set-Variable.Tests.ps1 +++ b/test/powershell/Set-Variable.Tests.ps1 @@ -1,4 +1,4 @@ -Describe "Set-Variable" { +Describe "Set-Variable" { ${nl} = [Environment]::Newline It "Should create a new variable with no parameters" { diff --git a/test/powershell/Split-Path.Tests.ps1 b/test/powershell/Split-Path.Tests.ps1 index 2c0f802aa0..761b337b1d 100644 --- a/test/powershell/Split-Path.Tests.ps1 +++ b/test/powershell/Split-Path.Tests.ps1 @@ -1,4 +1,4 @@ -Describe "Split-Path" { +Describe "Split-Path" { if ($IsWindows) { $qualifier = "C:" diff --git a/test/powershell/Start-Process.Tests.ps1 b/test/powershell/Start-Process.Tests.ps1 index 6880f79ee2..0408c404e2 100644 --- a/test/powershell/Start-Process.Tests.ps1 +++ b/test/powershell/Start-Process.Tests.ps1 @@ -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 diff --git a/test/powershell/Write-Error.Tests.ps1 b/test/powershell/Write-Error.Tests.ps1 index e8390188f3..a629ab393b 100644 --- a/test/powershell/Write-Error.Tests.ps1 +++ b/test/powershell/Write-Error.Tests.ps1 @@ -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 + } } \ No newline at end of file diff --git a/test/powershell/Write-Output.Tests.ps1 b/test/powershell/Write-Output.Tests.ps1 index 25849d64ba..fad5a9b5cd 100644 --- a/test/powershell/Write-Output.Tests.ps1 +++ b/test/powershell/Write-Output.Tests.ps1 @@ -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 + } + } +} diff --git a/test/powershell/Write-Verbose.Tests.ps1 b/test/powershell/Write-Verbose.Tests.ps1 index d6fb4f774f..478bf309d7 100644 --- a/test/powershell/Write-Verbose.Tests.ps1 +++ b/test/powershell/Write-Verbose.Tests.ps1 @@ -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" + } } \ No newline at end of file diff --git a/test/powershell/foo b/test/powershell/foo new file mode 100644 index 0000000000..f1de821480 --- /dev/null +++ b/test/powershell/foo @@ -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 \ No newline at end of file