Environment-Variables.Tests.ps1

This commit is contained in:
Zachary Folwick 2015-12-28 11:05:48 -08:00
parent 1b4276f563
commit de2af02ff7
13 changed files with 201 additions and 84 deletions

View file

@ -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
}
}

View file

@ -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
}
}
}

View file

@ -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

View file

@ -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]
}
}
}

View file

@ -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" {

View file

@ -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

View file

@ -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."

View file

@ -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"

View file

@ -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" {

View file

@ -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
}

View file

@ -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

View file

@ -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

BIN
src/pester-tests/test Executable file

Binary file not shown.