diff --git a/Makefile b/Makefile index e064b3119..235c606b5 100644 --- a/Makefile +++ b/Makefile @@ -57,7 +57,7 @@ test-hashbang: ## - we cd because some tests rely on the current working directory PESTER=$(MONAD)/src/pester-tests test-pester: - $(POWERSHELL_SIMPLE) 'cd $(PESTER); $$env:TEMP="/tmp"; invoke-pester -OutputFile $(MONAD)/pester-tests.xml -OutputFormat NUnitXml' + $(POWERSHELL_SIMPLE) '$$env:TEMP="/tmp"; invoke-pester $(PESTER) -OutputFile $(MONAD)/pester-tests.xml -OutputFormat NUnitXml' ## Pester self-tests ## - results in pester-self-tests.xml diff --git a/src/pester-tests/Get-Item.Tests.ps1 b/src/pester-tests/Get-Item.Tests.ps1 index 05b041b91..80f102fb5 100644 --- a/src/pester-tests/Get-Item.Tests.ps1 +++ b/src/pester-tests/Get-Item.Tests.ps1 @@ -1,25 +1,22 @@ -Describe "Get-Item" { +$here = Split-Path -Parent $MyInvocation.MyCommand.Path + +Describe "Get-Item" { It "Should list all the items in the current working directory when asterisk is used" { - (Get-Item *).GetType().BaseType | Should Be 'array' - (Get-Item *).GetType().Name | Should Be 'Object[]' + (Get-Item $here/*).GetType().BaseType | Should Be 'array' + (Get-Item $here/*).GetType().Name | Should Be 'Object[]' } It "Should return the name of the current working directory when a dot is used" { - (Get-Item .).GetType().BaseType | Should Be 'System.IO.FileSystemInfo' - (Get-Item .).Name | Should Be 'pester-tests' + (Get-Item $here).GetType().BaseType | Should Be 'System.IO.FileSystemInfo' + (Get-Item $here).Name | Should Be 'pester-tests' } It "Should return the proper Name and BaseType for directory objects vs file system objects" { - (Get-Item .).GetType().Name | Should Be 'DirectoryInfo' - (Get-Item ./Get-Item.Tests.ps1).GetType().Name | Should Be 'FileInfo' - } - - It "Should return a different directory when a path argument is used" { - (Get-Item /usr/bin) | Should Not BeNullOrEmpty - (Get-Item ..) | Should Not BeNullOrEmpty + (Get-Item $here).GetType().Name | Should Be 'DirectoryInfo' + (Get-Item $here/Get-Item.Tests.ps1).GetType().Name | Should Be 'FileInfo' } It "Should have mode flags set" { - ls / | foreach-object { $_.Mode | Should Not BeNullOrEmpty } + ls $here | foreach-object { $_.Mode | Should Not BeNullOrEmpty } } } diff --git a/src/pester-tests/Get-ItemProperty.Tests.ps1 b/src/pester-tests/Get-ItemProperty.Tests.ps1 index 96c2e1dfd..aded612c3 100644 --- a/src/pester-tests/Get-ItemProperty.Tests.ps1 +++ b/src/pester-tests/Get-ItemProperty.Tests.ps1 @@ -1,6 +1,8 @@ -Describe "Get-ItemProperty" { - $currentDirectory = Split-Path . -Leaf - $parentDirectory = Split-Path .. -Leaf +$here = Split-Path -Parent $MyInvocation.MyCommand.Path + +Describe "Get-ItemProperty" { + $currentDirectory = Split-Path $here -Leaf + $parentDirectory = Split-Path $here/.. -Leaf if (Test-Path /tmp) { $tempDirectory = "/tmp/testfolder" @@ -18,15 +20,11 @@ New-Item $testfile -ItemType file -Force It "Should be able to be called on in the current directory" { - { Get-ItemProperty . } | Should Not Throw - - $(Get-ItemProperty .).Name | Should Be $currentDirectory + $(Get-ItemProperty $here).Name | Should Be $currentDirectory } It "Should be able to be called on a parent directory" { - { Get-ItemProperty .. } | Should Not Throw - - (Get-ItemProperty ..).Name | Should Be $parentDirectory + (Get-ItemProperty $here/..).Name | Should Be $parentDirectory } It "Should be able to be called on a directory using the path switch" { diff --git a/src/pester-tests/Import-Csv.Tests.ps1 b/src/pester-tests/Import-Csv.Tests.ps1 index b7c9e7d77..154248d3e 100644 --- a/src/pester-tests/Import-Csv.Tests.ps1 +++ b/src/pester-tests/Import-Csv.Tests.ps1 @@ -1,5 +1,7 @@ -Describe "Import-Csv" { - $testCsv = "./assets/TestCsv.csv" +$here = Split-Path -Parent $MyInvocation.MyCommand.Path + +Describe "Import-Csv" { + $testCsv = "$here/assets/TestCsv.csv" It "Should be able to call without error" { { Import-Csv $testCsv } | Should Not Throw diff --git a/src/pester-tests/Select-Object.Tests.ps1 b/src/pester-tests/Select-Object.Tests.ps1 index 3317113d2..9d5c65c29 100644 --- a/src/pester-tests/Select-Object.Tests.ps1 +++ b/src/pester-tests/Select-Object.Tests.ps1 @@ -1,4 +1,5 @@ -. ./Test-Mocks.ps1 +$here = Split-Path -Parent $MyInvocation.MyCommand.Path +. "$here/Test-Mocks.ps1" Describe "Select-Object" { BeforeEach { diff --git a/src/pester-tests/Set-PSBreakpoint.Tests.ps1 b/src/pester-tests/Set-PSBreakpoint.Tests.ps1 index 285a4877e..89e7ac479 100644 --- a/src/pester-tests/Set-PSBreakpoint.Tests.ps1 +++ b/src/pester-tests/Set-PSBreakpoint.Tests.ps1 @@ -1,5 +1,7 @@ -Describe "Set-PSBreakpoint" { - New-Variable -Name script -Value ./assets/testablescript.ps1 -Scope Global +$here = Split-Path -Parent $MyInvocation.MyCommand.Path + +Describe "Set-PSBreakpoint" { + New-Variable -Name script -Value $here/assets/testablescript.ps1 -Scope Global It "Should be able to called with script and line parameters without error " { { Set-PSBreakpoint -Script $script -Line 1 } | Should Not Throw