From d8996b2bf74d242c5f90cd70693bf19cecf4d04d Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Wed, 19 Aug 2015 14:13:15 -0700 Subject: [PATCH 1/5] added pester tests for out-file and got running in linux --- src/pester-tests/Test-Out-File.Tests.ps1 | 112 +++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/pester-tests/Test-Out-File.Tests.ps1 diff --git a/src/pester-tests/Test-Out-File.Tests.ps1 b/src/pester-tests/Test-Out-File.Tests.ps1 new file mode 100644 index 000000000..9856af0ae --- /dev/null +++ b/src/pester-tests/Test-Out-File.Tests.ps1 @@ -0,0 +1,112 @@ +Describe "Test-Out-File" { + $a = "some test text" + $b = New-Object psobject -Property @{text=$a} + $Testfile = "/tmp/outfileTest.txt" + + BeforeEach { + if (Test-Path -Path $testfile) + { + Set-ItemProperty -Path $testfile -Name IsReadOnly -Value $false + rm $testfile + } + } + + AfterEach { + # implement in *nix to remove test files after each test if they exist + rm $testfile + } + + It "Should be able to be called without error" { + { Out-File -FilePath $testfile } | Should Not Throw + } + + It "Should be able to accept string input" { + { $a | Out-File -FilePath $testfile } | Should Not Throw + + { Out-File -FilePath $testfile -InputObject $a } | Should Not Throw + } + + It "Should be able to accept object input" { + { $b | Out-File -FilePath $testfile } | Should Not Throw + + { Out-File -FilePath $testfile -InputObject $b } | Should Not Throw + } + + It "Should not overwrite when the noclobber switch is used" { + + Out-File -FilePath $testfile -InputObject $b + + { Out-File -FilePath $testfile -InputObject $b -NoClobber -ErrorAction SilentlyContinue } | Should Throw "already exists." + { Out-File -FilePath $testfile -InputObject $b -NoOverWrite -ErrorAction SilentlyContinue } | Should Throw "already exists." + + $actual = Get-Content $testfile + + $actual[0] | Should Be "" + $actual[1] | Should Match "text" + $actual[2] | Should Match "----" + $actual[3] | Should Match "some test text" + } + + It "Should Append a new line when the append switch is used" { + { Out-File -FilePath $testfile -InputObject $b } | Should Not Throw + { Out-File -FilePath $testfile -InputObject $b -Append } | Should Not Throw + + $actual = Get-Content $testfile + + $actual[0] | Should Be "" + $actual[1] | Should Match "text" + $actual[2] | Should Match "----" + $actual[3] | Should Match "some test text" + $actual[4] | Should Be "" + $actual[5] | Should Be "" + $actual[6] | Should Be "" + $actual[7] | Should Match "text" + $actual[8] | Should Match "----" + $actual[9] | Should Match "some test text" + $actual[10] | Should Be "" + $actual[11] | Should Be "" + + } + + It "Should limit each line to the specified number of characters when the width switch is used on objects" { + + Out-File -FilePath $testfile -Width 10 -InputObject $b + + $actual = Get-Content $testfile + + $actual[0] | Should Be "" + $actual[1] | Should Be "text " + $actual[2] | Should Be "---- " + $actual[3] | Should Be "some te..." + + } + + ### -force switch override + It "Should allow the cmdlet to overwrite an existing read-only file" { + # create a read-only text file + { Out-File -FilePath $testfile -InputObject $b } | Should Not Throw + Set-ItemProperty -Path $testfile -Name IsReadOnly -Value $true + + # write information to the RO file + { Out-File -FilePath $testfile -InputObject $b -Append -Force } | Should Not Throw + + $actual = Get-Content $testfile + + $actual[0] | Should Be "" + $actual[1] | Should Match "text" + $actual[2] | Should Match "----" + $actual[3] | Should Match "some test text" + $actual[4] | Should Be "" + $actual[5] | Should Be "" + $actual[6] | Should Be "" + $actual[7] | Should Match "text" + $actual[8] | Should Match "----" + $actual[9] | Should Match "some test text" + $actual[10] | Should Be "" + $actual[11] | Should Be "" + + # reset to not read only so it can be deleted + Set-ItemProperty -Path $testfile -Name IsReadOnly -Value $false + } + ###These commands show how to use the Out-File cmdlet when you are not in a FileSystem drive. +} From adb2e66c91d088d9c92d6f810e3bac838a1cdb69 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Mon, 24 Aug 2015 10:06:48 -0700 Subject: [PATCH 2/5] removed typos --- src/pester-tests/Test-Out-File.Tests.ps1 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/pester-tests/Test-Out-File.Tests.ps1 b/src/pester-tests/Test-Out-File.Tests.ps1 index 9856af0ae..db63179f4 100644 --- a/src/pester-tests/Test-Out-File.Tests.ps1 +++ b/src/pester-tests/Test-Out-File.Tests.ps1 @@ -81,7 +81,6 @@ } - ### -force switch override It "Should allow the cmdlet to overwrite an existing read-only file" { # create a read-only text file { Out-File -FilePath $testfile -InputObject $b } | Should Not Throw @@ -108,5 +107,4 @@ # reset to not read only so it can be deleted Set-ItemProperty -Path $testfile -Name IsReadOnly -Value $false } - ###These commands show how to use the Out-File cmdlet when you are not in a FileSystem drive. -} +} From 00e542524ca3af892575bf4d93d29480b3641934 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Thu, 3 Sep 2015 16:15:50 -0700 Subject: [PATCH 3/5] modified test code according to code review --- src/pester-tests/Test-Out-File.Tests.ps1 | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/pester-tests/Test-Out-File.Tests.ps1 b/src/pester-tests/Test-Out-File.Tests.ps1 index db63179f4..6d7db2b43 100644 --- a/src/pester-tests/Test-Out-File.Tests.ps1 +++ b/src/pester-tests/Test-Out-File.Tests.ps1 @@ -1,29 +1,37 @@ Describe "Test-Out-File" { $a = "some test text" $b = New-Object psobject -Property @{text=$a} - $Testfile = "/tmp/outfileTest.txt" + $testfile = "/tmp/outfileTest.txt" BeforeEach { if (Test-Path -Path $testfile) { - Set-ItemProperty -Path $testfile -Name IsReadOnly -Value $false - rm $testfile + Remove-Item -Path $testfile -Force } } AfterEach { - # implement in *nix to remove test files after each test if they exist - rm $testfile + Remove-Item -Path $testfile -Force } It "Should be able to be called without error" { { Out-File -FilePath $testfile } | Should Not Throw } - It "Should be able to accept string input" { + It "Should be able to accept string input via piping" { { $a | Out-File -FilePath $testfile } | Should Not Throw + $actual = Get-Content $testfile + + $actual | Should Be $a + } + + It "Should be able to accept string input via the InputObject swictch" { { Out-File -FilePath $testfile -InputObject $a } | Should Not Throw + + $actual = Get-Content $testfile + + $actual | Should Be $a } It "Should be able to accept object input" { From 6ca644f37525f2bfc0a0dd5d3a6bd4692e9ff0bd Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Mon, 14 Sep 2015 13:58:18 -0700 Subject: [PATCH 4/5] brought monad up to date with latest PSL changes --- src/monad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/monad b/src/monad index 9aecfb12f..378897d1d 160000 --- a/src/monad +++ b/src/monad @@ -1 +1 @@ -Subproject commit 9aecfb12f69d91908812751e1b69d7c5c8098e07 +Subproject commit 378897d1d5cf19e63fb7faefd301eca6624daf38 From 1615ded3e47d2fe1ba4160d66e1d39b7fc0b0ff3 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Mon, 14 Sep 2015 15:07:31 -0700 Subject: [PATCH 5/5] incorporated final changes to pester tests --- src/pester-tests/Test-Out-File.Tests.ps1 | 41 ++++++++++-------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/src/pester-tests/Test-Out-File.Tests.ps1 b/src/pester-tests/Test-Out-File.Tests.ps1 index 6d7db2b43..b08126e5f 100644 --- a/src/pester-tests/Test-Out-File.Tests.ps1 +++ b/src/pester-tests/Test-Out-File.Tests.ps1 @@ -1,17 +1,10 @@ Describe "Test-Out-File" { - $a = "some test text" - $b = New-Object psobject -Property @{text=$a} + $expectedContent = "some test text" + $inputObject = New-Object psobject -Property @{text=$expectedContent} $testfile = "/tmp/outfileTest.txt" - BeforeEach { - if (Test-Path -Path $testfile) - { - Remove-Item -Path $testfile -Force - } - } - AfterEach { - Remove-Item -Path $testfile -Force + Remove-Item -Path $testfile -Force } It "Should be able to be called without error" { @@ -19,33 +12,33 @@ } It "Should be able to accept string input via piping" { - { $a | Out-File -FilePath $testfile } | Should Not Throw + { $expectedContent | Out-File -FilePath $testfile } | Should Not Throw $actual = Get-Content $testfile - $actual | Should Be $a + $actual | Should Be $expectedContent } It "Should be able to accept string input via the InputObject swictch" { - { Out-File -FilePath $testfile -InputObject $a } | Should Not Throw + { Out-File -FilePath $testfile -InputObject $expectedContent } | Should Not Throw $actual = Get-Content $testfile - $actual | Should Be $a + $actual | Should Be $expectedContent } It "Should be able to accept object input" { - { $b | Out-File -FilePath $testfile } | Should Not Throw + { $inputObject | Out-File -FilePath $testfile } | Should Not Throw - { Out-File -FilePath $testfile -InputObject $b } | Should Not Throw + { Out-File -FilePath $testfile -InputObject $inputObject } | Should Not Throw } It "Should not overwrite when the noclobber switch is used" { - Out-File -FilePath $testfile -InputObject $b + Out-File -FilePath $testfile -InputObject $inputObject - { Out-File -FilePath $testfile -InputObject $b -NoClobber -ErrorAction SilentlyContinue } | Should Throw "already exists." - { Out-File -FilePath $testfile -InputObject $b -NoOverWrite -ErrorAction SilentlyContinue } | Should Throw "already exists." + { Out-File -FilePath $testfile -InputObject $inputObject -NoClobber -ErrorAction SilentlyContinue } | Should Throw "already exists." + { Out-File -FilePath $testfile -InputObject $inputObject -NoOverWrite -ErrorAction SilentlyContinue } | Should Throw "already exists." $actual = Get-Content $testfile @@ -56,8 +49,8 @@ } It "Should Append a new line when the append switch is used" { - { Out-File -FilePath $testfile -InputObject $b } | Should Not Throw - { Out-File -FilePath $testfile -InputObject $b -Append } | Should Not Throw + { Out-File -FilePath $testfile -InputObject $inputObject } | Should Not Throw + { Out-File -FilePath $testfile -InputObject $inputObject -Append } | Should Not Throw $actual = Get-Content $testfile @@ -78,7 +71,7 @@ It "Should limit each line to the specified number of characters when the width switch is used on objects" { - Out-File -FilePath $testfile -Width 10 -InputObject $b + Out-File -FilePath $testfile -Width 10 -InputObject $inputObject $actual = Get-Content $testfile @@ -91,11 +84,11 @@ It "Should allow the cmdlet to overwrite an existing read-only file" { # create a read-only text file - { Out-File -FilePath $testfile -InputObject $b } | Should Not Throw + { Out-File -FilePath $testfile -InputObject $inputObject } | Should Not Throw Set-ItemProperty -Path $testfile -Name IsReadOnly -Value $true # write information to the RO file - { Out-File -FilePath $testfile -InputObject $b -Append -Force } | Should Not Throw + { Out-File -FilePath $testfile -InputObject $inputObject -Append -Force } | Should Not Throw $actual = Get-Content $testfile