From 7d904d91faa3e0fb87c1dda965e0cc375a3fe67d Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Wed, 18 Nov 2015 16:26:01 -0800 Subject: [PATCH 1/2] added write-output pester tests --- src/pester-tests/Write-Output.Tests.ps1 | 50 +++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/pester-tests/Write-Output.Tests.ps1 diff --git a/src/pester-tests/Write-Output.Tests.ps1 b/src/pester-tests/Write-Output.Tests.ps1 new file mode 100644 index 000000000..fe91493ed --- /dev/null +++ b/src/pester-tests/Write-Output.Tests.ps1 @@ -0,0 +1,50 @@ +Describe "Write-Output" { + It "Should allow piped input" { + { "hi" | Write-Output } | Should Not Throw + } + + It "Should use inputobject switch" { + { Write-Output -InputObject "hi" } | Should Not Throw + } + + It "Should be able to write to a variable" { + Write-Output -InputObject "hi" -OutVariable var + $var | Should Be "hi" + } + + 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 + } + + It "Should have the same result between the echo alias and the cmdlet" { + $alias = echo -InputObject "hi" + $cmdlet = Write-Output -InputObject "hi" + + $alias | Should Be $cmdlet + } + + It "Should have the same result between the write alias and the cmdlet" { + $alias = write -InputObject "hi" + $cmdlet = Write-Output -InputObject "hi" + + $alias | Should Be $cmdlet + } + + It "Should see individual objects when not using the NoEnumerate switch" { + $singleCollection = $(Write-Output @(1,2,3)| Measure-Object).Count + + $singleCollection | Should Be 3 + } + + It "Should be able to treat a collection as a single object using the NoEnumerate switch" { + $singleCollection = $(Write-Output @(1,2,3) -NoEnumerate | Measure-Object).Count + + $singleCollection | Should Be 1 + } +} \ No newline at end of file From 384d81ca211c75d48d0364985d1e1e61c9cd62b6 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Thu, 19 Nov 2015 11:44:26 -0800 Subject: [PATCH 2/2] modified and added tests according to PR --- src/pester-tests/Write-Output.Tests.ps1 | 102 ++++++++++++++---------- 1 file changed, 60 insertions(+), 42 deletions(-) diff --git a/src/pester-tests/Write-Output.Tests.ps1 b/src/pester-tests/Write-Output.Tests.ps1 index fe91493ed..25849d64b 100644 --- a/src/pester-tests/Write-Output.Tests.ps1 +++ b/src/pester-tests/Write-Output.Tests.ps1 @@ -1,50 +1,68 @@ Describe "Write-Output" { - It "Should allow piped input" { - { "hi" | Write-Output } | Should Not Throw + $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 + } } - It "Should use inputobject switch" { - { Write-Output -InputObject "hi" } | Should Not Throw + 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 + } } - It "Should be able to write to a variable" { - Write-Output -InputObject "hi" -OutVariable var - $var | Should Be "hi" + 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 + } } - It "Should send object to the next command in the pipeline" { - Write-Output -InputObject (1+1) | Should Be 2 + 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 + } } - - 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 - } - - It "Should have the same result between the echo alias and the cmdlet" { - $alias = echo -InputObject "hi" - $cmdlet = Write-Output -InputObject "hi" - - $alias | Should Be $cmdlet - } - - It "Should have the same result between the write alias and the cmdlet" { - $alias = write -InputObject "hi" - $cmdlet = Write-Output -InputObject "hi" - - $alias | Should Be $cmdlet - } - - It "Should see individual objects when not using the NoEnumerate switch" { - $singleCollection = $(Write-Output @(1,2,3)| Measure-Object).Count - - $singleCollection | Should Be 3 - } - - It "Should be able to treat a collection as a single object using the NoEnumerate switch" { - $singleCollection = $(Write-Output @(1,2,3) -NoEnumerate | Measure-Object).Count - - $singleCollection | Should Be 1 - } -} \ No newline at end of file +}