From de2af02ff7d8fd12e61bd47e2af744af91feb3ed Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Mon, 28 Dec 2015 11:05:48 -0800 Subject: [PATCH] Environment-Variables.Tests.ps1 --- src/pester-tests/#%2Amerge%2A#31209PgX# | 14 ++++ src/pester-tests/#%2Amerge%2A#9359p5X# | 14 ++++ src/pester-tests/Compare-Object.Tests.ps1 | 17 +---- src/pester-tests/ConvertTo-Xml.Tests.ps1 | 46 ++++++++++++ .../Environment-Variables.Tests.ps1 | 17 ++--- src/pester-tests/Get-ItemProperty.Tests.ps1 | 16 +++-- src/pester-tests/Measure-Object.Tests.ps1 | 8 +-- src/pester-tests/Select-String.Tests.ps1 | 14 ++-- src/pester-tests/Set-Location.Tests.ps1 | 8 ++- src/pester-tests/Set-PSBreakpoint.Tests.ps1 | 66 +++++++++--------- .../Set-PSBreakpoint.Tests.ps1.orig | 51 ++++++++++++++ src/pester-tests/Split-Path.Tests.ps1 | 14 ++-- src/pester-tests/test | Bin 0 -> 408 bytes 13 files changed, 201 insertions(+), 84 deletions(-) create mode 100644 src/pester-tests/#%2Amerge%2A#31209PgX# create mode 100644 src/pester-tests/#%2Amerge%2A#9359p5X# create mode 100644 src/pester-tests/ConvertTo-Xml.Tests.ps1 create mode 100644 src/pester-tests/Set-PSBreakpoint.Tests.ps1.orig create mode 100755 src/pester-tests/test diff --git a/src/pester-tests/#%2Amerge%2A#31209PgX# b/src/pester-tests/#%2Amerge%2A#31209PgX# new file mode 100644 index 0000000000..3692e94191 --- /dev/null +++ b/src/pester-tests/#%2Amerge%2A#31209PgX# @@ -0,0 +1,14 @@ +$here = Split-Path -Parent $MyInvocation.MyCommand.Path + +Describe "Set-PSBreakpoint" { + New-Variable -Name script -Value $here/assets/testablescript.ps1 -Scope Global -Force + + It "Should be able to called with script and line parameters without error " { + { Set-PSBreakpoint -Script $script -Line 1 } | Should Not Throw + } + + It "Should be able to be called using the command switch" { + # Note- we don't actually require the command to exist in the script- it will simply not get a breakpoint + { Set-PSBreakpoint -Script $script -Command aoeuaoeu } | Should Not Throw + } +} diff --git a/src/pester-tests/#%2Amerge%2A#9359p5X# b/src/pester-tests/#%2Amerge%2A#9359p5X# new file mode 100644 index 0000000000..842ee47fde --- /dev/null +++ b/src/pester-tests/#%2Amerge%2A#9359p5X# @@ -0,0 +1,14 @@ +Describe "Wait-Event" { + + Context "Validate Wait-Event is waiting for events" { + It "Should time out when it does not receive a FakeEvent" { + # Don't depend on Measure-Command + $stopwatch = [System.Diagnostics.Stopwatch]::startNew() + # Testing the the timeout, so wait for an event that will never be + # raised because it is fake + Wait-Event -Timeout 1 -SourceIdentifier "FakeEvent" + $stopwatch.Stop() + $stopwatch.ElapsedMilliseconds | Should BeGreaterThan 1000 + } + } +} diff --git a/src/pester-tests/Compare-Object.Tests.ps1 b/src/pester-tests/Compare-Object.Tests.ps1 index cddf690a93..3f4e70c6fd 100644 --- a/src/pester-tests/Compare-Object.Tests.ps1 +++ b/src/pester-tests/Compare-Object.Tests.ps1 @@ -1,18 +1,7 @@ Describe "Compare-Object" { - # First ensure the environment is set up - if (Test-Path "/tmp") - { - $testDirectory = "/tmp/testDirectory" - $nl = "`n" - $slash = "/" - - } - else - { - $testDirectory = "C:\Users\v-zafolw\testdirectory" - $nl = "`r`n" - $slash = "\\" - } + $testDirectory = $env:HOME + "testDirectory" + $nl = [Environment]::NewLine + $slash = [Environment]::DirectorySeparatorChar $dir = $testDirectory New-Item $testDirectory -ItemType directory -Force diff --git a/src/pester-tests/ConvertTo-Xml.Tests.ps1 b/src/pester-tests/ConvertTo-Xml.Tests.ps1 new file mode 100644 index 0000000000..a44385af55 --- /dev/null +++ b/src/pester-tests/ConvertTo-Xml.Tests.ps1 @@ -0,0 +1,46 @@ +Describe "Test-ConvertTo-Xml" { + $testObject = Get-ChildItem + $slash = [System.IO.Path]::DirectorySeparatorChar + $testDirectory = $Env:TEMP + $slash + "testDirectory" + $testfile = $testDirectory + $slash + "testfile.xml" + $nl = [Environment]::NewLine + + New-Item $testDirectory -ItemType Directory -Force + + It "Should create an xml Document" { + $($testObject | ConvertTo-Xml).GetType().Name | Should Be XmlDocument + } + + It "Should be able to save an object after being converted to an xml object" { + { $xml = $testObject | ConvertTo-Xml + $xml.Save($testfile) } | Should Not Throw + + Test-Path $testfile | Should Be $true + } + + It "Should have a data type of XmlDocument and a BaseType of System.Xml.XmlNode" { + $actual = $testObject | ConvertTo-Xml + + } + + It "Should be able to use the As switch without error" { + { ConvertTo-Xml -InputObject $testObject -As String } | Should Not Throw + { ConvertTo-Xml -InputObject $testObject -As Document } | Should Not Throw + { ConvertTo-Xml -InputObject $testObject -As Stream } | Should Not Throw + } + + It "Should be the same output between the As switch and just saving the file as an xml document" { + # Create the test object, and do some formatting to get it in a testable format + $asSwitch = ($testObject | ConvertTo-Xml -As String).Split([Environment]::NewLine,[System.StringSplitOptions]::RemoveEmptyEntries) + + ($testObject | ConvertTo-Xml).Save($testfile) + + # iterate through each line and compare the saved variable and the file contents + for($line=0; $line -le $testfile.Length; $line++) + { + $currentLine = (Get-Content $testfile)[$line] + + $currentLine | Should Be $asSwitch[$line] + } + } +} diff --git a/src/pester-tests/Environment-Variables.Tests.ps1 b/src/pester-tests/Environment-Variables.Tests.ps1 index 7b3fe1da92..f8a62e0cf0 100644 --- a/src/pester-tests/Environment-Variables.Tests.ps1 +++ b/src/pester-tests/Environment-Variables.Tests.ps1 @@ -1,4 +1,6 @@ Describe "Environment-Variables" { + $isWindows = [System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Windows) + It "Should have environment variables" { Get-Item ENV: | Should Not BeNullOrEmpty } @@ -8,27 +10,26 @@ } It "Should contain /bin in the PATH" { - if ($ENV:TEMP -eq "/tmp" ) + if ($isWindows) { - $ENV:PATH | Should Match "/bin" + $ENV:PATH | Should Match "C:" } else { - $ENV:PATH | Should Match "C:" + $ENV:PATH | Should Match "/bin" } } It "Should have the correct HOME" { - if ($ENV:TEMP -eq "/tmp" ) + if ($isWindows) { - $expected = /bin/bash -c "cd ~ && pwd" - $ENV:HOME | Should Be $expected + $expected = "\Users\" + $ENV:USERNAME } else { - $expected = "\Users\" + $ENV:USERNAME - $ENV:HOMEPATH | Should Be $expected + $expected = /bin/bash -c "cd ~ && pwd" } + $ENV:HOME | Should Be $expected } It "Should be able to set the environment variables" { diff --git a/src/pester-tests/Get-ItemProperty.Tests.ps1 b/src/pester-tests/Get-ItemProperty.Tests.ps1 index f2d73d74bc..67592ef02b 100644 --- a/src/pester-tests/Get-ItemProperty.Tests.ps1 +++ b/src/pester-tests/Get-ItemProperty.Tests.ps1 @@ -3,19 +3,21 @@ Describe "Get-ItemProperty" { $currentDirectory = Split-Path $here -Leaf $parentDirectory = Split-Path $here/.. -Leaf - if ($Env:TEMP -eq "/tmp") - { - $tempDirectory = "/tmp/testfolder" - $testProvider = "/" - } - else + $isWindows = [System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Windows) + + if ($isWindows) { $tempDirectory = "~/testfolder" $testProvider = "C" } + else + { + $tempDirectory = "/tmp/testfolder" + $testProvider = "/" + } New-Item $tempDirectory -ItemType Directory -Force - $testfile = $tempDirectory + "/" + "testfile1" + $testfile = $tempDirectory + [Environment]::DirectorySeparatorChar + "testfile1" New-Item $testfile -ItemType file -Force diff --git a/src/pester-tests/Measure-Object.Tests.ps1 b/src/pester-tests/Measure-Object.Tests.ps1 index 7d6205ee6c..602a5af5e7 100644 --- a/src/pester-tests/Measure-Object.Tests.ps1 +++ b/src/pester-tests/Measure-Object.Tests.ps1 @@ -126,13 +126,7 @@ } Context "String tests" { - if ($true) # TODO: test if Windows or Linux - { - $nl = "`n" - } - else { - $nl = "`r`n" - } + $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." diff --git a/src/pester-tests/Select-String.Tests.ps1 b/src/pester-tests/Select-String.Tests.ps1 index 35c78f401a..7f4375e790 100644 --- a/src/pester-tests/Select-String.Tests.ps1 +++ b/src/pester-tests/Select-String.Tests.ps1 @@ -87,16 +87,18 @@ } Context "Filesytem actions" { - if ($env:TEMP -eq "/tmp") - { - $testDirectory = "/tmp/" - $testInputFile = "/tmp/testfile1.txt" - } - else + $isWindows = [System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Windows) + + if ($isWindows) { $testDirectory = "C:\tmp\" $testInputFile = "C:\tmp\testfile1.txt" } + else + { + $testDirectory = "/tmp/" + $testInputFile = "/tmp/testfile1.txt" + } BeforeEach { New-Item $testInputFile -Itemtype "file" -Force -Value "This is a text string, and another string${nl}This is the second line${nl}This is the third line${nl}This is the fourth line${nl}No matches" diff --git a/src/pester-tests/Set-Location.Tests.ps1 b/src/pester-tests/Set-Location.Tests.ps1 index 3a8b176041..aeacbbaa33 100644 --- a/src/pester-tests/Set-Location.Tests.ps1 +++ b/src/pester-tests/Set-Location.Tests.ps1 @@ -1,12 +1,14 @@ Describe "Set-Location" { $startDirectory = Get-Location - if ( $env:TEMP -eq "/tmp") + $isWindows = [System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Windows) + + if ($isWindows) { - $target = "/" + $target = "C:\" } else { - $target = "C:\" + $target = "/" } It "Should be able to be called without error" { diff --git a/src/pester-tests/Set-PSBreakpoint.Tests.ps1 b/src/pester-tests/Set-PSBreakpoint.Tests.ps1 index 36dc88b8f9..1ad10e376f 100644 --- a/src/pester-tests/Set-PSBreakpoint.Tests.ps1 +++ b/src/pester-tests/Set-PSBreakpoint.Tests.ps1 @@ -1,34 +1,34 @@ -$here = Split-Path -Parent $MyInvocation.MyCommand.Path - -Describe "Set-PSBreakpoint" { - # Set up test script - $testScript = "$here/psbreakpointtestscript.ps1" - - "`$var = 1 " > $testScript - - It "Should be able to set a psbreakpoint on a line" { - $lineNumber = 1 - $(Set-PSBreakpoint -Line $lineNumber -Script $testScript).Line | Should Be $lineNumber - } - - It "Should throw when a string is entered for a line number" { - { - $lineNumber = "one" - $(Set-PSBreakpoint -Line $lineNumber -Script $testScript).Line - - } | Should Throw - } - - It "Should be able to set a psbreakpoint on a Command" { - $command = "theCommand" - $(Set-PSBreakpoint -Command $command -Script $testScript).Command | Should Be $command - } - - It "Should be able to set a psbreakpoint on a variable" { - $var = "theVariable" - $(Set-PSBreakpoint -Command $var -Script $testScript).Command | Should Be $var - } - - # clean up after ourselves - Remove-Item -Path $testScript +$here = Split-Path -Parent $MyInvocation.MyCommand.Path + +Describe "Set-PSBreakpoint" { + # Set up test script + $testScript = "$here/psbreakpointtestscript.ps1" + + "`$var = 1 " > $testScript + + It "Should be able to set a psbreakpoint on a line" { + $lineNumber = 1 + $(Set-PSBreakpoint -Line $lineNumber -Script $testScript).Line | Should Be $lineNumber + } + + It "Should throw when a string is entered for a line number" { + { + $lineNumber = "one" + $(Set-PSBreakpoint -Line $lineNumber -Script $testScript).Line + + } | Should Throw + } + + It "Should be able to set a psbreakpoint on a Command" { + $command = "theCommand" + $(Set-PSBreakpoint -Command $command -Script $testScript).Command | Should Be $command + } + + It "Should be able to set a psbreakpoint on a variable" { + $var = "theVariable" + $(Set-PSBreakpoint -Command $var -Script $testScript).Command | Should Be $var + } + + # clean up after ourselves + Remove-Item -Path $testScript } diff --git a/src/pester-tests/Set-PSBreakpoint.Tests.ps1.orig b/src/pester-tests/Set-PSBreakpoint.Tests.ps1.orig new file mode 100644 index 0000000000..75a338b8b3 --- /dev/null +++ b/src/pester-tests/Set-PSBreakpoint.Tests.ps1.orig @@ -0,0 +1,51 @@ +<<<<<<< HEAD +$here = Split-Path -Parent $MyInvocation.MyCommand.Path + +Describe "Set-PSBreakpoint" { + New-Variable -Name script -Value $here/assets/testablescript.ps1 -Scope Global -Force + + It "Should be able to called with script and line parameters without error " { + { Set-PSBreakpoint -Script $script -Line 1 } | Should Not Throw + } + + It "Should be able to be called using the command switch" { + # Note- we don't actually require the command to exist in the script- it will simply not get a breakpoint + { Set-PSBreakpoint -Script $script -Command aoeuaoeu } | Should Not Throw + } +} +======= +$here = Split-Path -Parent $MyInvocation.MyCommand.Path + +Describe "Set-PSBreakpoint" { + # Set up test script + $testScript = "$here/psbreakpointtestscript.ps1" + + "`$var = 1 " > $testScript + + It "Should be able to set a psbreakpoint on a line" { + $lineNumber = 1 + $(Set-PSBreakpoint -Line $lineNumber -Script $testScript).Line | Should Be $lineNumber + } + + It "Should throw when a string is entered for a line number" { + { + $lineNumber = "one" + $(Set-PSBreakpoint -Line $lineNumber -Script $testScript).Line + + } | Should Throw + } + + It "Should be able to set a psbreakpoint on a Command" { + $command = "theCommand" + $(Set-PSBreakpoint -Command $command -Script $testScript).Command | Should Be $command + } + + It "Should be able to set a psbreakpoint on a variable" { + $var = "theVariable" + $(Set-PSBreakpoint -Command $var -Script $testScript).Command | Should Be $var + } + + # clean up after ourselves + Remove-Item -Path $testScript +} +>>>>>>> master diff --git a/src/pester-tests/Split-Path.Tests.ps1 b/src/pester-tests/Split-Path.Tests.ps1 index ec94b47e10..0b65701c03 100644 --- a/src/pester-tests/Split-Path.Tests.ps1 +++ b/src/pester-tests/Split-Path.Tests.ps1 @@ -1,11 +1,13 @@ Describe "Split-Path" { - if ( $Env:TEMP -eq "/tmp") + $isWindows = [System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Windows) + + if ($isWindows) { - $qualifier = "/" + $qualifier = "C:" } else { - $qualifier = "C:" + $qualifier = "/" } It "Should return a string object when invoked" { @@ -40,7 +42,7 @@ It "Should return the path when the noqualifier switch is used on a Linux system" { { Split-Path ${qualifier}usr/bin -NoQualifier } | Should Not Throw - if ($env:TEMP -eq "/tmp") + if ($isWindows) { Split-Path ${qualifier}usr/bin -NoQualifier | Should Be "/usr/bin" } @@ -64,8 +66,8 @@ $testFile1 = "testfile1.ps1" $testFile2 = "testfile2.ps1" - $testFilePath1 = $testDir + "/" + $testFile1 - $testFilePath2 = $testDir + "/" + $testFile2 + $testFilePath1 = $testDir + [Environment]::NewLine + $testFile1 + $testFilePath2 = $testDir + [Environment]::NewLine + $testFile2 New-Item -ItemType file -Path $testFilePath1, $testFilePath2 -Force diff --git a/src/pester-tests/test b/src/pester-tests/test new file mode 100755 index 0000000000000000000000000000000000000000..a2f5918d12641d30c4d44b6457de639c0d484879 GIT binary patch literal 408 zcma)&K?{OV5QOLKuaFK=R6-p)cnJd!MbV){bP&@DQbUdM&sU#{SkNJseLK9JH#_@Y z&#h9Ol`GIl4medpn(8RxF4YxeY9d=*jX^e9vNKLoQ?lV1;5r7>nY@a3tn>=GiWPzz z&Sx!Emh^IMm>0;$QAh?lR1x`TK{TX@#%m+lp literal 0 HcmV?d00001